Data-Throttler

 view release on metacpan or  search on metacpan

t/002File.t  view on Meta::CPAN

END { unlink $file if defined $file };

my $throttler = Data::Throttler->new(
    max_items => 2,
    interval  => 60,
    db_file   => $file,
);

is($throttler->try_push(), 1, "1st item in");
is($throttler->try_push(), 1, "2nd item in");
is($throttler->try_push(), 0, "3nd item blocked");

my $throttler2 = Data::Throttler->new(
    max_items => 999,
    interval  => 1235,
    db_file   => $file,
);

is($throttler2->try_push(), 1, "3nd item in");
is($throttler2->try_push(), 1, "4th item in");

# Reset test
my $throttler3 = Data::Throttler->new(
    max_items => 2,
    interval  => 60,
    db_file   => $file,
    reset     => 1,
);
is($throttler3->try_push(), 1, "1st item in");
is($throttler3->try_push(), 1, "2nd item in");
is($throttler3->try_push(), 0, "3rd item blocked");

# Reload test
my $throttler4 = Data::Throttler->new(
    max_items => 2,
    interval  => 60,
    db_file   => $file,
);
is($throttler4->try_push(), 0, "item blocked after reload");
is($throttler4->reset_key(), 2, "resetting key returned expected value");
is($throttler4->try_push(), 1, "item allowed after resetting key");
is($throttler4->reset_key(), 1, "resetting key returned expected value");

};

t/003Bug.t  view on Meta::CPAN

            time => time(),
    );
    is($rc, 1, "push ok");
    # print $th->buckets_dump();
}

my $rc = $th->try_push( 
        key  => "wonk",
        time => time(),
        );
is($rc, 0, "push blocked");

for(1..9) {
    $th->try_push( key  => "wonk1",
                   time => time()-720,
                  );
}

$rc = $th->try_push( 
        key  => "wonk1",
        time => time(),
        );
is($rc, 1, "push ok with different key");

$rc = $th->try_push( 
        key  => "wonk1",
        time => time(),
        );
is($rc, 0, "push blocked");

# print $th->buckets_dump();



( run in 3.206 seconds using v1.01-cache-2.11-cpan-9b1e4054eb1 )