Mercurial > hg > memcached
comparison t/delete-window.t @ 0:30782bb1fc04 MEMCACHED_1_2_3
memcached-1.2.3
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 23 Sep 2007 03:58:34 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:30782bb1fc04 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 use strict; | |
4 use Test::More tests => 20; | |
5 use FindBin qw($Bin); | |
6 use lib "$Bin/lib"; | |
7 use MemcachedTest; | |
8 | |
9 my $server = new_memcached(); | |
10 my $sock = $server->sock; | |
11 my $line = sub { return scalar <$sock> }; | |
12 | |
13 # immediate set/deletes | |
14 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"; | |
15 is($line->(), "STORED\r\n", "pipeline set"); | |
16 is($line->(), "DELETED\r\n", "pipeline delete"); | |
17 is($line->(), "STORED\r\n", "pipeline set"); | |
18 is($line->(), "DELETED\r\n", "pipeline delete"); | |
19 | |
20 # not found test | |
21 print $sock "delete foo\r\n"; | |
22 is($line->(), "NOT_FOUND\r\n", "thing not found to delete"); | |
23 | |
24 # test the cool-down window (see protocol doc) whereby add/replace commands can't | |
25 # work n seconds after deleting. | |
26 print $sock "set foo 0 0 3\r\nbar\r\n"; | |
27 is($line->(), "STORED\r\n", "stored foo"); | |
28 print $sock "delete foo 1\r\n"; | |
29 is($line->(), "DELETED\r\n", "deleted with 1 second window"); | |
30 mem_get_is($sock, "foo", undef); | |
31 print $sock "add foo 0 0 7\r\nfoo-add\r\n"; | |
32 is($line->(), "NOT_STORED\r\n", "didn't add foo"); | |
33 print $sock "replace foo 0 0 11\r\nfoo-replace\r\n"; | |
34 is($line->(), "NOT_STORED\r\n", "didn't replace foo"); | |
35 print $sock "set foo 0 0 7\r\nfoo-set\r\n"; | |
36 is($line->(), "STORED\r\n", "stored foo-set"); | |
37 | |
38 # add can work after expiration time | |
39 print $sock "set foo 0 0 3\r\nbar\r\n"; | |
40 is($line->(), "STORED\r\n", "stored foo"); | |
41 print $sock "delete foo 1\r\n"; | |
42 is($line->(), "DELETED\r\n", "deleted with 1 second window"); | |
43 sleep(1.2); | |
44 print $sock "add foo 0 0 7\r\nfoo-add\r\n"; | |
45 is($line->(), "STORED\r\n", "stored foo-add"); | |
46 | |
47 mem_get_is($sock, "foo", "foo-add", "foo == 'foo-add' (before deleter)"); | |
48 | |
49 # test 'baz' with set, delete w/ timer, set, wait 5.2 seconds (for 5 | |
50 # second deleter event), then get to see which we get. | |
51 print $sock "set baz 0 0 4\r\nval1\r\n"; | |
52 is($line->(), "STORED\r\n", "stored baz = val1"); | |
53 print $sock "delete baz 1\r\n"; | |
54 is($line->(), "DELETED\r\n", "deleted with 1 second window"); | |
55 print $sock "set baz 0 0 4\r\nval2\r\n"; | |
56 is($line->(), "STORED\r\n", "stored baz = val2"); | |
57 | |
58 diag("waiting 5 seconds for the deleter event..."); | |
59 sleep(5.2); | |
60 | |
61 # follow-up on 1st test: | |
62 mem_get_is($sock, "foo", "foo-add", "foo == 'foo-add' (after deleter)"); | |
63 | |
64 # and follow-up on 2nd test: | |
65 mem_get_is($sock, "baz", "val2", "baz=='val2'"); | |
66 | |
67 | |
68 |