AnyEvent-Serialize
view release on metacpan or search on metacpan
t/serialize.t view on Meta::CPAN
use warnings;
use strict;
use Time::HiRes qw(time);
use Data::Dumper;
use AnyEvent;
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Useqq = 1;
local $Data::Dumper::Deepcopy = 1;
use Test::More tests => 54;
BEGIN {
use_ok 'AnyEvent';
use_ok('AnyEvent::Serialize', ':all', 'block_size' => 10);
};
sub rand_array($);
sub compare_object($$);
sub rand_hash($);
my @a;
for (0 .. 9) {
push @a, (50 < rand 100) ? rand_hash 6 : rand_array 6;
# push @a, (50 < rand 100) ? [1,2] : {1,2};
}
$_ = { str => Dumper($_), orig => $_ } for @a;
{
my $counter = 0;
my $cv = condvar AnyEvent;
my (@res, @sres);
for my $i (0 .. $#a) {
deserialize $a[$i]{str} =>
sub {
$res[$i] = { obj => \@_, time => time, order => $counter++ };
$cv->send if $counter == @a * 2;
};
serialize $a[$i]{orig} =>
sub {
my ($s, $rd) = @_;
$sres[$i] = {
str => $s,
recursion => $rd,
time => time,
order => $counter++
};
$cv->send if $counter == @a * 2;
};
}
$cv->recv;
for (0 .. $#res) {
ok compare_object($res[$_]{obj}[0], $a[$_]{orig}),
"$_: object deserialized";
ok !$res[$_]{obj}[1], "$_: no error detected";
ok !$res[$_]{obj}[2], "$_: undeserialized tail is empty";
my $dsr = eval $sres[$_]{str};
ok compare_object($dsr, $a[$_]{orig}),
"$_: object serialized";
ok !$sres[$_]{recursion}, "$_: no recursion detected";
( run in 1.807 second using v1.01-cache-2.11-cpan-39bf76dae61 )