def setUpClass(cls): if SIMULACRON_JAR is None or CASSANDRA_VERSION < "2.1": return start_and_prime_singledc() cls.cluster = Cluster(protocol_version=PROTOCOL_VERSION, compression=False) cls.session = cls.cluster.connect(wait_for_all_pools=True) spec_ep_brr = ExecutionProfile( load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( 1, 6), request_timeout=12) spec_ep_rr = ExecutionProfile( speculative_execution_policy=ConstantSpeculativeExecutionPolicy( .5, 10), request_timeout=12) spec_ep_rr_lim = ExecutionProfile( load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( 0.5, 1), request_timeout=12) spec_ep_brr_lim = ExecutionProfile( load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( 4, 10)) cls.cluster.add_execution_profile("spec_ep_brr", spec_ep_brr) cls.cluster.add_execution_profile("spec_ep_rr", spec_ep_rr) cls.cluster.add_execution_profile("spec_ep_rr_lim", spec_ep_rr_lim) cls.cluster.add_execution_profile("spec_ep_brr_lim", spec_ep_brr_lim)
def setUp(self): spec_ep_brr = ExecutionProfile( load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( .01, 20)) spec_ep_rr = ExecutionProfile( speculative_execution_policy=ConstantSpeculativeExecutionPolicy( .01, 20)) spec_ep_rr_lim = ExecutionProfile( load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( .01, 1)) self.cluster.add_execution_profile("spec_ep_brr", spec_ep_brr) self.cluster.add_execution_profile("spec_ep_rr", spec_ep_rr) self.cluster.add_execution_profile("spec_ep_rr_lim", spec_ep_rr_lim)
def test_can_write_speculative(self): """ Verify that the driver will keep querying C* even if there is a host down while being upgraded and that all the writes will eventually succeed using the ConstantSpeculativeExecutionPolicy policy @since 3.12 @jira_ticket PYTHON-546 @expected_result all the writes succeed @test_category upgrade """ spec_ep_rr = ExecutionProfile(speculative_execution_policy=ConstantSpeculativeExecutionPolicy(.5, 10), request_timeout=12) cluster = Cluster() self.addCleanup(cluster.shutdown) cluster.add_execution_profile("spec_ep_rr", spec_ep_rr) session = cluster.connect() self.start_upgrade(0) c = count() while not self.is_upgraded(): session.execute("INSERT INTO test3rf.test(k, v) VALUES (%s, 0)", (next(c),), execution_profile='spec_ep_rr') time.sleep(0.0001) session.default_consistency_level = ConsistencyLevel.ALL total_number_of_inserted = session.execute("SELECT COUNT(*) from test3rf.test")[0][0] self.assertEqual(total_number_of_inserted, next(c)) self.assertEqual(self.logger_handler.get_message_count("error", ""), 0)
def test_delay_can_be_0(self): """ Test to validate that the delay can be zero for the ConstantSpeculativeExecutionPolicy @since 3.13 @jira_ticket PYTHON-836 @expected_result all the queries are executed immediately @test_category policy """ number_of_requests = 4 spec = ExecutionProfile( speculative_execution_policy=ConstantSpeculativeExecutionPolicy( 0, number_of_requests)) cluster = Cluster() cluster.add_execution_profile("spec", spec) session = cluster.connect(wait_for_all_pools=True) self.addCleanup(cluster.shutdown) counter = count() def patch_and_count(f): def patched(*args, **kwargs): next(counter) f(*args, **kwargs) return patched ResponseFuture._on_speculative_execute = patch_and_count( ResponseFuture._on_speculative_execute) stmt = SimpleStatement("INSERT INTO test3rf.test(k, v) VALUES (1, 2)") stmt.is_idempotent = True results = session.execute(stmt, execution_profile="spec") self.assertEqual(len(results.response_future.attempted_hosts), 3) self.assertEqual(next(counter), number_of_requests)
def test_constant_spec_exec_policy(self): self.assertEqual( insights_registry.serialize(ConstantSpeculativeExecutionPolicy(100, 101)), {'type': 'ConstantSpeculativeExecutionPolicy', 'namespace': 'cassandra.policies', 'options': {'delay': 100, 'max_attempts': 101} } )
def setUpClass(cls): cls.common_setup(1) spec_ep_brr = ExecutionProfile(load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy(.01, 20)) spec_ep_rr = ExecutionProfile(speculative_execution_policy=ConstantSpeculativeExecutionPolicy(.01, 20)) spec_ep_rr_lim = ExecutionProfile(load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy(.01, 1)) spec_ep_brr_lim = ExecutionProfile(load_balancing_policy=BadRoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy(0.4, 10)) cls.cluster.add_execution_profile("spec_ep_brr", spec_ep_brr) cls.cluster.add_execution_profile("spec_ep_rr", spec_ep_rr) cls.cluster.add_execution_profile("spec_ep_rr_lim", spec_ep_rr_lim) cls.cluster.add_execution_profile("spec_ep_brr_lim", spec_ep_brr_lim)
def __init__(self, url, dbname, consistency=None): self.isShutdown = False self.url = url self.dbname = dbname self.nSuccess = 0 self.nErrors = 0 self.nActive = 0 self.consistency = ConsistencyLevel.ONE if consistency is None else consistency self.cluster = Cluster( url, control_connection_timeout=30.0, reconnection_policy=ConstantReconnectionPolicy(15.0, max_attempts=None), default_retry_policy=ConstantSpeculativeExecutionPolicy(30, 10)) self.cur = self.cluster.connect(dbname) self.cur.default_timeout = 60.0
def test_delay_can_be_0(self): """ Test to validate that the delay can be zero for the ConstantSpeculativeExecutionPolicy @since 3.13 @jira_ticket PYTHON-836 @expected_result all the queries are executed immediately @test_category policy """ query_to_prime = "INSERT INTO madeup_keyspace.madeup_table(k, v) VALUES (1, 2)" prime_query(query_to_prime, then={"delay_in_ms": 5000}) number_of_requests = 4 spec = ExecutionProfile( load_balancing_policy=RoundRobinPolicy(), speculative_execution_policy=ConstantSpeculativeExecutionPolicy( 0, number_of_requests)) cluster = Cluster() cluster.add_execution_profile("spec", spec) session = cluster.connect(wait_for_all_pools=True) self.addCleanup(cluster.shutdown) counter = count() def patch_and_count(f): def patched(*args, **kwargs): next(counter) print("patched") f(*args, **kwargs) return patched self.addCleanup(setattr, ResponseFuture, "send_request", ResponseFuture.send_request) ResponseFuture.send_request = patch_and_count( ResponseFuture.send_request) stmt = SimpleStatement(query_to_prime) stmt.is_idempotent = True results = session.execute(stmt, execution_profile="spec") self.assertEqual(len(results.response_future.attempted_hosts), 3) # send_request is called number_of_requests times for the speculative request # plus one for the call from the main thread. self.assertEqual(next(counter), number_of_requests + 1)