本文整理汇总了Python中tests.integration.long.utils.CoordinatorStats.reset_counts方法的典型用法代码示例。如果您正苦于以下问题:Python CoordinatorStats.reset_counts方法的具体用法?Python CoordinatorStats.reset_counts怎么用?Python CoordinatorStats.reset_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.integration.long.utils.CoordinatorStats
的用法示例。
在下文中一共展示了CoordinatorStats.reset_counts方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConsistencyTests
# 需要导入模块: from tests.integration.long.utils import CoordinatorStats [as 别名]
# 或者: from tests.integration.long.utils.CoordinatorStats import reset_counts [as 别名]
class ConsistencyTests(unittest.TestCase):
def setUp(self):
self.coordinator_stats = CoordinatorStats()
def _cl_failure(self, consistency_level, e):
self.fail('Instead of success, saw %s for CL.%s:\n\n%s' % (
e, ConsistencyLevel.value_to_name[consistency_level],
traceback.format_exc()))
def _cl_expected_failure(self, cl):
self.fail('Test passed at ConsistencyLevel.%s:\n\n%s' % (
ConsistencyLevel.value_to_name[cl], traceback.format_exc()))
def _insert(self, session, keyspace, count, consistency_level=ConsistencyLevel.ONE):
session.execute('USE %s' % keyspace)
for i in range(count):
ss = SimpleStatement('INSERT INTO cf(k, i) VALUES (0, 0)',
consistency_level=consistency_level)
session.execute(ss)
def _query(self, session, keyspace, count, consistency_level=ConsistencyLevel.ONE):
routing_key = struct.pack('>i', 0)
for i in range(count):
ss = SimpleStatement('SELECT * FROM cf WHERE k = 0',
consistency_level=consistency_level,
routing_key=routing_key)
self.coordinator_stats.add_coordinator(session.execute_async(ss))
def _assert_writes_succeed(self, session, keyspace, consistency_levels):
for cl in consistency_levels:
self.coordinator_stats.reset_counts()
try:
self._insert(session, keyspace, 1, cl)
except Exception as e:
self._cl_failure(cl, e)
def _assert_reads_succeed(self, session, keyspace, consistency_levels, expected_reader=3):
for cl in consistency_levels:
self.coordinator_stats.reset_counts()
try:
self._query(session, keyspace, 1, cl)
for i in range(3):
if i == expected_reader:
self.coordinator_stats.assert_query_count_equals(self, i, 1)
else:
self.coordinator_stats.assert_query_count_equals(self, i, 0)
except Exception as e:
self._cl_failure(cl, e)
def _assert_writes_fail(self, session, keyspace, consistency_levels):
for cl in consistency_levels:
self.coordinator_stats.reset_counts()
try:
self._insert(session, keyspace, 1, cl)
self._cl_expected_failure(cl)
except (cassandra.Unavailable, cassandra.WriteTimeout):
pass
def _assert_reads_fail(self, session, keyspace, consistency_levels):
for cl in consistency_levels:
self.coordinator_stats.reset_counts()
try:
self._query(session, keyspace, 1, cl)
self._cl_expected_failure(cl)
except (cassandra.Unavailable, cassandra.ReadTimeout):
pass
def _test_tokenaware_one_node_down(self, keyspace, rf, accepted):
cluster = Cluster(
load_balancing_policy=TokenAwarePolicy(RoundRobinPolicy()),
protocol_version=PROTOCOL_VERSION)
session = cluster.connect()
wait_for_up(cluster, 1, wait=False)
wait_for_up(cluster, 2)
create_schema(session, keyspace, replication_factor=rf)
self._insert(session, keyspace, count=1)
self._query(session, keyspace, count=1)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 1)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
try:
force_stop(2)
wait_for_down(cluster, 2)
self._assert_writes_succeed(session, keyspace, accepted)
self._assert_reads_succeed(session, keyspace,
accepted - set([ConsistencyLevel.ANY]))
self._assert_writes_fail(session, keyspace,
SINGLE_DC_CONSISTENCY_LEVELS - accepted)
self._assert_reads_fail(session, keyspace,
SINGLE_DC_CONSISTENCY_LEVELS - accepted)
finally:
start(2)
wait_for_up(cluster, 2)
def test_rfone_tokenaware_one_node_down(self):
self._test_tokenaware_one_node_down(
#.........这里部分代码省略.........
示例2: LoadBalancingPolicyTests
# 需要导入模块: from tests.integration.long.utils import CoordinatorStats [as 别名]
# 或者: from tests.integration.long.utils.CoordinatorStats import reset_counts [as 别名]
#.........这里部分代码省略.........
@since 2.6.0
@jira_ticket PYTHON-160
@expected_result TokenAwarePolicy should be the default loadbalancing policy.
@test_category load_balancing:token_aware
"""
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
if murmur3 is not None:
self.assertTrue(isinstance(cluster.load_balancing_policy, TokenAwarePolicy))
else:
self.assertTrue(isinstance(cluster.load_balancing_policy, DCAwareRoundRobinPolicy))
cluster.shutdown()
def test_roundrobin(self):
use_singledc()
keyspace = 'test_roundrobin'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
self._wait_for_nodes_up(range(1, 4), cluster)
create_schema(cluster, session, keyspace, replication_factor=3)
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 4)
self.coordinator_stats.assert_query_count_equals(self, 2, 4)
self.coordinator_stats.assert_query_count_equals(self, 3, 4)
force_stop(3)
self._wait_for_nodes_down([3], cluster)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 6)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
decommission(1)
start(3)
self._wait_for_nodes_down([1], cluster)
self._wait_for_nodes_up([3], cluster)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 6)
cluster.shutdown()
def test_roundrobin_two_dcs(self):
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
self._wait_for_nodes_up(range(1, 5), cluster)
create_schema(cluster, session, keyspace, replication_strategy=[2, 2])
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 3)
self.coordinator_stats.assert_query_count_equals(self, 2, 3)
self.coordinator_stats.assert_query_count_equals(self, 3, 3)
示例3: LoadBalancingPolicyTests
# 需要导入模块: from tests.integration.long.utils import CoordinatorStats [as 别名]
# 或者: from tests.integration.long.utils.CoordinatorStats import reset_counts [as 别名]
#.........这里部分代码省略.........
@since 2.6.0
@jira_ticket PYTHON-160
@expected_result TokenAwarePolicy should be the default loadbalancing policy.
@test_category load_balancing:token_aware
"""
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
if murmur3 is not None:
self.assertTrue(isinstance(cluster.load_balancing_policy, TokenAwarePolicy))
else:
self.assertTrue(isinstance(cluster.load_balancing_policy, DCAwareRoundRobinPolicy))
cluster.shutdown()
def test_roundrobin(self):
use_singledc()
keyspace = 'test_roundrobin'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
self._wait_for_nodes_up(range(1, 4), cluster)
create_schema(cluster, session, keyspace, replication_factor=3)
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 4)
self.coordinator_stats.assert_query_count_equals(self, 2, 4)
self.coordinator_stats.assert_query_count_equals(self, 3, 4)
force_stop(3)
self._wait_for_nodes_down([3], cluster)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 6)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
decommission(1)
start(3)
self._wait_for_nodes_down([1], cluster)
self._wait_for_nodes_up([3], cluster)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 6)
cluster.shutdown()
def test_roundrobin_two_dcs(self):
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
self._wait_for_nodes_up(range(1, 5), cluster)
create_schema(cluster, session, keyspace, replication_strategy=[2, 2])
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 3)
self.coordinator_stats.assert_query_count_equals(self, 2, 3)
self.coordinator_stats.assert_query_count_equals(self, 3, 3)
示例4: LoadBalancingPolicyTests
# 需要导入模块: from tests.integration.long.utils import CoordinatorStats [as 别名]
# 或者: from tests.integration.long.utils.CoordinatorStats import reset_counts [as 别名]
class LoadBalancingPolicyTests(unittest.TestCase):
def setUp(self):
self.coordinator_stats = CoordinatorStats()
self.prepared = None
@classmethod
def tearDownClass(cls):
use_singledc()
def _insert(self, session, keyspace, count=12,
consistency_level=ConsistencyLevel.ONE):
session.execute('USE %s' % keyspace)
ss = SimpleStatement('INSERT INTO cf(k, i) VALUES (0, 0)',
consistency_level=consistency_level)
execute_concurrent_with_args(session, ss, [None] * count)
def _query(self, session, keyspace, count=12,
consistency_level=ConsistencyLevel.ONE, use_prepared=False):
if use_prepared:
query_string = 'SELECT * FROM %s.cf WHERE k = ?' % keyspace
if not self.prepared or self.prepared.query_string != query_string:
self.prepared = session.prepare(query_string)
for i in range(count):
self.coordinator_stats.add_coordinator(session.execute_async(self.prepared.bind((0,))))
else:
routing_key = struct.pack('>i', 0)
for i in range(count):
ss = SimpleStatement('SELECT * FROM %s.cf WHERE k = 0' % keyspace,
consistency_level=consistency_level,
routing_key=routing_key)
self.coordinator_stats.add_coordinator(session.execute_async(ss))
def test_roundrobin(self):
use_singledc()
keyspace = 'test_roundrobin'
cluster = Cluster(
load_balancing_policy=RoundRobinPolicy())
session = cluster.connect()
wait_for_up(cluster, 1, wait=False)
wait_for_up(cluster, 2, wait=False)
wait_for_up(cluster, 3)
create_schema(session, keyspace, replication_factor=3)
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 4)
self.coordinator_stats.assert_query_count_equals(self, 2, 4)
self.coordinator_stats.assert_query_count_equals(self, 3, 4)
force_stop(3)
wait_for_down(cluster, 3)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 6)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
decommission(1)
start(3)
wait_for_down(cluster, 1)
wait_for_up(cluster, 3)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 6)
def test_roundrobin_two_dcs(self):
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs'
cluster = Cluster(
load_balancing_policy=RoundRobinPolicy())
session = cluster.connect()
wait_for_up(cluster, 1, wait=False)
wait_for_up(cluster, 2, wait=False)
wait_for_up(cluster, 3, wait=False)
wait_for_up(cluster, 4)
create_schema(session, keyspace, replication_strategy=[2, 2])
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 3)
self.coordinator_stats.assert_query_count_equals(self, 2, 3)
self.coordinator_stats.assert_query_count_equals(self, 3, 3)
self.coordinator_stats.assert_query_count_equals(self, 4, 3)
force_stop(1)
bootstrap(5, 'dc3')
# reset control connection
self._insert(session, keyspace, count=1000)
wait_for_up(cluster, 5)
#.........这里部分代码省略.........
示例5: LoadBalancingPolicyTests
# 需要导入模块: from tests.integration.long.utils import CoordinatorStats [as 别名]
# 或者: from tests.integration.long.utils.CoordinatorStats import reset_counts [as 别名]
class LoadBalancingPolicyTests(unittest.TestCase):
def setUp(self):
remove_cluster() # clear ahead of test so it doesn't use one left in unknown state
self.coordinator_stats = CoordinatorStats()
self.prepared = None
@classmethod
def teardown_class(cls):
remove_cluster()
def _insert(self, session, keyspace, count=12,
consistency_level=ConsistencyLevel.ONE):
session.execute('USE %s' % keyspace)
ss = SimpleStatement('INSERT INTO cf(k, i) VALUES (0, 0)',
consistency_level=consistency_level)
execute_concurrent_with_args(session, ss, [None] * count)
def _query(self, session, keyspace, count=12,
consistency_level=ConsistencyLevel.ONE, use_prepared=False):
if use_prepared:
query_string = 'SELECT * FROM %s.cf WHERE k = ?' % keyspace
if not self.prepared or self.prepared.query_string != query_string:
self.prepared = session.prepare(query_string)
for i in range(count):
while True:
try:
self.coordinator_stats.add_coordinator(session.execute_async(self.prepared.bind((0,))))
break
except (OperationTimedOut, ReadTimeout):
ex_type, ex, tb = sys.exc_info()
log.warn("{0}: {1} Backtrace: {2}".format(ex_type.__name__, ex, traceback.extract_tb(tb)))
del tb
else:
routing_key = struct.pack('>i', 0)
for i in range(count):
ss = SimpleStatement('SELECT * FROM %s.cf WHERE k = 0' % keyspace,
consistency_level=consistency_level,
routing_key=routing_key)
while True:
try:
self.coordinator_stats.add_coordinator(session.execute_async(ss))
break
except (OperationTimedOut, ReadTimeout):
ex_type, ex, tb = sys.exc_info()
log.warn("{0}: {1} Backtrace: {2}".format(ex_type.__name__, ex, traceback.extract_tb(tb)))
del tb
def test_roundrobin(self):
use_singledc()
keyspace = 'test_roundrobin'
cluster = Cluster(
load_balancing_policy=RoundRobinPolicy(),
protocol_version=PROTOCOL_VERSION)
session = cluster.connect()
wait_for_up(cluster, 1, wait=False)
wait_for_up(cluster, 2, wait=False)
wait_for_up(cluster, 3)
create_schema(session, keyspace, replication_factor=3)
self._insert(session, keyspace)
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 4)
self.coordinator_stats.assert_query_count_equals(self, 2, 4)
self.coordinator_stats.assert_query_count_equals(self, 3, 4)
force_stop(3)
wait_for_down(cluster, 3)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 6)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 0)
decommission(1)
start(3)
wait_for_down(cluster, 1)
wait_for_up(cluster, 3)
self.coordinator_stats.reset_counts()
self._query(session, keyspace)
self.coordinator_stats.assert_query_count_equals(self, 1, 0)
self.coordinator_stats.assert_query_count_equals(self, 2, 6)
self.coordinator_stats.assert_query_count_equals(self, 3, 6)
def test_roundrobin_two_dcs(self):
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs'
cluster = Cluster(
load_balancing_policy=RoundRobinPolicy(),
protocol_version=PROTOCOL_VERSION)
session = cluster.connect()
wait_for_up(cluster, 1, wait=False)
wait_for_up(cluster, 2, wait=False)
wait_for_up(cluster, 3, wait=False)
#.........这里部分代码省略.........