| 1 | # $Id$ |
| 2 | |
| 3 | use strictscip-perl cpan TheSchwartz 1.12 strict/; |
| 4 | use warningsscip-perl cpan TheSchwartz 1.12 warnings/; |
| 5 | use Test::Morescip-perl cpan TheSchwartz 1.12 Test/More/ tests => 19; |
| 6 | |
| 7 | use TheSchwartzscip-perl cpan TheSchwartz 1.12 TheSchwartz/; |
| 8 | use Storablescip-perl cpan TheSchwartz 1.12 Storable/; |
| 9 | |
| 10 | # With this test, all data structures are in memory so far. Nothing's |
| 11 | # been inserted into the database because we have no client object |
| 12 | # yet with which to insert. |
| 13 | |
| 14 | my $args = { scoops => 2, with => [ 'cheese', 'love' ] }; |
| 15 | my $fargs = Storable::nfreezescip-perl cpan TheSchwartz 1.12 Storable/nfreeze().($args); |
| 16 | |
| 17 | my $job1 = TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( "feedmajor", $fargs ); |
| 18 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok().( $job1, 'TheSchwartz::Job' ); |
| 19 | my $job2 = TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( "feedmajor", \$fargs ); |
| 20 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok().( $job2, 'TheSchwartz::Job' ); |
| 21 | my $job3 = TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( funcname => 'feedmajor', arg => $args ); |
| 22 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok().( $job3, 'TheSchwartz::Job' ); |
| 23 | my $job4 = TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( funcname => 'feedmajor', arg => $fargs ); |
| 24 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok().( $job4, 'TheSchwartz::Job' ); |
| 25 | my $job5 = TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( funcname => 'feedmajor', arg => \$fargs ); |
| 26 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok().( $job5, 'TheSchwartz::Job' ); |
| 27 | |
| 28 | is_deeplyscip-perl cpan TheSchwartz 1.12 main/is_deeply().( $job1->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., $job2->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., "job2 is equivalent" ); |
| 29 | is_deeplyscip-perl cpan TheSchwartz 1.12 main/is_deeply().( $job1->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., $job3->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., "job3 is equivalent" ); |
| 30 | is_deeplyscip-perl cpan TheSchwartz 1.12 main/is_deeply().( $job1->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., $job4->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., "job4 is equivalent" ); |
| 31 | is_deeplyscip-perl cpan TheSchwartz 1.12 main/is_deeply().( $job1->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., $job5->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., "job5 is equivalent" ); |
| 32 | |
| 33 | my $job6 = TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( |
| 34 | funcname => 'feeddog', |
| 35 | run_after => timescip-perl cpan TheSchwartz 1.12 main/time().() + 60, |
| 36 | priority => 7, |
| 37 | arg => { scoops => 2, with => [ 'cheese', 'love' ] }, |
| 38 | coalesce => 'major', |
| 39 | jobid => intscip-perl cpan TheSchwartz 1.12 main/int().( randscip-perl cpan TheSchwartz 1.12 main/rand().() * 5000 ), |
| 40 | ); |
| 41 | isa_okscip-perl cpan TheSchwartz 1.12 main/isa_ok(). $job6, 'TheSchwartz::Job'; |
| 42 | |
| 43 | # second arg can also be an arrayref |
| 44 | my $job_a1 = TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( "feedmajor", |
| 45 | [ 'cheese', 'water', 'beer' ] ); |
| 46 | my $job_a2 = TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( |
| 47 | funcname => "feedmajor", |
| 48 | arg => [ 'cheese', 'water', 'beer' ] |
| 49 | ); |
| 50 | is_deeplyscip-perl cpan TheSchwartz 1.12 main/is_deeply().( $job_a1->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., $job_a2->column_valuesscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/column_values()., |
| 51 | "ctors with arrayrefs match" ); |
| 52 | |
| 53 | my $jobbad = eval { |
| 54 | TheSchwartz::Job->newscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new().( |
| 55 | funcname => 'feeddog', |
| 56 | run_atter => timescip-perl cpan TheSchwartz 1.12 main/time().() + 60, # [sic] typo |
| 57 | ); |
| 58 | }; |
| 59 | okscip-perl cpan TheSchwartz 1.12 main/ok().( !$jobbad, "no bad job" ); |
| 60 | okscip-perl cpan TheSchwartz 1.12 main/ok().( $@scip-perl cpan TheSchwartz 1.12 main/`$@`., "error creating job with bad argument" ); |
| 61 | |
| 62 | # can't have multiple non-ref args |
| 63 | $jobbad = eval { |
| 64 | TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( "feeddog", "scalar1", "scalar2" ); |
| 65 | }; |
| 66 | okscip-perl cpan TheSchwartz 1.12 main/ok().( !$jobbad, "no bad job" ); |
| 67 | okscip-perl cpan TheSchwartz 1.12 main/ok().( $@scip-perl cpan TheSchwartz 1.12 main/`$@`., "error creating job with bad argument" ); |
| 68 | |
| 69 | # can't have multiple non-ref args, even if first is scalarref |
| 70 | $jobbad = eval { |
| 71 | TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( "feeddog", \"scalar1", "scalar2" ); |
| 72 | }; |
| 73 | okscip-perl cpan TheSchwartz 1.12 main/ok().( !$jobbad, "no bad job" ); |
| 74 | okscip-perl cpan TheSchwartz 1.12 main/ok().( $@scip-perl cpan TheSchwartz 1.12 main/`$@`., "error creating job with bad argument" ); |
| 75 | |
| 76 | # can't have multiple non-ref args, even if first is hashrf |
| 77 | $jobbad = eval { |
| 78 | TheSchwartz::Job->new_from_arrayscip-perl cpan TheSchwartz 1.12 TheSchwartz/Job/new_from_array().( |
| 79 | "feeddog", |
| 80 | { with => 'poison' }, |
| 81 | { extra => 'arg' } |
| 82 | ); |
| 83 | }; |
| 84 | okscip-perl cpan TheSchwartz 1.12 main/ok().( !$jobbad, "no bad job" ); |
| 85 | okscip-perl cpan TheSchwartz 1.12 main/ok().( $@scip-perl cpan TheSchwartz 1.12 main/`$@`., "error creating job with bad argument" ); |