"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/slabs_reassign.t" (21 Feb 2022, 2621 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 131;
6 use FindBin qw($Bin);
7 use lib "$Bin/lib";
8 use MemcachedTest;
9
10 # Enable manual slab reassign, cap at 6 slabs
11 my $server = new_memcached('-o slab_reassign -m 4');
12 my $stats = mem_stats($server->sock, ' settings');
13 is($stats->{slab_reassign}, "yes");
14
15 my $sock = $server->sock;
16
17 # Fill a largeish slab until it evicts (honors the -m 6)
18 my $bigdata = 'x' x 70000; # slab 31
19 for (1 .. 60) {
20 print $sock "set bfoo$_ 0 0 70000\r\n", $bigdata, "\r\n";
21 is(scalar <$sock>, "STORED\r\n", "stored key");
22 }
23
24 # Fill a smaller slab until it evicts
25 my $smalldata = 'y' x 20000; # slab 25
26 for (1 .. 60) {
27 print $sock "set sfoo$_ 0 0 20000\r\n", $smalldata, "\r\n";
28 is(scalar <$sock>, "STORED\r\n", "stored key");
29 }
30
31 my $items_before = mem_stats($sock, "items");
32 isnt($items_before->{"items:31:evicted"}, 0, "slab 31 evicted is nonzero");
33 isnt($items_before->{"items:25:evicted"}, 0, "slab 25 evicted is nonzero");
34
35 my $slabs_before = mem_stats($sock, "slabs");
36
37 # Invalid argument test
38 print $sock "slabs reassign invalid1 invalid2\r\n";
39 is(scalar <$sock>, "CLIENT_ERROR bad command line format\r\n");
40
41 # Move a large slab to the smaller slab
42 print $sock "slabs reassign 31 25\r\n";
43 is(scalar <$sock>, "OK\r\n", "slab rebalancer started");
44
45 # Still working out how/if to signal the thread. For now, just sleep.
46 sleep 2;
47
48 # Check that stats counters increased
49 my $slabs_after = mem_stats($sock, "slabs");
50 $stats = mem_stats($sock);
51
52 isnt($stats->{slabs_moved}, 0, "slabs moved is nonzero");
53
54 # Check that slab stats reflect the change
55 ok($slabs_before->{"31:total_pages"} != $slabs_after->{"31:total_pages"},
56 "slab 31 pagecount changed");
57 ok($slabs_before->{"25:total_pages"} != $slabs_after->{"25:total_pages"},
58 "slab 25 pagecount changed");
59
60 # Try to move another slab, see that you can move two in a row
61 print $sock "slabs reassign 31 25\r\n";
62 like(scalar <$sock>, qr/^OK/, "Cannot re-run against class with empty space");
63
64 # Try to move a page backwards. Should complain that source class isn't "safe"
65 # to move from.
66 # TODO: Wait until the above command completes, then try to move it back?
67 # Seems pointless...
68 #print $sock "slabs reassign 25 31\r\n";
69 #like(scalar <$sock>, qr/^UNSAFE/, "Cannot move an unsafe slab back");
70
71 # Try to insert items into both slabs
72 print $sock "set bfoo51 0 0 70000\r\n", $bigdata, "\r\n";
73 is(scalar <$sock>, "STORED\r\n", "stored key");
74
75 print $sock "set sfoo51 0 0 20000\r\n", $smalldata, "\r\n";
76 is(scalar <$sock>, "STORED\r\n", "stored key");
77
78 # Do need to come up with better automated tests for this.