++ed by:
Roman F.

NAME

Test::Gearman - A class for testing and mocking Gearman workers.

VERSION

version v0.2.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 ($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');

DESCRIPTION

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".

PUBLIC ATTRIBUTES

functions

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
         },
     },
 );

function_names()

Returns a list of all registered worker 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.

log_file

Gearman daemon log file. This is synonymous with --log-file option.

Default: stderr

PRIVATE ATTRIBUTES

server

An instance of Proc::Guard that runs gearmand server.

worker

An instance of Proc::Guard 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.




Hosting generously
sponsored by Bytemark