예제 #1
0
 def test_chr_get_node(self):
     hosts = [
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
         ("127.0.0.1", "cache2"),
     ]
     hashring = ConsistentHashRing(hosts)
     node = hashring.get_node('hosts.worker1.cpu')
     self.assertEqual(node, ('127.0.0.1', 'cache2'))
예제 #2
0
 def test_chr_remove_node_missing(self):
     hosts = [
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
         ("127.0.0.1", "cache2"),
     ]
     hashring = ConsistentHashRing(hosts)
     self.assertEqual(hashring.nodes, set(hosts))
     hashring.remove_node(("127.0.0.1", "cache4"))
     self.assertEqual(hashring.nodes, set(hosts))
     self.assertEqual(hashring.nodes_len, 3)
예제 #3
0
 def test_chr_add_node_duplicate(self):
     hosts = [
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
         ("127.0.0.1", "cache2"),
     ]
     hashring = ConsistentHashRing(hosts)
     self.assertEqual(hashring.nodes, set(hosts))
     hashring.add_node(("127.0.0.1", "cache2"))
     self.assertEqual(hashring.nodes, set(hosts))
     self.assertEqual(hashring.nodes_len, 3)
예제 #4
0
 def test_chr_compute_ring_position(self):
     hosts = [
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
         ("127.0.0.1", "cache2"),
     ]
     hashring = ConsistentHashRing(hosts)
     self.assertEqual(hashring.compute_ring_position('hosts.worker1.cpu'),
                      64833)
     self.assertEqual(hashring.compute_ring_position('hosts.worker2.cpu'),
                      38509)
예제 #5
0
 def test_chr_get_node_fnv1a(self):
     hosts = [
         ("127.0.0.1", "ba603c36342304ed77953f84ac4d357b"),
         ("127.0.0.2", "5dd63865534f84899c6e5594dba6749a"),
         ("127.0.0.3", "866a18b81f2dc4649517a1df13e26f28"),
     ]
     hashring = ConsistentHashRing(hosts, hash_type='fnv1a_ch')
     self.assertEqual(hashring.get_node('hosts.worker1.cpu'),
                      ('127.0.0.1', 'ba603c36342304ed77953f84ac4d357b'))
     self.assertEqual(hashring.get_node('hosts.worker2.cpu'),
                      ('127.0.0.3', '866a18b81f2dc4649517a1df13e26f28'))
예제 #6
0
 def test_chr_compute_ring_position_fnv1a(self):
     hosts = [
         ("127.0.0.1", "ba603c36342304ed77953f84ac4d357b"),
         ("127.0.0.2", "5dd63865534f84899c6e5594dba6749a"),
         ("127.0.0.3", "866a18b81f2dc4649517a1df13e26f28"),
     ]
     hashring = ConsistentHashRing(hosts, hash_type='fnv1a_ch')
     self.assertEqual(hashring.compute_ring_position('hosts.worker1.cpu'),
                      59573)
     self.assertEqual(hashring.compute_ring_position('hosts.worker2.cpu'),
                      35749)
예제 #7
0
 def test_chr_get_nodes(self):
     hosts = [
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
         ("127.0.0.1", "cache2"),
     ]
     hashring = ConsistentHashRing(hosts)
     node = hashring.get_nodes('hosts.worker1.cpu')
     expected = [
         ("127.0.0.1", "cache2"),
         ("127.0.0.1", "cache0"),
         ("127.0.0.1", "cache1"),
     ]
     self.assertEqual(node, expected)