diff options
author | Dustin Sallings <dustin@spy.net> | 2007-10-03 19:59:11 +0000 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2007-10-03 19:59:11 +0000 |
commit | fc2e8effbb555e853bb71bdc0d01525a5a9dbfe3 (patch) | |
tree | d56ddd8c7e8ab5c707561eb6caeeaabb1af99e44 /t/getset.t | |
parent | 058050572dd7d34e7c3c52be0af3c5b47dd1fb6c (diff) | |
download | memcached-fc2e8effbb555e853bb71bdc0d01525a5a9dbfe3.tar.gz |
Incorporate "cas" operation developed by Dustin Sallings
<dustin@spy.net> and implemented by Chris Goffinet
<goffinet@yahoo-inc.com>. This change allows you to do
atomic changes to an existing key.
git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@615 b0b603af-a30f-0410-a34e-baf09ae79d0b
Diffstat (limited to 't/getset.t')
-rwxr-xr-x | t/getset.t | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 528; +use Test::More tests => 535; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -42,6 +42,33 @@ is(scalar <$sock>, "DELETED\r\n", "deleted foo"); 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"); + # pipeling 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"); |