| 80 | | def testReservedDelete(self): |
|---|
| 81 | | """Test a delete with a reservation timestamp.""" |
|---|
| 82 | | self.mc.set("x", 5, 19, "somevalue") |
|---|
| 83 | | self.assertEquals((19, "somevalue"), self.mc.get("x")) |
|---|
| 84 | | self.mc.delete("x", 1) |
|---|
| 85 | | self.assertNotExists("x") |
|---|
| 86 | | try: |
|---|
| 87 | | self.mc.add("x", 5, 19, "ex2") |
|---|
| 88 | | self.fail("Expected failure to add during timed delete") |
|---|
| 89 | | except MemcachedError, e: |
|---|
| 90 | | self.assertEquals(memcacheConstants.ERR_EXISTS, e.status) |
|---|
| 91 | | time.sleep(1.1) |
|---|
| 92 | | self.mc.add("x", 5, 19, "ex2") |
|---|
| 93 | | |
|---|
| 94 | | def testFlush(self): |
|---|
| 95 | | """Test flushing.""" |
|---|
| 96 | | self.mc.set("x", 5, 19, "somevaluex") |
|---|
| 97 | | self.mc.set("y", 5, 17, "somevaluey") |
|---|
| 98 | | self.assertEquals((19, "somevaluex"), self.mc.get("x")) |
|---|
| 99 | | self.assertEquals((17, "somevaluey"), self.mc.get("y")) |
|---|
| 100 | | self.mc.flush() |
|---|
| 101 | | self.assertNotExists("x") |
|---|
| 102 | | self.assertNotExists("y") |
|---|
| 103 | | |
|---|
| 104 | | def testNoop(self): |
|---|
| 105 | | """Making sure noop is understood.""" |
|---|
| 106 | | self.mc.noop() |
|---|
| 107 | | |
|---|
| 108 | | def testAdd(self): |
|---|
| 109 | | """Test add functionality.""" |
|---|
| 110 | | self.assertNotExists("x") |
|---|
| 111 | | self.mc.add("x", 5, 19, "ex") |
|---|
| 112 | | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| 113 | | try: |
|---|
| 114 | | self.mc.add("x", 5, 19, "ex2") |
|---|
| 115 | | self.fail("Expected failure to add existing key") |
|---|
| 116 | | except MemcachedError, e: |
|---|
| 117 | | self.assertEquals(memcacheConstants.ERR_EXISTS, e.status) |
|---|
| 118 | | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| 119 | | |
|---|
| 120 | | def testReplace(self): |
|---|
| 121 | | """Test replace functionality.""" |
|---|
| 122 | | self.assertNotExists("x") |
|---|
| 123 | | try: |
|---|
| 124 | | self.mc.replace("x", 5, 19, "ex") |
|---|
| 125 | | self.fail("Expected failure to replace missing key") |
|---|
| 126 | | except MemcachedError, e: |
|---|
| 127 | | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| 128 | | self.mc.add("x", 5, 19, "ex") |
|---|
| 129 | | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| 130 | | self.mc.replace("x", 5, 19, "ex2") |
|---|
| 131 | | self.assertEquals((19, "ex2"), self.mc.get("x")) |
|---|
| 132 | | |
|---|
| 133 | | def testMultiGet(self): |
|---|
| 134 | | """Testing multiget functionality""" |
|---|
| 135 | | self.mc.add("x", 5, 1, "ex") |
|---|
| 136 | | self.mc.add("y", 5, 2, "why") |
|---|
| 137 | | vals=self.mc.getMulti('xyz') |
|---|
| 138 | | self.assertEquals((1, 'ex'), vals['x']) |
|---|
| 139 | | self.assertEquals((2, 'why'), vals['y']) |
|---|
| 140 | | self.assertEquals(2, len(vals)) |
|---|
| 141 | | |
|---|
| 142 | | def testIncrDoesntExistNoCreate(self): |
|---|
| 143 | | """Testing incr when a value doesn't exist (and not creating).""" |
|---|
| 144 | | try: |
|---|
| 145 | | self.mc.incr("x", exp=-1) |
|---|
| 146 | | self.fail("Expected failure to increment non-existent key") |
|---|
| 147 | | except MemcachedError, e: |
|---|
| 148 | | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| 149 | | self.assertNotExists("x") |
|---|
| 150 | | |
|---|
| 151 | | def testIncrDoesntExistCreate(self): |
|---|
| 152 | | """Testing incr when a value doesn't exist (and we make a new one)""" |
|---|
| 153 | | self.assertNotExists("x") |
|---|
| 154 | | self.assertEquals(19, self.mc.incr("x", init=19)) |
|---|
| 155 | | |
|---|
| 156 | | def testDecrDoesntExistNoCreate(self): |
|---|
| 157 | | """Testing decr when a value doesn't exist (and not creating).""" |
|---|
| 158 | | try: |
|---|
| 159 | | self.mc.decr("x", exp=-1) |
|---|
| 160 | | self.fail("Expected failiure to decrement non-existent key.") |
|---|
| 161 | | except MemcachedError, e: |
|---|
| 162 | | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| 163 | | self.assertNotExists("x") |
|---|
| 164 | | |
|---|
| 165 | | def testDecrDoesntExistCreate(self): |
|---|
| 166 | | """Testing decr when a value doesn't exist (and we make a new one)""" |
|---|
| 167 | | self.assertNotExists("x") |
|---|
| 168 | | self.assertEquals(19, self.mc.decr("x", init=19)) |
|---|
| 169 | | |
|---|
| | 120 | def testReservedDelete(self): |
|---|
| | 121 | """Test a delete with a reservation timestamp.""" |
|---|
| | 122 | self.mc.set("x", 5, 19, "somevalue") |
|---|
| | 123 | self.assertEquals((19, "somevalue"), self.mc.get("x")) |
|---|
| | 124 | self.mc.delete("x", 1) |
|---|
| | 125 | self.assertNotExists("x") |
|---|
| | 126 | try: |
|---|
| | 127 | self.mc.add("x", 5, 19, "ex2") |
|---|
| | 128 | self.fail("Expected failure to add during timed delete") |
|---|
| | 129 | except MemcachedError, e: |
|---|
| | 130 | self.assertEquals(memcacheConstants.ERR_EXISTS, e.status) |
|---|
| | 131 | time.sleep(1.1) |
|---|
| | 132 | self.mc.add("x", 5, 19, "ex2") |
|---|
| | 133 | |
|---|
| | 134 | def testFlush(self): |
|---|
| | 135 | """Test flushing.""" |
|---|
| | 136 | self.mc.set("x", 5, 19, "somevaluex") |
|---|
| | 137 | self.mc.set("y", 5, 17, "somevaluey") |
|---|
| | 138 | self.assertEquals((19, "somevaluex"), self.mc.get("x")) |
|---|
| | 139 | self.assertEquals((17, "somevaluey"), self.mc.get("y")) |
|---|
| | 140 | self.mc.flush() |
|---|
| | 141 | self.assertNotExists("x") |
|---|
| | 142 | self.assertNotExists("y") |
|---|
| | 143 | |
|---|
| | 144 | |
|---|
| | 145 | def testAdd(self): |
|---|
| | 146 | """Test add functionality.""" |
|---|
| | 147 | self.assertNotExists("x") |
|---|
| | 148 | self.mc.add("x", 5, 19, "ex") |
|---|
| | 149 | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| | 150 | try: |
|---|
| | 151 | self.mc.add("x", 5, 19, "ex2") |
|---|
| | 152 | self.fail("Expected failure to add existing key") |
|---|
| | 153 | except MemcachedError, e: |
|---|
| | 154 | self.assertEquals(memcacheConstants.ERR_EXISTS, e.status) |
|---|
| | 155 | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| | 156 | |
|---|
| | 157 | def testReplace(self): |
|---|
| | 158 | """Test replace functionality.""" |
|---|
| | 159 | self.assertNotExists("x") |
|---|
| | 160 | try: |
|---|
| | 161 | self.mc.replace("x", 5, 19, "ex") |
|---|
| | 162 | self.fail("Expected failure to replace missing key") |
|---|
| | 163 | except MemcachedError, e: |
|---|
| | 164 | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| | 165 | self.mc.add("x", 5, 19, "ex") |
|---|
| | 166 | self.assertEquals((19, "ex"), self.mc.get("x")) |
|---|
| | 167 | self.mc.replace("x", 5, 19, "ex2") |
|---|
| | 168 | self.assertEquals((19, "ex2"), self.mc.get("x")) |
|---|
| | 169 | |
|---|
| | 170 | def testMultiGet(self): |
|---|
| | 171 | """Testing multiget functionality""" |
|---|
| | 172 | self.mc.add("x", 5, 1, "ex") |
|---|
| | 173 | self.mc.add("y", 5, 2, "why") |
|---|
| | 174 | vals=self.mc.getMulti('xyz') |
|---|
| | 175 | self.assertEquals((1, 'ex'), vals['x']) |
|---|
| | 176 | self.assertEquals((2, 'why'), vals['y']) |
|---|
| | 177 | self.assertEquals(2, len(vals)) |
|---|
| | 178 | |
|---|
| | 179 | def testIncrDoesntExistNoCreate(self): |
|---|
| | 180 | """Testing incr when a value doesn't exist (and not creating).""" |
|---|
| | 181 | try: |
|---|
| | 182 | self.mc.incr("x", exp=-1) |
|---|
| | 183 | self.fail("Expected failure to increment non-existent key") |
|---|
| | 184 | except MemcachedError, e: |
|---|
| | 185 | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| | 186 | self.assertNotExists("x") |
|---|
| | 187 | |
|---|
| | 188 | def testIncrDoesntExistCreate(self): |
|---|
| | 189 | """Testing incr when a value doesn't exist (and we make a new one)""" |
|---|
| | 190 | self.assertNotExists("x") |
|---|
| | 191 | self.assertEquals(19, self.mc.incr("x", init=19)) |
|---|
| | 192 | |
|---|
| | 193 | def testDecrDoesntExistNoCreate(self): |
|---|
| | 194 | """Testing decr when a value doesn't exist (and not creating).""" |
|---|
| | 195 | try: |
|---|
| | 196 | self.mc.decr("x", exp=-1) |
|---|
| | 197 | self.fail("Expected failiure to decrement non-existent key.") |
|---|
| | 198 | except MemcachedError, e: |
|---|
| | 199 | self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status) |
|---|
| | 200 | self.assertNotExists("x") |
|---|
| | 201 | |
|---|
| | 202 | def testDecrDoesntExistCreate(self): |
|---|
| | 203 | """Testing decr when a value doesn't exist (and we make a new one)""" |
|---|
| | 204 | self.assertNotExists("x") |
|---|
| | 205 | self.assertEquals(19, self.mc.decr("x", init=19)) |
|---|
| | 206 | |
|---|
| | 361 | sub __incrdecr { |
|---|
| | 362 | my $self = shift; |
|---|
| | 363 | my ($cmd, $key, $amt, $init, $exp) = @_; |
|---|
| | 364 | return $self->_doCmd($cmd, $key, '', pack(::INCRDECR_PKT_FMT, $amt, $init, $exp)); |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | sub incr { |
|---|
| | 368 | my $self = shift; |
|---|
| | 369 | my ($key, $amt, $init, $exp) = @_; |
|---|
| | 370 | $amt = 1 unless defined $amt; |
|---|
| | 371 | $init = 0 unless defined $init; |
|---|
| | 372 | $exp = 0 unless defined $exp; |
|---|
| | 373 | |
|---|
| | 374 | return $self->__incrdecr(::CMD_INCR, $key, $amt, $init, $exp); |
|---|
| | 375 | } |
|---|
| | 376 | |
|---|
| | 377 | sub decr { |
|---|
| | 378 | my $self = shift; |
|---|
| | 379 | my ($key, $amt, $init, $exp) = @_; |
|---|
| | 380 | $amt = 1 unless defined $amt; |
|---|
| | 381 | $init = 0 unless defined $init; |
|---|
| | 382 | $exp = 0 unless defined $exp; |
|---|
| | 383 | |
|---|
| | 384 | return $self->__incrdecr(::CMD_INCR, $key, 0 - $amt, $init, $exp); |
|---|
| | 385 | } |
|---|
| | 386 | |
|---|