Test::Gearman - A class for testing and mocking Gearman workers.
version v0.2.0
use Test::Gearman; my $tg = Test::Gearman->new( functions => { reverse => sub { my $job = shift; my $workload = $job->workload(); my $result = reverse($workload); return $result; }, }, ); ## now you can either get a client object ## from Test::Gearman object my ($ret, $result) = $tg->client->do('reverse', 'this is a test'); ## or build your own use Gearman::XS::Client; my $client = Gearman::XS::Client->new; $client->add_server($tg->host, $tg->port); my ($ret, $job_handle) = $client->do_background('reverse', 'hello world');
Test::Gearman is a class for testing Gearman workers.
This class only works with C version of gearmand, and Gearman::XS bindings.
An actual Gearman daemon is launched, and workers are forked when you instantiate the class. The Gearman and workers are automatically shut down and destroyed when the instance of the class goes out of scope.
By default Gearman daemon will listen on a random available "port".
A HashRef of CodeRefs that stores worker function names as keys and a CodeRef as work to be done.
my $tg = Test::Gearman->new( functions => { function_name => sub { ## worker code }, }, );
Returns a list of all registered worker function names.
Returns a CodeRef for the given function name.
Path to Gearman daemon binary. If one is not provided it tries to find it in the $PATH.
$PATH
Note: this must be a C version of gearmand, and not the Perl version as they have different interfaces.
You can also set the path to the binary via $ENV{GEARMAND}.
$ENV{GEARMAND}
Host to which Gearman daemon will bind.
Default is 127.0.0.1.
Port on which gearmand runs. It is picked randomly at the start, but you can manually specify a port if you wish.
Worker timeout in seconds.
Default is 5.
Client timeout in seconds.
An instance of Gearman::XS::Client that you can use to inject jobs.
Gearman daemon log file. This is synonymous with --log-file option.
--log-file
Default: stderr
An instance of Proc::Guard that runs gearmand server.
An instance of Proc::Guard that runs workers.
Roman F. <romanf@cpan.org>
This software is copyright (c) 2013 by Need Backup.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test::Gearman, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Gearman
CPAN shell
perl -MCPAN -e shell install Test::Gearman
For more information on module installation, please visit the detailed CPAN module installation guide.