|
Packit Service |
584ef9 |
#!/usr/bin/perl
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
use strict;
|
|
Packit Service |
584ef9 |
use Test::More tests => 149;
|
|
Packit Service |
584ef9 |
use FindBin qw($Bin);
|
|
Packit Service |
584ef9 |
use lib "$Bin/lib";
|
|
Packit Service |
584ef9 |
use MemcachedTest;
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# assuming max slab is 1M and default mem is 64M
|
|
Packit Service |
584ef9 |
my $server = new_memcached('-o no_modern');
|
|
Packit Service |
584ef9 |
my $sock = $server->sock;
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# create a big value for the largest slab
|
|
Packit Service |
584ef9 |
my $max = 1024 * 1024;
|
|
Packit Service |
584ef9 |
my $big = 'x' x (1024 * 1024 - 250);
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
ok(length($big) > 512 * 1024);
|
|
Packit Service |
584ef9 |
ok(length($big) < 1024 * 1024);
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# test that an even bigger value is rejected while we're here
|
|
Packit Service |
584ef9 |
my $too_big = $big . $big . $big;
|
|
Packit Service |
584ef9 |
my $len = length($too_big);
|
|
Packit Service |
584ef9 |
print $sock "set too_big 0 0 $len\r\n$too_big\r\n";
|
|
Packit Service |
584ef9 |
is(scalar <$sock>, "SERVER_ERROR object too large for cache\r\n", "too_big not stored");
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# set the big value
|
|
Packit Service |
584ef9 |
my $len = length($big);
|
|
Packit Service |
584ef9 |
print $sock "set big 0 0 $len\r\n$big\r\n";
|
|
Packit Service |
584ef9 |
is(scalar <$sock>, "STORED\r\n", "stored big");
|
|
Packit Service |
584ef9 |
mem_get_is($sock, "big", $big);
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# no evictions yet
|
|
Packit Service |
584ef9 |
my $stats = mem_stats($sock);
|
|
Packit Service |
584ef9 |
is($stats->{"evictions"}, "0", "no evictions to start");
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# set many big items, enough to get evictions
|
|
Packit Service |
584ef9 |
for (my $i = 0; $i < 100; $i++) {
|
|
Packit Service |
584ef9 |
print $sock "set item_$i 0 0 $len\r\n$big\r\n";
|
|
Packit Service |
584ef9 |
is(scalar <$sock>, "STORED\r\n", "stored item_$i");
|
|
Packit Service |
584ef9 |
}
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# some evictions should have happened
|
|
Packit Service |
584ef9 |
my $stats = mem_stats($sock);
|
|
Packit Service |
584ef9 |
my $evictions = int($stats->{"evictions"});
|
|
Packit Service |
584ef9 |
ok($evictions == 37, "some evictions happened");
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# the first big value should be gone
|
|
Packit Service |
584ef9 |
mem_get_is($sock, "big", undef);
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# the earliest items should be gone too
|
|
Packit Service |
584ef9 |
for (my $i = 0; $i < $evictions - 1; $i++) {
|
|
Packit Service |
584ef9 |
mem_get_is($sock, "item_$i", undef);
|
|
Packit Service |
584ef9 |
}
|
|
Packit Service |
584ef9 |
|
|
Packit Service |
584ef9 |
# check that the non-evicted are the right ones
|
|
Packit Service |
584ef9 |
for (my $i = $evictions - 1; $i < $evictions + 4; $i++) {
|
|
Packit Service |
584ef9 |
mem_get_is($sock, "item_$i", $big);
|
|
Packit Service |
584ef9 |
}
|