0
|
1 #!/usr/bin/perl
|
|
2
|
|
3 use strict;
|
|
4 use Test::More tests => 528;
|
|
5 use FindBin qw($Bin);
|
|
6 use lib "$Bin/lib";
|
|
7 use MemcachedTest;
|
|
8
|
|
9
|
|
10 my $server = new_memcached();
|
|
11 my $sock = $server->sock;
|
|
12
|
|
13
|
|
14 # set foo (and should get it)
|
|
15 print $sock "set foo 0 0 6\r\nfooval\r\n";
|
|
16 is(scalar <$sock>, "STORED\r\n", "stored foo");
|
|
17 mem_get_is($sock, "foo", "fooval");
|
|
18
|
|
19 # add bar (and should get it)
|
|
20 print $sock "add bar 0 0 6\r\nbarval\r\n";
|
|
21 is(scalar <$sock>, "STORED\r\n", "stored barval");
|
|
22 mem_get_is($sock, "bar", "barval");
|
|
23
|
|
24 # add foo (but shouldn't get new value)
|
|
25 print $sock "add foo 0 0 5\r\nfoov2\r\n";
|
|
26 is(scalar <$sock>, "NOT_STORED\r\n", "not stored");
|
|
27 mem_get_is($sock, "foo", "fooval");
|
|
28
|
|
29 # replace bar (should work)
|
|
30 print $sock "replace bar 0 0 6\r\nbarva2\r\n";
|
|
31 is(scalar <$sock>, "STORED\r\n", "replaced barval 2");
|
|
32
|
|
33 # replace notexist (shouldn't work)
|
|
34 print $sock "replace notexist 0 0 6\r\nbarva2\r\n";
|
|
35 is(scalar <$sock>, "NOT_STORED\r\n", "didn't replace notexist");
|
|
36
|
|
37 # delete foo.
|
|
38 print $sock "delete foo\r\n";
|
|
39 is(scalar <$sock>, "DELETED\r\n", "deleted foo");
|
|
40
|
|
41 # delete foo again. not found this time.
|
|
42 print $sock "delete foo\r\n";
|
|
43 is(scalar <$sock>, "NOT_FOUND\r\n", "deleted foo, but not found");
|
|
44
|
|
45 # pipeling is okay
|
|
46 print $sock "set foo 0 0 6\r\nfooval\r\ndelete foo\r\nset foo 0 0 6\r\nfooval\r\ndelete foo\r\n";
|
|
47 is(scalar <$sock>, "STORED\r\n", "pipeline set");
|
|
48 is(scalar <$sock>, "DELETED\r\n", "pipeline delete");
|
|
49 is(scalar <$sock>, "STORED\r\n", "pipeline set");
|
|
50 is(scalar <$sock>, "DELETED\r\n", "pipeline delete");
|
|
51
|
|
52
|
|
53 # Test sets up to a large size around 1MB.
|
|
54 # Everything up to 1MB - 1k should succeed, everything 1MB +1k should fail.
|
|
55
|
|
56 my $len = 1024;
|
|
57 while ($len < 1024*1028) {
|
|
58 my $val = "B"x$len;
|
|
59 print $sock "set foo_$len 0 0 $len\r\n$val\r\n";
|
|
60 if ($len > (1024*1024)) {
|
|
61 is(scalar <$sock>, "SERVER_ERROR object too large for cache\r\n", "failed to store size $len");
|
|
62 } else {
|
|
63 is(scalar <$sock>, "STORED\r\n", "stored size $len");
|
|
64 }
|
|
65 $len += 2048;
|
|
66 }
|
|
67
|