-
Notifications
You must be signed in to change notification settings - Fork 82
/
consistency_test.py
209 lines (161 loc) · 7.33 KB
/
consistency_test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from time import sleep
from dtest import Tester
from assertions import *
from tools import *
class TestConsistency(Tester):
def quorum_quorum_test(self):
cluster = self.cluster
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
cursor1 = self.cql_connection(node1).cursor()
self.create_ks(cursor1, 'ks', 3)
self.create_cf(cursor1, 'cf')
cursor2 = self.cql_connection(node2, 'ks').cursor()
# insert and get at CL.QUORUM
for n in xrange(0, 100):
insert_c1c2(cursor1, n, "QUORUM")
query_c1c2(cursor2, n, "QUORUM")
# shutdown a node an test again
node3.stop(wait_other_notice=True)
for n in xrange(100, 200):
insert_c1c2(cursor1, n, "QUORUM")
query_c1c2(cursor2, n, "QUORUM")
# shutdown another node and test we get unavailabe exception
node2.stop(wait_other_notice=True)
assert_unavailable(insert_c1c2, cursor1, 200, "QUORUM")
def all_all_test(self):
cluster = self.cluster
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
cursor1 = self.cql_connection(node1).cursor()
self.create_ks(cursor1, 'ks', 3)
self.create_cf(cursor1, 'cf')
cursor2 = self.cql_connection(node2, 'ks').cursor()
# insert and get at CL.ALL
for n in xrange(0, 100):
insert_c1c2(cursor1, n, "ALL")
query_c1c2(cursor2, n, "ALL")
# shutdown one node and test we get unavailabe exception
node3.stop(wait_other_notice=True)
assert_unavailable(insert_c1c2, cursor1, 100, "ALL")
def one_one_test(self):
cluster = self.cluster
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
cursor1 = self.cql_connection(node1).cursor()
self.create_ks(cursor1, 'ks', 3)
self.create_cf(cursor1, 'cf')
cursor2 = self.cql_connection(node2, 'ks').cursor()
# insert and get at CL.ONE
for n in xrange(0, 100):
insert_c1c2(cursor1, n, "ONE")
retry_till_success(query_c1c2, cursor2, n, "ONE", timeout=5)
# shutdown a node an test again
node3.stop(wait_other_notice=True)
for n in xrange(100, 200):
insert_c1c2(cursor1, n, "ONE")
retry_till_success(query_c1c2, cursor2, n, "ONE", timeout=5)
# shutdown a second node an test again
node2.stop(wait_other_notice=True)
for n in xrange(200, 300):
insert_c1c2(cursor1, n, "ONE")
retry_till_success(query_c1c2, cursor1, n, "ONE", timeout=5)
def one_all_test(self):
cluster = self.cluster
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
cursor1 = self.cql_connection(node1).cursor()
self.create_ks(cursor1, 'ks', 3)
self.create_cf(cursor1, 'cf')
cursor2 = self.cql_connection(node2, 'ks').cursor()
# insert and get at CL.ONE
for n in xrange(0, 100):
insert_c1c2(cursor1, n, "ONE")
query_c1c2(cursor2, n, "ALL")
# shutdown a node an test again
node3.stop(wait_other_notice=True)
insert_c1c2(cursor1, 100, "ONE")
assert_unavailable(query_c1c2, cursor2, 100, "ALL")
def all_one_test(self):
cluster = self.cluster
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
cursor1 = self.cql_connection(node1).cursor()
self.create_ks(cursor1, 'ks', 3)
self.create_cf(cursor1, 'cf')
cursor2 = self.cql_connection(node2, 'ks').cursor()
# insert and get at CL.ONE
for n in xrange(0, 100):
insert_c1c2(cursor1, n, "ALL")
query_c1c2(cursor2, n, "ONE")
# shutdown a node an test again
node3.stop(wait_other_notice=True)
assert_unavailable(insert_c1c2, cursor1, 100, "ALL")
def short_read_test(self):
cluster = self.cluster
# Disable hinted handoff and set batch commit log so this doesn't
# interfer with the test
cluster.set_configuration_options(values={ 'hinted_handoff_enabled' : False}, batch_commitlog=True)
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
time.sleep(.5)
cursor = self.cql_connection(node1).cursor()
self.create_ks(cursor, 'ks', 3)
self.create_cf(cursor, 'cf', read_repair=0.0)
# insert 9 columns in one row
insert_columns(cursor, 0, 9)
cursor.close()
# Deleting 3 first columns with a different node dead each time
self.stop_delete_and_restart(1, 0)
self.stop_delete_and_restart(2, 1)
self.stop_delete_and_restart(3, 2)
# Query 3 firsts columns
cursor = self.cql_connection(node1, 'ks').cursor()
cursor.execute('SELECT FIRST 3 * FROM cf USING CONSISTENCY QUORUM WHERE key=k0')
assert cursor.rowcount == 1
res = cursor.fetchone()
# the key is returned
assert len(res) - 1 == 3, 'Expecting 3 values (excluding the key), got %d (%s)' % (len(res) - 1, str(res))
assert res[0] == 'k0', str(res)
# value 0, 1 and 2 have been deleted
for i in xrange(1, 4):
assert res[i] == 'value%d' % (i+2), 'Expecting value%d, got %s (%s)' % (i+2, res[i], str(res))
def short_read_reversed_test(self):
cluster = self.cluster
# Disable hinted handoff and set batch commit log so this doesn't
# interfer with the test
cluster.set_configuration_options(values={ 'hinted_handoff_enabled' : False}, batch_commitlog=True)
cluster.populate(3).start()
[node1, node2, node3] = cluster.nodelist()
time.sleep(.5)
cursor = self.cql_connection(node1).cursor()
self.create_ks(cursor, 'ks', 3)
self.create_cf(cursor, 'cf', read_repair=0.0)
# insert 9 columns in one row
insert_columns(cursor, 0, 9)
cursor.close()
# Deleting 3 last columns with a different node dead each time
self.stop_delete_and_restart(1, 6)
self.stop_delete_and_restart(2, 7)
self.stop_delete_and_restart(3, 8)
# Query 3 firsts columns
cursor = self.cql_connection(node1, 'ks').cursor()
cursor.execute('SELECT FIRST 3 REVERSED * FROM cf USING CONSISTENCY QUORUM WHERE key=k0')
assert cursor.rowcount == 1
res = cursor.fetchone()
# the key is returned
assert len(res) - 1 == 3, 'Expecting 3 values (excluding the key), got %d (%s)' % (len(res) - 1, str(res))
assert res[len(res) - 1] == 'k0', str(res)
# value 6, 7 and 8 have been deleted
for i in xrange(0, 3):
assert res[i] == 'value%d' % (5-i), 'Expecting value%d, got %s (%s)' % (5-i, res[i], str(res))
def stop_delete_and_restart(self, node_number, column):
to_stop = self.cluster.nodes["node%d" % node_number]
next_node = self.cluster.nodes["node%d" % (((node_number + 1) % 3) + 1)]
to_stop.flush()
to_stop.stop(wait_other_notice=True)
cursor = self.cql_connection(next_node, 'ks').cursor()
cursor.execute('DELETE c%d, c2 FROM cf USING CONSISTENCY QUORUM WHERE key=k0' % column)
cursor.close()
to_stop.set_log_level("DEBUG")
to_stop.start(wait_other_notice=True)