'Test to ensure that speculative execution honors LBP, and that they retry appropriately.
This test will use various LBP, and ConstantSpeculativeExecutionPolicy settings and ensure the proper number of hosts are queried
@since 3.7.0
@jira_ticket PYTHON-218
@expected_result speculative retries should honor max retries, idempotent state of queries, and underlying lbp.
@test_category metadata'

@greaterthancass21
def test_speculative_execution(self):

    query_to_prime = 'INSERT    INTO    test3rf.test    (k,    v)    VALUES    (0,    1);'
    prime_query(query_to_prime, then={'delay_in_ms': 4000})
    statement = SimpleStatement(query_to_prime, is_idempotent=True)
    statement_non_idem = SimpleStatement(query_to_prime, is_idempotent=False)
    result = self.session.execute(statement, execution_profile='spec_ep_brr')
    self.assertEqual(21, len(result.response_future.attempted_hosts))
    result = self.session.execute(statement, execution_profile='spec_ep_rr')
    self.assertEqual(3, len(result.response_future.attempted_hosts))
    result = self.session.execute(statement, execution_profile='spec_ep_rr_lim')
    self.assertEqual(2, len(result.response_future.attempted_hosts))
    result = self.session.execute(statement_non_idem, execution_profile='spec_ep_brr')
    self.assertEqual(1, len(result.response_future.attempted_hosts))
    result = self.session.execute(statement_non_idem)
    self.assertEqual(1, len(result.response_future.attempted_hosts))
    result = self.session.execute(statement)
    self.assertEqual(1, len(result.response_future.attempted_hosts))
    with self.assertRaises(OperationTimedOut):
        self.session.execute(statement, execution_profile='spec_ep_rr', timeout=0.5)
    prepared_query_to_prime = 'SELECT    *    FROM    test3rf.test    where    k    =    ?'
    when = {'params': {'k': '0'}, 'param_types': {'k': 'ascii'}}
    prime_query(prepared_query_to_prime, when=when, then={'delay_in_ms': 4000})
    prepared_statement = self.session.prepare(prepared_query_to_prime)
    result = self.session.execute(prepared_statement, ('0',), execution_profile='spec_ep_brr')
    self.assertEqual(1, len(result.response_future.attempted_hosts))
    prepared_statement.is_idempotent = True
    result = self.session.execute(prepared_statement, ('0',), execution_profile='spec_ep_brr')
    self.assertLess(1, len(result.response_future.attempted_hosts))
