def test_levels_needed(self): finger = FingerTable(Node(uidlib.new_uid(), '', '', '')) self.assertTrue( len([x for x in finger.get_levels()]) == finger.max_level) finger.add(Node(uidlib.new_uid(), '', '', '')) self.assertTrue( len([x for x in finger.get_levels()]) == finger.max_level - 1)
def testHashabilitySet(self): import copy a = Node(uidlib.new_uid(), 'localhost', '8338', None) b = set([]) b.add(a) c = copy.copy(a) b.add(c) self.assertTrue(len(b) == 1)
def testadds(self): finger = FingerTable(Node(uidlib.new_uid(), '', '', '')) Nodes = set([]) for i in range(100): a = uidlib.new_uid() b = Node(a, '', '', '') Nodes.add(b) finger.add(b) for y in finger.get_levels(): pass for x in Nodes: finger.remove(x) self.assertTrue(len(finger.known) == 0)
def __init__(self, start_addr, port=8339, ip='127.0.0.1'): #Special node which talks about ourselves self.port = port self.ip = ip self.node = node.Node(uidlib.new_uid(), ip, port, None) #Handler Classes self.finger = FingerTable(self.node) self.set_handler = SetHandler(self.finger) #Set up the listening server self._s= gevent.server.StreamServer(( self.ip, self.port), self._handle) self._s.start() gevent.spawn(self._ask_help) if start_addr: Connect(self.finger, self.set_handler, start_addr) LoopBackProtocol(ip + ":" + str(port), self.finger, self.set_handler)
def testCreation(self): a = Node(uidlib.new_uid(), 'localhost', '8338', None) self.assertTrue(isinstance(a, Node))
def test_levels_needed(self): finger = FingerTable(Node(uidlib.new_uid(), '', '', '')) self.assertTrue(len([x for x in finger.get_levels()]) == finger.max_level) finger.add(Node(uidlib.new_uid(), '', '', '')) self.assertTrue(len([x for x in finger.get_levels()]) == finger.max_level-1)