forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlru-crawler.t
100 lines (83 loc) · 2.41 KB
/
lru-crawler.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 221;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
my $server = new_memcached('-m 32 -o no_modern');
{
my $stats = mem_stats($server->sock, ' settings');
is($stats->{lru_crawler}, "no");
}
my $sock = $server->sock;
# Fill a slab a bit.
# Some immortal items, some long expiring items, some short expiring items.
# Done so the immortals end up at the tail.
for (1 .. 30) {
print $sock "set ifoo$_ 0 0 2\r\nok\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
for (1 .. 30) {
print $sock "set lfoo$_ 0 3600 2\r\nok\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
for (1 .. 30) {
print $sock "set sfoo$_ 0 1 2\r\nok\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
{
my $slabs = mem_stats($sock, "slabs");
is($slabs->{"1:used_chunks"}, 90, "slab1 has 90 used chunks");
}
sleep 3;
print $sock "lru_crawler enable\r\n";
is(scalar <$sock>, "OK\r\n", "enabled lru crawler");
{
my $stats = mem_stats($server->sock, ' settings');
is($stats->{lru_crawler}, "yes");
}
print $sock "lru_crawler crawl 1\r\n";
is(scalar <$sock>, "OK\r\n", "kicked lru crawler");
while (1) {
my $stats = mem_stats($sock);
last unless $stats->{lru_crawler_running};
sleep 1;
}
{
my $slabs = mem_stats($sock, "slabs");
is($slabs->{"1:used_chunks"}, 60, "slab1 now has 60 used chunks");
my $items = mem_stats($sock, "items");
is($items->{"items:1:crawler_reclaimed"}, 30, "slab1 has 30 reclaims");
}
for (1 .. 30) {
mem_get_is($sock, "ifoo$_", "ok");
mem_get_is($sock, "lfoo$_", "ok");
mem_get_is($sock, "sfoo$_", undef);
}
print $sock "lru_crawler disable\r\n";
is(scalar <$sock>, "OK\r\n", "disabled lru crawler");
{
my $stats = mem_stats($server->sock, ' settings');
is($stats->{lru_crawler}, "no");
}
$server->stop;
# Test initializing crawler from starttime.
$server = new_memcached('-m 32 -o no_modern,lru_crawler');
$sock = $server->sock;
for (1 .. 30) {
print $sock "set sfoo$_ 0 1 2\r\nok\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
sleep 3;
print $sock "lru_crawler crawl 1\r\n";
is(scalar <$sock>, "OK\r\n", "kicked lru crawler");
while (1) {
my $stats = mem_stats($sock);
last unless $stats->{lru_crawler_running};
sleep 1;
}
{
my $slabs = mem_stats($sock, "slabs");
is($slabs->{"1:used_chunks"}, 0, "slab1 now has 0 used chunks");
}