forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetset.t
executable file
·119 lines (98 loc) · 3.68 KB
/
getset.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env perl
use strict;
use Test::More tests => 37991;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
my $server = new_memcached('-m 128');
my $sock = $server->sock;
# set foo (and should get it)
print $sock "set foo 0 0 6\r\nfooval\r\n";
is(scalar <$sock>, "STORED\r\n", "stored foo");
mem_get_is($sock, "foo", "fooval");
# add bar (and should get it)
print $sock "add bar 0 0 6\r\nbarval\r\n";
is(scalar <$sock>, "STORED\r\n", "stored barval");
mem_get_is($sock, "bar", "barval");
# add foo (but shouldn't get new value)
print $sock "add foo 0 0 5\r\nfoov2\r\n";
is(scalar <$sock>, "NOT_STORED\r\n", "not stored");
mem_get_is($sock, "foo", "fooval");
# replace bar (should work)
print $sock "replace bar 0 0 6\r\nbarva2\r\n";
is(scalar <$sock>, "STORED\r\n", "replaced barval 2");
# replace notexist (shouldn't work)
print $sock "replace notexist 0 0 6\r\nbarva2\r\n";
is(scalar <$sock>, "NOT_STORED\r\n", "didn't replace notexist");
# delete foo.
print $sock "delete foo\r\n";
is(scalar <$sock>, "DELETED\r\n", "deleted foo");
# delete foo again. not found this time.
print $sock "delete foo\r\n";
is(scalar <$sock>, "NOT_FOUND\r\n", "deleted foo, but not found");
# add moo
#
print $sock "add moo 0 0 6\r\nmooval\r\n";
is(scalar <$sock>, "STORED\r\n", "stored barval");
mem_get_is($sock, "moo", "mooval");
# check-and-set (cas) failure case, try to set value with incorrect cas unique val
print $sock "cas moo 0 0 6 0\r\nMOOVAL\r\n";
is(scalar <$sock>, "EXISTS\r\n", "check and set with invalid id");
# test "gets", grab unique ID
print $sock "gets moo\r\n";
# VALUE moo 0 6 3084947704
#
my @retvals = split(/ /, scalar <$sock>);
my $data = scalar <$sock>; # grab data
my $dot = scalar <$sock>; # grab dot on line by itself
is($retvals[0], "VALUE", "get value using 'gets'");
my $unique_id = $retvals[4];
# clean off \r\n
$unique_id =~ s/\r\n$//;
ok($unique_id =~ /^\d+$/, "unique ID '$unique_id' is an integer");
# now test that we can store moo with the correct unique id
print $sock "cas moo 0 0 6 $unique_id\r\nMOOVAL\r\n";
is(scalar <$sock>, "STORED\r\n");
mem_get_is($sock, "moo", "MOOVAL");
# pipeline is okay
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";
is(scalar <$sock>, "STORED\r\n", "pipeline set");
is(scalar <$sock>, "DELETED\r\n", "pipeline delete");
is(scalar <$sock>, "STORED\r\n", "pipeline set");
is(scalar <$sock>, "DELETED\r\n", "pipeline delete");
# Test sets up to a large size around 1MB.
# Everything up to 1MB - 1k should succeed, everything 1MB +1k should fail.
my $len = 1024;
while ($len < 1024*1028) {
my $val = "B"x$len;
if ($len > (1024*1024)) {
# Ensure causing a memory overflow doesn't leave stale data.
print $sock "set foo_$len 0 0 3\r\nMOO\r\n";
is(scalar <$sock>, "STORED\r\n");
print $sock "set foo_$len 0 0 $len\r\n$val\r\n";
is(scalar <$sock>, "SERVER_ERROR object too large for cache\r\n", "failed to store size $len");
mem_get_is($sock, "foo_$len");
} else {
print $sock "set foo_$len 0 0 $len\r\n$val\r\n";
is(scalar <$sock>, "STORED\r\n", "stored size $len");
}
$len += 2048;
}
{
# Test large ASCII multigets.
print $sock "set foobarbaz 0 0 2\r\nhi\r\n";
is(scalar <$sock>, "STORED\r\n", "base foo stored");
my $len = 1024 * 128;
my $klist = '';
my $kcount = 0;
for (my $x = 0; $x < $len; $x += 7) {
$klist .= "foobarbaz ";
$kcount++;
}
print $sock "get $klist\r\n";
while ($kcount--) {
is(scalar <$sock>, "VALUE foobarbaz 0 2\r\n", "foo returned");
is(scalar <$sock>, "hi\r\n", "foo 'hi' returned");
}
is(scalar <$sock>, "END\r\n", "foo END seen");
}