forked from apache/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stress_tool_test.py
53 lines (43 loc) · 2.08 KB
/
stress_tool_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
from __future__ import division
from dtest import Tester
from tools.data import rows_to_list
from tools.decorators import since
@since('3.0')
class TestStressSparsenessRatio(Tester):
"""
@jira_ticket CASSANDRA-9522
Tests for the `row-population-ratio` parameter to `cassandra-stress`.
"""
def uniform_ratio_test(self):
"""
Tests that the ratio-specifying string 'uniform(5..15)/50' results in
~80% of the values written being non-null.
"""
self.distribution_template(ratio_spec='uniform(5..15)/50',
expected_ratio=.8,
delta=.1)
def fixed_ratio_test(self):
"""
Tests that the string 'fixed(1)/3' results in ~1/3 of the values
written being non-null.
"""
self.distribution_template(ratio_spec='fixed(1)/3',
expected_ratio=1 - 1 / 3,
delta=.01)
def distribution_template(self, ratio_spec, expected_ratio, delta):
"""
@param ratio_spec the string passed to `row-population-ratio` in the call to `cassandra-stress`
@param expected_ratio the expected ratio of null/non-null values in the values written
@param delta the acceptable delta between the expected and actual ratios
A parameterized test for the `row-population-ratio` parameter to
`cassandra-stress`.
"""
self.cluster.populate(1).start(wait_for_binary_proto=True)
node = self.cluster.nodelist()[0]
node.stress(['write', 'n=1000', 'no-warmup', '-rate', 'threads=50', '-col', 'n=FIXED(50)',
'-insert', 'row-population-ratio={ratio_spec}'.format(ratio_spec=ratio_spec)])
session = self.patient_cql_connection(node)
written = rows_to_list(session.execute('SELECT * FROM keyspace1.standard1;'))
num_nones = sum(row.count(None) for row in written)
num_results = sum(len(row) for row in written)
self.assertAlmostEqual(float(num_nones) / num_results, expected_ratio, delta=delta)