'Test that replicas are queried first for TokenAwarePolicy. A table with RF 1
is created. All the queries should go to that replica when TokenAwarePolicy
is used.
Then using HostFilterPolicy the replica is excluded from the considered hosts.
By checking the trace we verify that there are no more replicas.
@since 3.5
@jira_ticket PYTHON-653
@expected_result the replicas are queried for HostFilterPolicy
@test_category metadata'

def test_replicas_are_queried(self):

    queried_hosts = set()
    with Cluster(protocol_version=PROTOCOL_VERSION, load_balancing_policy=TokenAwarePolicy(RoundRobinPolicy())) as cluster:
        session = cluster.connect(wait_for_all_pools=True)
        session.execute('\n                                                                                CREATE    TABLE    test1rf.table_with_big_key    (\n                                                                                                k1    int,\n                                                                                                k2    int,\n                                                                                                k3    int,\n                                                                                                k4    int,\n                                                                                                PRIMARY    KEY((k1,    k2,    k3),    k4))')
        prepared = session.prepare('SELECT    *    from    test1rf.table_with_big_key\n                                                                                                                                                                        WHERE    k1    =    ?    AND    k2    =    ?    AND    k3    =    ?    AND    k4    =    ?')
        for i in range(10):
            result = session.execute(prepared, (i, i, i, i), trace=True)
            queried_hosts = self._assert_replica_queried(result.get_query_trace(), only_replicas=True)
            last_i = i
    only_replica = queried_hosts.pop()
    available_hosts = [host for host in ['127.0.0.1', '127.0.0.2', '127.0.0.3'] if (host != only_replica)]
    with Cluster(contact_points=available_hosts, protocol_version=PROTOCOL_VERSION, load_balancing_policy=HostFilterPolicy(RoundRobinPolicy(), predicate=(lambda host: (host.address != only_replica)))) as cluster:
        session = cluster.connect(wait_for_all_pools=True)
        prepared = session.prepare('SELECT    *    from    test1rf.table_with_big_key\n                                                                                                                                                                        WHERE    k1    =    ?    AND    k2    =    ?    AND    k3    =    ?    AND    k4    =    ?')
        for _ in range(10):
            result = session.execute(prepared, (last_i, last_i, last_i, last_i), trace=True)
            self._assert_replica_queried(result.get_query_trace(), only_replicas=False)
        session.execute('DROP    TABLE    test1rf.table_with_big_key')
