-
Notifications
You must be signed in to change notification settings - Fork 82
/
topology_test.py
142 lines (107 loc) · 4.4 KB
/
topology_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
from dtest import Tester
from tools import *
from assertions import *
import os, sys, time
from ccmlib.cluster import Cluster
class TestTopology(Tester):
def movement_test(self):
cluster = self.cluster
# Create an unbalanced ring
cluster.populate(3, tokens=[0, 2**125, 2**124]).start()
[node1, node2, node3] = cluster.nodelist()
cursor = self.cql_connection(node1).cursor()
self.create_ks(cursor, 'ks', 1)
self.create_cf(cursor, 'cf')
for n in xrange(0, 10000):
insert_c1c2(cursor, n, "ONE")
cluster.flush()
sizes = [ node.data_size() for node in [node1, node2, node3] ]
# Given the assigned token, node2 and node3 should have approximately
# the same amount of data and node1 must have 6 times as much
assert_almost_equal(sizes[1], sizes[2])
assert_almost_equal(sizes[0], 6 * sizes[1])
# Move nodes to balance the cluster
balancing_tokens = Cluster.balanced_tokens(3)
node2.move(balancing_tokens[1])
node3.move(balancing_tokens[2])
time.sleep(1)
cluster.cleanup()
# Check we can get all the keys
for n in xrange(0, 10000):
query_c1c2(cursor, n, "ONE")
# Now the load should be basically even
sizes = [ node.data_size() for node in [node1, node2, node3] ]
assert_almost_equal(sizes[0], sizes[1])
assert_almost_equal(sizes[0], sizes[2])
assert_almost_equal(sizes[1], sizes[2])
def decomission_test(self):
cluster = self.cluster
tokens = Cluster.balanced_tokens(4)
cluster.populate(4, tokens=tokens).start()
[node1, node2, node3, node4] = cluster.nodelist()
cursor = self.cql_connection(node1).cursor()
self.create_ks(cursor, 'ks', 2)
self.create_cf(cursor, 'cf')
for n in xrange(0, 10000):
insert_c1c2(cursor, n, "QUORUM")
cluster.flush()
sizes = [ node.data_size() for node in cluster.nodelist() if node.is_running()]
init_size = sizes[0]
assert_almost_equal(*sizes)
node4.decommission()
time.sleep(.5)
node4.stop()
cluster.cleanup()
time.sleep(.5)
# Check we can get all the keys
for n in xrange(0, 10000):
query_c1c2(cursor, n, "QUORUM")
sizes = [ node.data_size() for node in cluster.nodelist() if node.is_running() ]
three_node_sizes = sizes
assert_almost_equal(sizes[0], sizes[1])
assert_almost_equal((2.0/3.0) * sizes[0], sizes[2])
assert_almost_equal(sizes[2], init_size)
node3.stop(wait_other_notice=True)
node1.removeToken(tokens[2])
time.sleep(.5)
cluster.cleanup()
time.sleep(.5)
# Check we can get all the keys
for n in xrange(0, 10000):
query_c1c2(cursor, n, "QUORUM")
sizes = [ node.data_size() for node in cluster.nodelist() if node.is_running() ]
assert_almost_equal(*sizes)
assert_almost_equal(sizes[0], 2 * init_size)
node5 = new_node(cluster, token=(tokens[2]+1)).start()
time.sleep(.5)
cluster.cleanup()
time.sleep(.5)
# Check we can get all the keys
for n in xrange(0, 10000):
query_c1c2(cursor, n, "QUORUM")
sizes = [ node.data_size() for node in cluster.nodelist() if node.is_running() ]
# We should be back to the earlir 3 nodes situation
for i in xrange(0, len(sizes)):
assert_almost_equal(sizes[i], three_node_sizes[i])
def replace_test(self):
cluster = self.cluster
tokens = Cluster.balanced_tokens(3)
cluster.populate(3, tokens=tokens).start()
[node1, node2, node3] = cluster.nodelist()
cursor = self.cql_connection(node1).cursor()
self.create_ks(cursor, 'ks', 3)
self.create_cf(cursor, 'cf')
for n in xrange(0, 10000):
insert_c1c2(cursor, n, "QUORUM")
cluster.flush()
node3.stop(wait_other_notice=True)
time.sleep(.5)
node4 = new_node(cluster, token=tokens[2])
node4.start(replace_token=tokens[2])
time.sleep(.5)
cluster.cleanup()
time.sleep(.5)
for n in xrange(0, 10000):
query_c1c2(cursor, n, "QUORUM")
sizes = [ node.data_size() for node in cluster.nodelist() if node.is_running()]
assert_almost_equal(*sizes)