forked from dustin/memcached-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestClient-CollBOPEvictTest.py
executable file
·111 lines (99 loc) · 3.62 KB
/
testClient-CollBOPEvictTest.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
103
104
105
106
107
108
109
110
111
#!/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 testBOPLongRun(self):
""" Test bop long run. """
key_cnt_ini = 600
key_cnt_run = 500
dat_cnt = 4000
print "BOP prepare begin"
for x in range(0, key_cnt_ini):
bkey = "bkey" + str(x)
for y in range(0, dat_cnt):
data = self.getData(bkey, y)
if y == 0: create = 1
else: create = 0
self.mc.bop_insert(bkey, y, data, create, 11, 0, 0)
if x % 10 == 9:
print " " + str(x+1) + " b+trees created"
print "BOP prepare end"
print "BOP run begin"
for x in range(0, key_cnt_run):
""" BOP insert """
kidx = x + key_cnt_ini
bkey = "bkey" + str(kidx)
for y in range(0, dat_cnt):
data = self.getData(bkey, y)
if y == 0: create = 1
else: create = 0
self.mc.bop_insert(bkey, y, data, create, 11, 0, 0)
""" BOP get """
""" rcnt: run count """
""" dcnt: data count """
""" didx: data index """
for kidx in range(x+key_cnt_ini, x+key_cnt_ini-10, -1):
bkey = "bkey" + str(kidx)
for rcnt in range(0, 10):
keys = []
vals = []
lkey = random.randrange(0, dat_cnt/2)
rkey = random.randrange(0, dat_cnt/2)
if lkey <= rkey:
dcnt = rkey - lkey + 1
for didx in range(lkey, rkey+1, 1):
data = self.getData(bkey, didx)
keys.append(didx)
vals.append(data)
else:
dcnt = lkey - rkey + 1;
for didx in range(lkey, rkey-1, -1):
data = self.getData(bkey, didx)
keys.append(didx)
vals.append(data)
self.assertEquals((11, dcnt, keys, vals), self.mc.bop_get(bkey, lkey, rkey))
for kidx in range(x, x+10, 1):
bkey = "bkey" + str(kidx)
self.assertNotExists(bkey)
""" BOP delete """
kidx = x + key_cnt_ini
bkey = "bkey" + str(kidx)
lkey = random.randrange(dat_cnt/2, dat_cnt)
rkey = random.randrange(dat_cnt/2, dat_cnt)
self.mc.bop_delete(bkey, lkey, rkey)
""" BOP run check """
if x % 10 == 9:
print " " + str(x+1) + " BOP runs"
print "BOP run end"
if __name__ == '__main__':
unittest.main()