forked from couchbase/perfrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittests.py
186 lines (155 loc) · 7.52 KB
/
unittests.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
from unittest import TestCase
from mock import patch
from perfrunner.helpers.misc import target_hash, server_group
from perfrunner.settings import TestConfig
from perfrunner.utils.install import CouchbaseInstaller, Build
from perfrunner.utils.install_gw import GatewayInstaller
from perfrunner.workloads.tcmalloc import (KeyValueIterator,
KeyLargeValueIterator,
LargeIterator)
class InstallTest(TestCase):
@patch('perfrunner.utils.install.CouchbaseInstaller.__init__')
def test_rpm_package(self, installer_mock):
installer_mock.return_value = None
installer = CouchbaseInstaller()
installer.build = Build('x86_64', 'rpm', '2.0.0-1976', '2.0.0', '1976',
None)
filenames = tuple(installer.get_expected_filenames())
expected = (
'couchbase-server-enterprise_centos6_x86_64_2.0.0-1976-rel.rpm',
'couchbase-server-enterprise-2.0.0-1976-centos6.x86_64.rpm',
'couchbase-server-enterprise_x86_64_2.0.0-1976-rel.rpm',
)
self.assertEqual(filenames, expected)
@patch('perfrunner.utils.install.CouchbaseInstaller.__init__')
def test_deb_package(self, installer_mock):
installer_mock.return_value = None
installer = CouchbaseInstaller()
installer.build = Build('x86_64', 'deb', '3.0.0-777', '3.0.0', '777',
None)
filenames = tuple(installer.get_expected_filenames())
expected = (
'couchbase-server-enterprise_ubuntu_1204_x86_64_3.0.0-777-rel.deb',
'couchbase-server-enterprise_3.0.0-777-ubuntu12.04_amd64.deb',
'couchbase-server-enterprise_x86_64_3.0.0-777-rel.deb',
)
self.assertEqual(filenames, expected)
@patch('perfrunner.utils.install.CouchbaseInstaller.__init__')
def test_win_package(self, installer_mock):
installer_mock.return_value = None
installer = CouchbaseInstaller()
installer.build = Build('x86_64', 'exe', '3.0.0-1028', '3.0.0', '1028',
None)
filenames = tuple(installer.get_expected_filenames())
expected = (
'couchbase-server-enterprise_x86_64_3.0.0-1028-rel.setup.exe',
'couchbase_server-enterprise-windows-amd64-3.0.0-1028.exe',
'couchbase_server/3.0.0/1028/couchbase_server-enterprise-windows-amd64-3.0.0-1028.exe',
)
self.assertEqual(filenames, expected)
# @patch('perfrunner.utils.install_gw.GatewayInstaller.__init__')
# def test_sgw_packakge(self, installer_mock):
# installer_mock.return_value = None
# installer = GatewayInstaller()
# installer.version = '0.0.0-178'
#
# filenames = tuple(
# fname for fname, url in installer.get_expected_locations()
# )
# # please see GatewayInstaller.BUILDS to compare
# expected = (
# 'couchbase-sync-gateway_0.0.0-178_x86_64-community.rpm',
# 'couchbase-sync-gateway_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-community_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-enterprise_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-enterprise_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-community_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-community_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-community_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway-community_0.0.0-178_x86_64.rpm',
# 'couchbase-sync-gateway_0.0.0-178_x86_64-community.rpm',
# )
# self.assertEqual(filenames, expected)
@patch('perfrunner.utils.install.CouchbaseInstaller.__init__')
def test_toy_package(self, installer_mock):
installer_mock.return_value = None
installer = CouchbaseInstaller()
installer.build = Build('x86_64', 'rpm', '2.0.0-1976', '2.0.0', '1976',
'mytoy')
filenames = tuple(installer.get_expected_filenames())
expected = (
'couchbase-server-community_toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_toy-mytoy-2.0.0-1976-toy_x86_64.rpm',
'couchbase-server-community_cent58-2.5.2-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_cent58-3.0.0-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_cent64-3.0.0-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_cent64-3.0.1-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_cent58-master-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
'couchbase-server-community_cent54-master-toy-mytoy-x86_64_2.0.0-1976-toy.rpm',
)
self.assertEqual(filenames, expected)
def test_target_hash(self):
self.assertEqual(target_hash('127.0.0.1'), '3cf55f')
class RebalanceTests(TestCase):
def test_server_group_6_to_8(self):
servers = range(8)
initial_nodes = 6
nodes_after = 8
group_number = 3
groups = []
for i, host in enumerate(servers[initial_nodes:nodes_after],
start=initial_nodes):
g = server_group(servers[:nodes_after], group_number, i)
groups.append(g)
self.assertEqual(groups, ['Group 3', 'Group 3'])
def test_initial_4_out_of_8(self):
servers = range(8)
initial_nodes = 4
group_number = 2
groups = []
for i, host in enumerate(servers[1:initial_nodes], start=1):
g = server_group(servers[:initial_nodes], group_number, i)
groups.append(g)
self.assertEqual(groups, ['Group 1', 'Group 2', 'Group 2'])
def test_server_group_3_to_4(self):
servers = range(8)
initial_nodes = 3
nodes_after = 4
group_number = 2
groups = []
for i, host in enumerate(servers[initial_nodes:nodes_after],
start=initial_nodes):
g = server_group(servers[:nodes_after], group_number, i)
groups.append(g)
self.assertEqual(groups, ['Group 2'])
class SettingsTest(TestCase):
def test_stale_update_after(self):
test_config = TestConfig()
test_config.parse(fname='tests/query_lat_20M.test')
views_params = test_config.index_settings.params
self.assertEqual(views_params, {})
def test_stale_false(self):
test_config = TestConfig()
test_config.parse(fname='tests/query_lat_20M_state_false.test')
views_params = test_config.index_settings.params
self.assertEqual(views_params, {'stale': 'false'})
class WorkloadTest(TestCase):
def test_value_size(self):
for _ in range(100):
iterator = KeyValueIterator(10000)
batch = iterator.next()
values = [len(str(v)) for k, v in batch]
mean = sum(values) / len(values)
self.assertAlmostEqual(mean, 1024, delta=128)
def test_large_field_size(self):
field = LargeIterator()._field('000000000001')
size = len(str(field))
self.assertAlmostEqual(size, LargeIterator.FIELD_SIZE, delta=16)
def test_large_value_size(self):
return
for _ in range(100):
iterator = KeyLargeValueIterator(10000)
batch = iterator.next()
values = [len(str(v)) for k, v in batch]
mean = sum(values) / len(values)
self.assertAlmostEqual(mean, 256000, delta=51200)