'Test token mappings'

def test_token_map(self):

    cluster = Cluster(protocol_version=PROTOCOL_VERSION)
    cluster.connect('test3rf')
    ring = cluster.metadata.token_map.ring
    owners = list((cluster.metadata.token_map.token_to_host_owner[token] for token in ring))
    get_replicas = cluster.metadata.token_map.get_replicas
    for ksname in ('test1rf', 'test2rf', 'test3rf'):
        self.assertNotEqual(list(get_replicas(ksname, ring[0])), [])
    for (i, token) in enumerate(ring):
        self.assertEqual(set(get_replicas('test3rf', token)), set(owners))
        self.assertEqual(set(get_replicas('test2rf', token)), set([owners[((i + 1) % 3)], owners[((i + 2) % 3)]]))
        self.assertEqual(set(get_replicas('test1rf', token)), set([owners[((i + 1) % 3)]]))
    cluster.shutdown()
