| 1 | use strictscip-perl cpan IPC-PubSub 0.29 strict/; |
| 2 | use warningsscip-perl cpan IPC-PubSub 0.29 warnings/; |
| 3 | use Test::Morescip-perl cpan IPC-PubSub 0.29 Test/More/; |
| 4 | use IPC::PubSubscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/; |
| 5 | use IO::Socket::INETscip-perl cpan IPC-PubSub 0.29 IO/Socket/INET/; |
| 6 | use File::Tempscip-perl cpan IPC-PubSub 0.29 File/Temp/ ':POSIX'; |
| 7 | |
| 8 | |
| 9 | my @backends = qw(PlainHash); |
| 10 | |
| 11 | unshiftscip-perl cpan IPC-PubSub 0.29 main/unshift(). @backends, 'DBM_Deep' if eval { requirescip-perl cpan IPC-PubSub 0.29 main/require(). DBM::Deep }; |
| 12 | unshiftscip-perl cpan IPC-PubSub 0.29 main/unshift(). @backends, 'JiftyDBI' if eval { requirescip-perl cpan IPC-PubSub 0.29 main/require(). Jifty::DBI }; |
| 13 | unshiftscip-perl cpan IPC-PubSub 0.29 main/unshift(). @backends, 'Memcached' if eval { requirescip-perl cpan IPC-PubSub 0.29 main/require(). Cache::Memcached } and IO::Socket::INET->newscip-perl cpan IPC-PubSub 0.29 IO/Socket/INET/new().('127.0.0.1:11211'); |
| 14 | |
| 15 | planscip-perl cpan IPC-PubSub 0.29 main/plan(). tests => 15 * scalarscip-perl cpan IPC-PubSub 0.29 main/scalar(). @backends; |
| 16 | |
| 17 | my $tmp = tmpnamscip-perl cpan IPC-PubSub 0.29 main/tmpnam().(); |
| 18 | END { unlinkscip-perl cpan IPC-PubSub 0.29 main/unlink(). $tmp } |
| 19 | |
| 20 | my %init_args = ( |
| 21 | DBM_Deep => [ $tmp ], |
| 22 | JiftyDBI => [ db_init => 1 ], |
| 23 | Memcached => [ randscip-perl cpan IPC-PubSub 0.29 main/rand().() . $$scip-perl cpan IPC-PubSub 0.29 main/$$. ], |
| 24 | ); |
| 25 | |
| 26 | SKIP: for my $backend (@backends) { |
| 27 | diagscip-perl cpan IPC-PubSub 0.29 main/diag().("Testing backend $backend"); |
| 28 | |
| 29 | my $bus = IPC::PubSub->newscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/new().($backend, @{$init_args{$backend}}); |
| 30 | |
| 31 | my @sub; $sub[0] = $bus->new_subscriberscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/new_subscriber().; |
| 32 | |
| 33 | is_deeplyscip-perl cpan IPC-PubSub 0.29 main/is_deeply().([mapscip-perl cpan IPC-PubSub 0.29 main/map(). {$_scip-perl cpan IPC-PubSub 0.29 main/$_.->[1]} @{$sub[0]->get_allscip-perl cpan IPC-PubSub 0.29 main/get_all().->{''}}], [], 'get_all worked when there is no pubs'); |
| 34 | is_deeplyscip-perl cpan IPC-PubSub 0.29 main/is_deeply().([$sub[0]->getscip-perl cpan IPC-PubSub 0.29 main/get().], [], 'get_all worked when there is no pubs'); |
| 35 | |
| 36 | my $pub = $bus->new_publisherscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/new_publisher().; |
| 37 | |
| 38 | $pub->msgscip-perl cpan IPC-PubSub 0.29 main/msg().('foo'); |
| 39 | |
| 40 | $sub[1] = $bus->new_subscriberscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/new_subscriber().; |
| 41 | |
| 42 | $pub->msgscip-perl cpan IPC-PubSub 0.29 main/msg().(['bar', 'bar']); |
| 43 | $pub->msgscip-perl cpan IPC-PubSub 0.29 main/msg().('baz'); |
| 44 | |
| 45 | my $got = $sub[0]->getscip-perl cpan IPC-PubSub 0.29 main/get().; |
| 46 | isscip-perl cpan IPC-PubSub 0.29 main/is().($got->[0], 'foo', 'get worked'); |
| 47 | isscip-perl cpan IPC-PubSub 0.29 main/is().($got->[1][0], 'bar', 'get worked'); |
| 48 | isscip-perl cpan IPC-PubSub 0.29 main/is().($got->[1][1], 'bar', 'get worked'); |
| 49 | isscip-perl cpan IPC-PubSub 0.29 main/is().($got->[2], 'baz', 'get worked'); |
| 50 | is_deeplyscip-perl cpan IPC-PubSub 0.29 main/is_deeply().([$sub[0]->getscip-perl cpan IPC-PubSub 0.29 main/get().], [], 'get emptied the cache'); |
| 51 | |
| 52 | is_deeplyscip-perl cpan IPC-PubSub 0.29 main/is_deeply().([mapscip-perl cpan IPC-PubSub 0.29 main/map(). {refscip-perl cpan IPC-PubSub 0.29 main/ref().($_scip-perl cpan IPC-PubSub 0.29 main/$_.) ? [@$_scip-perl cpan IPC-PubSub 0.29 main/$_.] : $_scip-perl cpan IPC-PubSub 0.29 main/$_.} mapscip-perl cpan IPC-PubSub 0.29 main/map(). {$_scip-perl cpan IPC-PubSub 0.29 main/$_.->[1]} @{$sub[1]->get_allscip-perl cpan IPC-PubSub 0.29 main/get_all().->{''}}], [['bar', 'bar'], 'baz'], 'get_all worked'); |
| 53 | is_deeplyscip-perl cpan IPC-PubSub 0.29 main/is_deeply().([mapscip-perl cpan IPC-PubSub 0.29 main/map(). {refscip-perl cpan IPC-PubSub 0.29 main/ref().($_scip-perl cpan IPC-PubSub 0.29 main/$_.) ? [@$_scip-perl cpan IPC-PubSub 0.29 main/$_.] : $_scip-perl cpan IPC-PubSub 0.29 main/$_.} mapscip-perl cpan IPC-PubSub 0.29 main/map(). {$_scip-perl cpan IPC-PubSub 0.29 main/$_.->[1]} @{$sub[1]->get_allscip-perl cpan IPC-PubSub 0.29 main/get_all().->{''}}], [], 'get_all emptied the cache'); |
| 54 | |
| 55 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key'), undef, 'modify (1)'); |
| 56 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key' => 'val'), 'val', 'modify (2)'); |
| 57 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key'), 'val', 'modify (3)'); |
| 58 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key' => sub { s/v/h/ }), 1, 'modify (4)'); |
| 59 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key'), 'hal', 'modify (5)'); |
| 60 | isscip-perl cpan IPC-PubSub 0.29 main/is().($bus->modifyscip-perl cpan IPC-PubSub 0.29 IPC/PubSub/modify().('key' => undef), undef, 'modify (6)'); |
| 61 | } |