line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::WebService::Amazon::DynamoDB::Server; |
2
|
|
|
|
|
|
|
$Test::WebService::Amazon::DynamoDB::Server::VERSION = '0.001'; |
3
|
7
|
|
|
7
|
|
3143
|
use strict; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
211
|
|
4
|
7
|
|
|
7
|
|
26
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
173
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
97
|
use parent qw(Exporter); |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Test::WebService::Amazon::DynamoDB - functions for testing the DynamoDB code |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.001 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Mostly intended as convenience functions for the |
19
|
|
|
|
|
|
|
L test suite. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
7
|
|
|
7
|
|
680
|
our @EXPORT = our @EXPORT_OK = qw( |
25
|
|
|
|
|
|
|
fmap_over |
26
|
|
|
|
|
|
|
ddb_server |
27
|
|
|
|
|
|
|
expect_events |
28
|
|
|
|
|
|
|
add_table |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
7
|
|
|
7
|
|
54
|
use WebService::Amazon::DynamoDB::Server; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
120
|
|
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
7
|
|
19
|
use Test::More; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
43
|
|
35
|
7
|
|
|
7
|
|
1824
|
use Future::Utils qw(fmap repeat call); |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
5399
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $SRV; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub fmap_over(&;@) { |
40
|
1
|
|
|
1
|
0
|
6738
|
my ($code, %args) = @_; |
41
|
1
|
|
|
|
|
2
|
my @result; |
42
|
|
|
|
|
|
|
(repeat { |
43
|
|
|
|
|
|
|
(shift || Future->done)->then(sub { |
44
|
3
|
|
|
|
|
191
|
my $last = shift; |
45
|
|
|
|
|
|
|
call { |
46
|
|
|
|
|
|
|
$code->($last)->on_done(sub { |
47
|
3
|
|
|
|
|
4002
|
push @result, @_ |
48
|
|
|
|
|
|
|
}) |
49
|
3
|
|
|
|
|
27
|
} |
50
|
3
|
|
|
|
|
14
|
}) |
51
|
3
|
|
66
|
3
|
|
111
|
} (exists $args{while} |
52
|
|
|
|
|
|
|
? ( |
53
|
|
|
|
|
|
|
while => sub { |
54
|
3
|
50
|
|
3
|
|
145
|
!@_ || $args{while}->(shift->get) |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
) :() |
57
|
|
|
|
|
|
|
))->transform(done => sub { |
58
|
1
|
50
|
|
1
|
|
186
|
$args{map} ? (map $args{map}->($_), @result) : @result |
59
|
|
|
|
|
|
|
}) |
60
|
1
|
50
|
|
|
|
15
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 ddb_server |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Runs a block of code with a custom L instance. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Primarily intended as a visual aid to allow setting |
67
|
|
|
|
|
|
|
up the test spec: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $srv = ddb_server { |
70
|
|
|
|
|
|
|
add_table name => 'xyz', ...; |
71
|
|
|
|
|
|
|
expect_events { |
72
|
|
|
|
|
|
|
put_item => 3, |
73
|
|
|
|
|
|
|
get_item => 4, |
74
|
|
|
|
|
|
|
describe_table => 1 |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
... |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Returns that instance when done. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub ddb_server(&;@) { |
84
|
7
|
|
|
7
|
1
|
83
|
my ($code) = shift; |
85
|
7
|
|
|
|
|
45
|
local $SRV = new_ok('WebService::Amazon::DynamoDB::Server'); |
86
|
7
|
|
|
|
|
4090
|
$code->($SRV); |
87
|
7
|
|
|
|
|
98
|
$SRV |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 add_table |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Adds the given table spec. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub add_table(@) { |
97
|
6
|
|
|
6
|
1
|
19
|
my %args = @_; |
98
|
6
|
|
|
|
|
16
|
$SRV->add_table(%args); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 expect_events |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Indicates that we're expecting certain events to fire. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
expect_events { |
106
|
|
|
|
|
|
|
create_table => 7, |
107
|
|
|
|
|
|
|
delete_table => 2, |
108
|
|
|
|
|
|
|
put_item => 5 |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub expect_events($) { |
114
|
7
|
|
|
7
|
1
|
51
|
my $stat = shift; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $event_info = { |
117
|
|
|
|
|
|
|
create_table => sub { |
118
|
1
|
|
|
1
|
|
7
|
my ($tbl) = @_; |
119
|
1
|
50
|
|
|
|
32
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
120
|
|
|
|
|
|
|
}, |
121
|
|
|
|
|
|
|
delete_table => sub { |
122
|
2
|
|
|
2
|
|
2
|
my ($tbl) = @_; |
123
|
2
|
50
|
|
|
|
5
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
124
|
|
|
|
|
|
|
}, |
125
|
|
|
|
|
|
|
update_table => sub { |
126
|
1
|
|
|
1
|
|
2
|
my ($tbl) = @_; |
127
|
1
|
50
|
|
|
|
3
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
describe_table => sub { |
130
|
5
|
|
|
5
|
|
8
|
my ($tbl) = @_; |
131
|
5
|
50
|
|
|
|
13
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
132
|
|
|
|
|
|
|
}, |
133
|
|
|
|
|
|
|
list_tables => sub { |
134
|
4
|
|
|
4
|
|
7
|
my ($tables) = @_; |
135
|
4
|
50
|
|
|
|
11
|
isa_ok($tables, 'ARRAY') or note explain $tables; |
136
|
4
|
|
|
|
|
1500
|
for(grep !$_->isa('WebService::Amazon::DynamoDB::Server::Table'), @$tables) { |
137
|
0
|
|
|
|
|
0
|
fail("unexpected entry in tables"); |
138
|
0
|
|
|
|
|
0
|
note explain $_; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
}, |
141
|
|
|
|
|
|
|
get_item => sub { |
142
|
0
|
|
|
0
|
|
0
|
my ($tbl, $item) = @_; |
143
|
0
|
0
|
|
|
|
0
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
144
|
0
|
0
|
|
|
|
0
|
isa_ok($item, 'WebService::Amazon::DynamoDB::Server::Item') or note explain $item; |
145
|
|
|
|
|
|
|
}, |
146
|
|
|
|
|
|
|
put_item => sub { |
147
|
2
|
|
|
2
|
|
3
|
my ($tbl, $item) = @_; |
148
|
2
|
50
|
|
|
|
7
|
isa_ok($tbl, 'WebService::Amazon::DynamoDB::Server::Table') or note explain $tbl; |
149
|
2
|
50
|
|
|
|
515
|
isa_ok($item, 'WebService::Amazon::DynamoDB::Server::Item') or note explain $item; |
150
|
|
|
|
|
|
|
} |
151
|
7
|
|
|
|
|
197
|
}; |
152
|
7
|
|
|
|
|
60
|
for (sort keys %$event_info) { |
153
|
49
|
|
|
|
|
566
|
my $k = $_; |
154
|
49
|
|
|
|
|
52
|
my $code = $event_info->{$k}; |
155
|
|
|
|
|
|
|
$SRV->bus->subscribe_to_event( |
156
|
|
|
|
|
|
|
$k => sub { |
157
|
40
|
|
|
40
|
|
1007
|
my ($ev, $req, $rslt, @extra) = @_; |
158
|
40
|
|
|
|
|
176
|
note "Had $k event"; |
159
|
|
|
|
|
|
|
# Reduce pending count for this type - we're aiming for 0 |
160
|
40
|
100
|
|
|
|
4826
|
--$stat->{$k} if exists $stat->{$k}; |
161
|
40
|
50
|
|
|
|
127
|
isa_ok($req, 'HASH') or note explain $req; |
162
|
40
|
50
|
|
|
|
13318
|
isa_ok($rslt, 'Future') or note explain $rslt; |
163
|
40
|
|
|
|
|
12444
|
ok($rslt->is_ready, '... and it is ready'); |
164
|
40
|
100
|
|
|
|
10976
|
if($rslt->failure) { |
165
|
25
|
|
|
|
|
328
|
like($rslt->failure, qr/Exception/, 'had the word "exception" somewhere'); |
166
|
|
|
|
|
|
|
} else { |
167
|
15
|
|
|
|
|
111
|
$code->(@extra); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
49
|
|
|
|
|
94
|
); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Report on status when our object is cleaned up |
174
|
|
|
|
|
|
|
$SRV->bus->subscribe_to_event( |
175
|
|
|
|
|
|
|
destroy => sub { |
176
|
7
|
|
|
7
|
|
165
|
my ($ev, $srv) = @_; |
177
|
7
|
|
|
|
|
67
|
is($stat->{$_}, 0, $_ . ' events triggered as expected') for sort keys %$stat; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
) |
180
|
7
|
|
|
|
|
93
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |