def test_get_empty_ring(self): """ Ensures that an exception is thrown when the ring is empty """ cons_hash = ConsistentHash(2) threw_value_error = False try: cons_hash.get_node('192.168.1.1') except exceptions.ValueError: threw_value_error = True self.assertTrue(threw_value_error)
def test_getting_keys(self): """ Ensures that random keys match to nodes """ cons_hash = ConsistentHash(2) nodes = [ '192.168.1.1:20000', '192.168.1.1:20001', '192.168.1.1:20002', '192.168.1.1:20003' ] for node in nodes: cons_hash.add(node) self.assertEquals(len(cons_hash), 8) node_counts = defaultdict(int) for i in xrange(0, 100): key = str(uuid.uuid4()) node = cons_hash.get_node(key) self.assertTrue(node in nodes) node_counts[node] += 1 self.assertTrue(cons_hash._is_consistent())
def test_getting_keys(self): """ Ensures that random keys match to nodes """ cons_hash = ConsistentHash(2) nodes = ['192.168.1.1:20000', '192.168.1.1:20001', '192.168.1.1:20002', '192.168.1.1:20003'] for node in nodes: cons_hash.add(node) self.assertEquals(len(cons_hash), 8) node_counts = defaultdict(int) for i in xrange(0,100): key = str(uuid.uuid4()) node = cons_hash.get_node(key) self.assertTrue(node in nodes) node_counts[node] += 1 self.assertTrue(cons_hash._is_consistent())