Changeset 680

Show
Ignore:
Timestamp:
12/13/07 07:48:54 (1 year ago)
Author:
hachi
Message:

64bit tests work on 32bit by cheating and using doubles and not bitshifting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/binary/server/t/binary.t

    r679 r680  
    1515use constant CMD_DELETE  => 4; 
    1616use constant CMD_INCR    => 5; 
    17 # CMD_QUIT = 6 
     17use constant CMD_QUIT    => 6; 
    1818use constant CMD_FLUSH   => 7; 
    19 # CMD_GETQ = 8 
     19use constant CMD_GETQ    => 8; 
    2020use constant CMD_NOOP    => 9; 
    2121use constant CMD_VERSION => 10; 
    22 
    23 # CMD_GETS = 50 
    24 # CMD_CAS = 51 
    25 
     22 
     23use constant CMD_GETS    => 50; 
     24use constant CMD_CAS     => 51; 
     25 
    2626# Flags, expiration 
    2727use constant SET_PKT_FMT => "NN"; 
     
    3434# amount, initial value, expiration 
    3535use constant INCRDECR_PKT_FMT => "NNNNN"; 
    36 
     36 
    3737use constant REQ_MAGIC_BYTE => 0x0f; 
    3838use constant RES_MAGIC_BYTE => 0xf0; 
    39 
     39 
    4040use constant PKT_FMT => "CCCxNN"; 
    4141#min recv packet size 
    4242use constant MIN_RECV_PACKET => length(pack(PKT_FMT)); 
    43 # 
    44 # 
    4543 
    4644my $mc = MC::Client->new; 
    47 $mc->flush; 
    48  
    49 diag "Test Version"; 
    50 
    51         my $v = $mc->version; 
    52         ok(defined $v && length($v), "Proper version"); 
    53 
    54  
    55 my $set = sub { 
    56         my ($key, $exp, $orig_flags, $orig_value) = @_; 
    57         $mc->set($key, $exp, $orig_flags, $orig_value); 
     45my $check = sub { 
     46        my ($key, $orig_flags, $orig_value) = @_; 
    5847        my ($flags, $value) = $mc->get($key); 
    5948        is($flags, $orig_flags, "Flags is set properly"); 
    6049        is($value, $orig_value, "Value is set properly"); 
    6150}; 
     51 
     52my $set = sub { 
     53        my ($key, $exp, $orig_flags, $orig_value) = @_; 
     54        $mc->set($key, $exp, $orig_flags, $orig_value); 
     55        $check->($key, $orig_flags, $orig_value); 
     56}; 
     57 
     58my $empty = sub { 
     59        my $key = shift; 
     60        my $rv =()= eval { $mc->get($key) }; 
     61        is($rv, 0, "Didn't get a result from get"); 
     62        ok($@->not_found, "We got a not found error when we expected one"); 
     63 
     64}; 
     65 
     66my $delete = sub { 
     67        my ($key, $when) = @_; 
     68        $mc->delete($key, $when); 
     69        $empty->($key); 
     70}; 
     71 
     72$mc->flush if 0; 
     73 
     74{ 
     75        diag "Test Version"; 
     76        my $v = $mc->version; 
     77        ok(defined $v && length($v), "Proper version"); 
     78} 
    6279 
    6380diag "Noop"; 
     
    6784$set->('x', 5, 19, "somevalue"); 
    6885 
    69 my $empty = sub { 
    70         my $key = shift; 
    71         my $rv =()= eval { $mc->get($key) }; 
    72         is($rv, 0, "Didn't get a result from get"); 
    73         ok($@->not_found, "We got a not found error when we expected one"); 
    74  
    75 }; 
    76  
    77 my $delete = sub { 
    78         my ($key, $when) = @_; 
    79         $mc->delete($key, $when); 
    80         $empty->($key); 
    81 }; 
    82  
    8386diag "Delete"; 
    8487$delete->('x'); 
    8588 
    8689diag "Flush"; 
     90$set->('x', 5, 19, "somevaluex"); 
     91$set->('y', 5, 17, "somevaluey"); 
     92$mc->flush; 
     93$empty->('x'); 
     94$empty->('y'); 
     95 
     96diag "Test increment"; 
     97$mc->flush; 
     98is($mc->incr("x"), 0, "First incr call is zero"); 
     99is($mc->incr("x"), 1, "Second incr call is one"); 
     100is($mc->incr("x", 211), 212, "Adding 211 gives you 212"); 
     101is($mc->incr("x", 2**33), 8589934804, "Blast the 32bit border"); 
     102 
    87103{ 
    88         $set->('x', 5, 19, "somevaluex"); 
    89         $set->('y', 5, 17, "somevaluey"); 
    90         $mc->flush; 
    91         $empty->('x'); 
    92         $empty->('y'); 
    93 
    94  
    95 diag "Test increment"; 
    96 
    97         $mc->flush; 
    98         is($mc->incr("x"), 0, "First incr call is zero"); 
    99         is($mc->incr("x"), 1, "Second incr call is one"); 
    100         is($mc->incr("x", 211), 212, "Adding 211 gives you 212"); 
    101         is($mc->incr("x", 2**33), 858993480, "Blast the 32bit border"); 
    102 
    103  
    104 diag "Reservation delete"; 
    105 
     104        diag "Reservation delete"; 
    106105        $set->('y', 5, 19, "someothervalue"); 
    107106        $delete->('y', 1); 
     
    113112} 
    114113 
     114{ 
     115        diag "Add"; 
     116        $empty->('i'); 
     117        $mc->add('i', 5, 19, "ex"); 
     118        $check->('i', 19, "ex"); 
     119 
     120        my $rv =()= eval { $mc->add('i', 5, 19, "ex2") }; 
     121        is($rv, 0, "Add didn't return anything"); 
     122        ok($@->exists, "Expected exists error received"); 
     123         
     124        $check->('i', 19, "ex"); 
     125} 
     126 
     127{ 
     128        diag "Replace"; 
     129        $empty->('j'); 
     130 
     131        my $rv =()= eval { $mc->replace('j', 5, 19, "ex") }; 
     132        is($rv, 0, "Replace didn't return anything"); 
     133        ok($@->not_found, "Expected not_found error received"); 
     134 
     135        $empty->('j'); 
     136         
     137        $mc->add('j', 5, 14, "ex2"); 
     138        $check->('j', 14, "ex2"); 
     139         
     140        $mc->replace('j', 5, 24, "ex3"); 
     141        $check->('j', 24, "ex3"); 
     142} 
     143 
    115144<<EOT; 
    116  
    117     def testAdd(self): 
    118         """Test add functionality.""" 
    119         self.assertNotExists("x") 
    120         self.mc.add("x", 5, 19, "ex") 
    121         self.assertEquals((19, "ex"), self.mc.get("x")) 
    122         try: 
    123             self.mc.add("x", 5, 19, "ex2") 
    124             self.fail("Expected failure to add existing key") 
    125         except MemcachedError, e: 
    126             self.assertEquals(memcacheConstants.ERR_EXISTS, e.status) 
    127         self.assertEquals((19, "ex"), self.mc.get("x")) 
    128  
    129     def testReplace(self): 
    130         """Test replace functionality.""" 
    131         self.assertNotExists("x") 
    132         try: 
    133             self.mc.replace("x", 5, 19, "ex") 
    134             self.fail("Expected failure to replace missing key") 
    135         except MemcachedError, e: 
    136             self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) 
    137         self.mc.add("x", 5, 19, "ex") 
    138         self.assertEquals((19, "ex"), self.mc.get("x")) 
    139         self.mc.replace("x", 5, 19, "ex2") 
    140         self.assertEquals((19, "ex2"), self.mc.get("x")) 
    141  
    142145    def testMultiGet(self): 
    143146        """Testing multiget functionality""" 
     
    334337        my $self = shift; 
    335338        my ($cmd, $key, $amt, $init, $exp) = @_; 
    336         return $self->_doCmd($cmd, $key, '', pack(::INCRDECR_PKT_FMT, $amt >> 32, 0xFFFFFFFF & $amt, $init >> 32, 0xFFFFFFFF & $init, $exp)); 
     339 
     340        my $amt_hi = int($amt / 2 ** 32); 
     341        my $amt_lo = int($amt % 2 ** 32); 
     342 
     343        my $init_hi = int($init / 2 ** 32); 
     344        my $init_lo = int($init % 2 ** 32); 
     345 
     346        return $self->_doCmd($cmd, $key, '', pack(::INCRDECR_PKT_FMT, $amt_hi, $amt_lo, $init_hi, $init_lo, $exp)); 
    337347} 
    338348 
     
    368378} 
    369379 
     380sub gets { 
     381        my $self = shift; 
     382        my $key = shift; 
     383 
     384        my $data = $self->_doCmd(::CMD_GETS, $key, ''); 
     385        my $header = substr $data, 0, 12, ''; 
     386        my ($flags, $ident_hi, $ident_lo) = unpack "NNN", $data; 
     387        my $ident = ($ident_hi * 2 ** 32) + $ident_lo; 
     388 
     389        return $flags, $ident, $data; 
     390} 
     391 
    370392<<EOT; 
    371     def gets(self, key): 
    372         """Get with an identifier (for cas).""" 
    373         data=self._doCmd(memcacheConstants.CMD_GETS, key, '') 
    374         parts=struct.unpack(">IQ", data[:12]) 
    375         return parts[0], parts[1], data[12:] 
    376  
    377393    def cas(self, key, exp, flags, oldVal, val): 
    378394        """CAS in a new value for the given key and comparison value."""