NAME
Test::Gearman - A class for testing and mocking Gearman workers.
VERSION
version v0.1.0
SYNOPSIS
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 $res = $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 $res = $client->do('reverse', 'some other test string');
DESCRIPTION
Test::Gearman is a class for testing Gearman workers.
This class only works with C version of gearmand, and Gearman::XS bindings.
PUBLIC ATTRIBUTES
functions
A HashRef of CodeRefs that stores work function names as keys and a CodeRef as work to be done.
function_names()
Returns a list of all function names.
get_function($function_name)
Returns a CodeRef for the given function name.
gearmand_bin
Path to Gearman daemon binary. If one is not provided it tries to find it in the $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}
.
host
Host to which Gearman daemon will bind.
Default is 127.0.0.1.
port
Port on which gearmand runs. It is picked randomly at the start, but you can manually specify a port if you wish.
worker_timeout
Worker timeout in seconds.
Default is 5.
client_timeout
Client timeout in seconds.
Default is 5.
client
An instance of Gearman::XS::Client that you can use to inject jobs.
PRIVATE ATTRIBUTES
server
An instance of Proc::Guard that runs gearmand server.
worker
An instance of Proc::Guard class that runs workers.
AUTHOR
Roman F. <romanf@cpan.org>
COPYRIGHT AND LICENSE
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.