-
Notifications
You must be signed in to change notification settings - Fork 35
/
stream.t
65 lines (46 loc) · 1.45 KB
/
stream.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Data::Stream::Bulk::Callback;
use ok 'KiokuDB';
use ok 'KiokuDB::Backend::Hash';
use_ok 'KiokuDB::Stream::Objects';
{
package KiokuDB_Test_Foo;
use Moose;
has id => (is => 'rw', isa => 'Str');
has num => (is => 'rw', isa => 'Int');
}
my $dir = KiokuDB->connect( "hash", serializer => 'memory');
my @objs = (
KiokuDB_Test_Foo->new( id => 'one', num => 1 ),
KiokuDB_Test_Foo->new( id => 'two', num => 2 ),
KiokuDB_Test_Foo->new( id => 'three', num => 3 ),
KiokuDB_Test_Foo->new( id => 'zero', num => 0 ),
KiokuDB_Test_Foo->new( id => 'four', num => 4 ),
);
my @ids;
my @entries;
{
my $s = $dir->new_scope;
foreach my $obj (@objs) {
lives_ok { $dir->store( $obj->id => $obj ) } "can store " . $obj->id;
}
@ids = $dir->live_objects->objects_to_ids(@objs);
@entries = map { $_->clone } $dir->live_objects->objects_to_entries(@objs);
}
sub iter {
my @x = @_;
Data::Stream::Bulk::Callback->new(
callback =>
sub { return unless @x; return [ shift @x ] })->filter(sub {[grep { $_->can("num") ? $_->num : $_->data->{num} } @$_ ]});
}
is_deeply([map { $_->num } iter(@objs)->all],[1,2,3,4], "found 4 objects");
my $stream = KiokuDB::Stream::Objects ->new(
directory => $dir,
entry_stream => iter(@entries),
);
is_deeply([map { $_->num } $stream->all],[1,2,3,4], "found 4 objects");
done_testing;