App-MtAws
view release on metacpan or search on metacpan
t/lib/UploadMultipartTest.pm view on Meta::CPAN
local *App::MtAws::QueueJob::MultipartPart::read_part = sub {
my $p = shift @parts;
if ($p) {
shift->{position} += $partsize;
return (1, @$p)
} else {
return;
}
};
my @callbacks;
for (@orig_parts) {
my $res = $j->next;
cmp_deeply $res,
App::MtAws::QueueJobResult->full_new(
task => {
args => {
start => $_->[0],
upload_id => $upload_id,
part_final_hash => $_->[1],
relfilename => $relfilename,
mtime => $mtime,
},
attachment => $_->[2],
action => 'upload_part',
cb => test_coderef,
cb_task_proxy => test_coderef,
},
code => JOB_OK,
);
push @callbacks, $res->{task}{cb_task_proxy};
}
local *App::MtAws::TreeHash::calc_tree = sub { shift->{tree} = "my_final_hash" };
local *App::MtAws::TreeHash::get_final_hash = sub { shift->{tree} };
while (my $cb = shift @callbacks) {
$cb->();
if (@callbacks) {
expect_wait($j);
} else {
cmp_deeply my $finish_resp = $j->next,
App::MtAws::QueueJobResult->full_new(
task => {
args => {
filesize => $n*$partsize,
upload_id => $upload_id,
relfilename => $relfilename,
final_hash => 'my_final_hash',
t/unit/queue_job/iterator.t view on Meta::CPAN
sub test_late_finish
{
my ($maxcnt, $cnt, $jobs_count) = @_;
my $live_counter = 0;
my @live_counter_log;
my $itt = create_iterator($maxcnt, $cnt, $jobs_count, sub { ++$live_counter });
my @actions = ();
my @passes;
while (@actions < $cnt) {
my @callbacks = ();
my $r;
while (1) {
$r = $itt->next;
push @live_counter_log, $live_counter;
ok $r->{code} eq JOB_OK || $r->{code} eq JOB_WAIT;
last if $r->{code} eq JOB_WAIT;
push @actions, $r->{task}{action};
push @callbacks, $r->{task}{cb_task_proxy};
}
if ($r->{code} eq JOB_WAIT) {
push @passes, scalar @callbacks;
$_->("somedata2") for @callbacks;
next;
}
}
cmp_deeply [sort @actions], [sort map { action_str($_) } 1..$cnt];
#print Dumper $maxcnt, $cnt, \@live_counter_log;
if ($cnt % $maxcnt) {
cmp_deeply {map { $_ => 1 } @live_counter_log}, {map { $_ => 1 } 1..$cnt+1}, "should not call itterator for all jobs at once";
} else {
cmp_deeply {map { $_ => 1 } @live_counter_log}, {map { $_ => 1 } 1..$cnt }, "should not call itterator for all jobs at once";
t/unit/queue_job/multipart_part.t view on Meta::CPAN
my $j = App::MtAws::QueueJob::MultipartPart->new(%args);
$test_cb->($j, \%args, \@orig_parts);
}
sub test_with_filename_and_mtime
{
my ($relfilename, $mtime) = @_;
# late finish (callbacks called in the end)
test_case 15, $relfilename, $mtime, sub {
my ($j, $args, $parts) = @_;
my @callbacks;
for (@$parts) {
my $res = $j->next;
cmp_deeply $res,
App::MtAws::QueueJobResult->full_new(
task => {
args => {
start => $_->[0],
upload_id => $args->{upload_id},
part_final_hash => $_->[1],
relfilename => $args->{relfilename},
mtime => $args->{mtime},
},
attachment => $_->[2],
action => 'upload_part',
cb => test_coderef,
cb_task_proxy => test_coderef,
},
code => JOB_OK,
);
push @callbacks, $res->{task}{cb_task_proxy};
}
lcg_srand 444242 => sub {
@callbacks = lcg_shuffle @callbacks; # late finish, but in random order
while (my $cb = shift @callbacks) {
$cb->();
cmp_deeply $j->next, App::MtAws::QueueJobResult->full_new(code => @callbacks ? JOB_WAIT : JOB_DONE);
}
}
};
# early finish (early calls of callbacks)
test_case 11, $relfilename, $mtime, sub {
my ($j, $args, $parts) = @_;
for (@$parts) {
my $res = $j->next;
cmp_deeply $res,
App::MtAws::QueueJobResult->full_new(
task => {
args => {
( run in 0.260 second using v1.01-cache-2.11-cpan-8d75d55dd25 )