Changeset 677
- Timestamp:
- 12/13/07 01:12:36 (1 year ago)
- Files:
-
- branches/binary/server/t/binary.t (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/binary/server/t/binary.t
r676 r677 9 9 10 10 # Command constants 11 # CMD_GET = 0 11 use constant CMD_GET => 0; 12 12 use constant CMD_SET => 1; 13 13 # CMD_ADD = 2 14 14 # CMD_REPLACE = 3 15 # CMD_DELETE = 4 15 use constant CMD_DELETE => 4; 16 16 # CMD_INCR = 5 17 17 # CMD_QUIT = 6 … … 25 25 # 26 26 # Flags, expiration 27 use constant SET_PKT_FMT => " Ll";27 use constant SET_PKT_FMT => "NN"; 28 28 # flags, expiration, id 29 29 # CAS_PKT_FMT=">IiQ" 30 30 # 31 31 # How long until the deletion takes effect. 32 # DEL_PKT_FMT=">i" 32 use constant DEL_PKT_FMT => "N"; 33 33 # 34 34 # amount, initial value, expiration … … 38 38 use constant RES_MAGIC_BYTE => 0xf0; 39 39 # 40 use constant PKT_FMT => "CCCx LL";40 use constant PKT_FMT => "CCCxNN"; 41 41 #min recv packet size 42 42 use constant MIN_RECV_PACKET => length(pack(PKT_FMT)); … … 50 50 $mc->flush; 51 51 52 # Test Version 52 diag "Test Version"; 53 53 { 54 54 my $v = $mc->version; … … 56 56 } 57 57 58 # Simple set/get 59 { 60 $mc->set('x', 5, 19, "somevalue"); 61 my ($flags, $value) = $mc->get("x"); 62 is($flags, 19, "Flags is set properly"); 63 is($value, "somevalue", "Value is set properly"); 64 } 58 my $set = sub { 59 my ($key, $exp, $orig_flags, $orig_value) = @_; 60 $mc->set($key, $exp, $orig_flags, $orig_value); 61 my ($flags, $value) = $mc->get($key); 62 is($flags, $orig_flags, "Flags is set properly"); 63 is($value, $orig_value, "Value is set properly"); 64 }; 65 66 diag "Simple set/get"; 67 $set->('x', 5, 19, "somevalue"); 68 69 my $delete = sub { 70 my ($key) = @_; 71 $mc->delete($key); 72 my $rv =()= $mc->get($key); 73 is($rv, 0, "Empty array from get means nothing stored here"); 74 }; 75 76 diag "Delete"; 77 $delete->('x'); 65 78 66 79 <<EOT; 67 def assertNotExists(self, key):68 try:69 x=self.mc.get(key)70 self.fail("Expected an exception, got " + `x`)71 except MemcachedError, e:72 self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status)73 74 def testDelete(self):75 """Test a set, get, delete, get sequence."""76 self.mc.set("x", 5, 19, "somevalue")77 self.assertEquals((19, "somevalue"), self.mc.get("x"))78 self.mc.delete("x")79 self.assertNotExists("x")80 81 80 def testReservedDelete(self): 82 81 """Test a delete with a reservation timestamp.""" … … 253 252 sub close { 254 253 my $self = shift; 255 return $self-> close(@_);254 return $self->{socket}->close(@_); 256 255 } 257 256 … … 315 314 } 316 315 316 sub __parseGet { 317 my $self = shift; 318 my $rv = shift; # currently contains 4 bytes of 'flag' followed by value 319 my $flag = substr $rv, 0, 4, ''; # Now $flag contains flags, $rv contains value 320 return unpack("N", $flag), $rv; 321 } 322 323 sub get { 324 my $self = shift; 325 my $key = shift; 326 my $parts = $self->_doCmd(::CMD_GET, $key, ''); 327 return $self->__parseGet($parts); 328 } 329 317 330 sub _mutate { 318 331 my $self = shift; … … 350 363 """Replace a value in the memcached server iff it already exists.""" 351 364 self._mutate(memcacheConstants.CMD_REPLACE, key, exp, flags, val) 352 353 def __parseGet(self, data):354 return struct.unpack(">I", data[:4])[0], data[4:]355 356 def get(self, key):357 """Get the value for a given key within the memcached server."""358 parts=self._doCmd(memcacheConstants.CMD_GET, key, '')359 return self.__parseGet(parts)360 365 361 366 def gets(self, key): … … 405 410 EOT 406 411 412 sub delete { 413 my $self = shift; 414 my ($key, $when) = @_; 415 $when = 0 unless defined $when; 416 417 return $self->_doCmd(::CMD_DELETE, $key, '', pack(::DEL_PKT_FMT, $when)); 418 } 419 407 420 sub version { 408 421 my $self = shift;
