'Tests that profile load balancing policies are honored.
@since 3.5
@jira_ticket PYTHON-569
@expected_result Execution Policy should be used when applicable.
@test_category config_profiles'

@local
def test_profile_load_balancing(self):

    query = 'select    release_version    from    system.local'
    node1 = ExecutionProfile(load_balancing_policy=HostFilterPolicy(RoundRobinPolicy(), (lambda host: (host.address == CASSANDRA_IP))))
    with Cluster(execution_profiles={'node1': node1}) as cluster:
        session = cluster.connect(wait_for_all_pools=True)
        expected_hosts = set(cluster.metadata.all_hosts())
        queried_hosts = set()
        for _ in expected_hosts:
            rs = session.execute(query)
            queried_hosts.add(rs.response_future._current_host)
        self.assertEqual(queried_hosts, expected_hosts)
        expected_hosts = set((h for h in cluster.metadata.all_hosts() if (h.address == CASSANDRA_IP)))
        queried_hosts = set()
        for _ in cluster.metadata.all_hosts():
            rs = session.execute(query, execution_profile='node1')
            queried_hosts.add(rs.response_future._current_host)
        self.assertEqual(queried_hosts, expected_hosts)
        named_tuple_row = rs[0]
        self.assertIsInstance(named_tuple_row, tuple)
        self.assertTrue(named_tuple_row.release_version)
        tmp_profile = copy(node1)
        tmp_profile.row_factory = tuple_factory
        queried_hosts = set()
        for _ in cluster.metadata.all_hosts():
            rs = session.execute(query, execution_profile=tmp_profile)
            queried_hosts.add(rs.response_future._current_host)
        self.assertEqual(queried_hosts, expected_hosts)
        tuple_row = rs[0]
        self.assertIsInstance(tuple_row, tuple)
        with self.assertRaises(AttributeError):
            tuple_row.release_version
        self.assertTrue(session.execute(query, execution_profile='node1')[0].release_version)
