forked from dustin/memcached-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestClient-CollSOPEvictTest.py
executable file
·102 lines (90 loc) · 3.24 KB
/
testClient-CollSOPEvictTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
"""
Binary memcached test client.
Copyright (c) 2007 Dustin Sallings <[email protected]>
"""
import sys
import time
import hmac
import socket
import random
import struct
import exceptions
import unittest
import memcacheConstants
from mc_bin_client import MemcachedClient, MemcachedError
class ComplianceTest(unittest.TestCase):
def setUp(self):
self.mc=MemcachedClient()
self.mc.flush()
def tearDown(self):
self.mc.flush()
self.mc.close()
def assertNotExists(self, key):
try:
x=self.mc.get(key)
self.fail("Expected an exception, got " + `x`)
except MemcachedError, e:
self.assertEquals(memcacheConstants.ERR_NOT_FOUND, e.status)
def assertGet(self, exp, gv):
self.assertTrue(gv is not None)
self.assertEquals((gv[0], gv[2]), exp)
def getData(self, key, index):
data = key + "_data_" + str(index)
return data
def testSOPLongRun(self):
""" Test sop long run. """
key_cnt_ini = 600
key_cnt_run = 500
dat_cnt = 4000
print "SOP prepare begin"
for x in range(0, key_cnt_ini):
skey = "skey" + str(x)
for y in range(0, dat_cnt):
data = self.getData(skey, y)
if y == 0: create = 1
else: create = 0
self.mc.sop_insert(skey, data, create, 13, 0, 0)
if x % 10 == 9:
print " " + str(x+1) + " sets created"
print "SOP prepare end"
print "SOP run begin"
for x in range(0, key_cnt_run):
""" SOP insert """
kidx = x + key_cnt_ini
skey = "skey" + str(kidx)
vals = []
for y in range(0, dat_cnt):
data = self.getData(skey, y)
vals.append(data)
if y == 0: create = 1
else: create = 0
self.mc.sop_insert(skey, data, create, 13, 0, 0)
""" SOP get """
self.assertEquals((13, dat_cnt, set(vals)), self.mc.sop_get(skey, dat_cnt))
""" rcnt: run count """
""" didx: data index """
for kidx in range(x+key_cnt_ini, x+key_cnt_ini-10, -1):
skey = "skey" + str(kidx)
for rcnt in range(0, 50):
didx = random.randrange(0, dat_cnt/2)
data = self.getData(skey, didx)
self.assertEquals(1, self.mc.sop_exist(skey, data))
for kidx in range(x, x+10, 1):
skey = "skey" + str(kidx)
self.assertNotExists(skey)
""" SOP delete """
for kidx in range(x+key_cnt_ini, x+key_cnt_ini-10, -1):
skey = "skey" + str(kidx)
for rcnt in range(0, 50):
didx = random.randrange(dat_cnt/2, dat_cnt)
data = self.getData(skey, didx)
exist = self.mc.sop_exist(skey, data)
if (exist == 1):
self.mc.sop_delete(skey, data)
""" SOP run check """
if x % 10 == 9:
print " " + str(x+1) + " SOP runs"
print "SOP run end"
if __name__ == '__main__':
unittest.main()