def test_tagging_wildcard(self): n = Node() n.put(HOST1, ADDR2, TAG2) n.put(WILD1, ADDR1, TAG1) res = n.get(HOST1) self.assertEquals(res, [(ADDR2, TAG2)]) res = n.get(HOST2) self.assertEquals(res, [(ADDR1, TAG1)])
def test_multiple_addresses(self): n = Node() # add a normal domain mapping for 2 nodes n.put(HOST1, ADDR1, TAG1) n.put(HOST1, ADDR2, TAG2) res = n.get(HOST1) self.assertEquals(res[1], (ADDR1, TAG1)) self.assertEquals(res[0], (ADDR2, TAG2))
def test_remove_tag(self): n = Node() # add a normal domain mapping for 2 nodes n.put(HOST1, ADDR1, TAG1) n.put(HOST1, ADDR2, TAG2) res = n.get(HOST1) self.assertEquals(res[1], (ADDR1, TAG1)) self.assertEquals(res[0], (ADDR2, TAG2)) # remove one tag n.remove(HOST1, addr=ADDR1) res = n.get(HOST1) self.assertEquals(res, [(ADDR2, TAG2)])
def test_multiple_wildcards(self): n = Node() # add a wildcard mapping n.put(WILD1, ADDR1, TAG1) n.put(WILD1, ADDR2, TAG2) res = n.get('xyz.foo.com') self.assertEquals(res[1], (ADDR1, TAG1)) self.assertEquals(res[0], (ADDR2, TAG2)) # remove the wildcard mapping for one tagged node n.remove(WILD1, TAG2) res = n.get('abc.foo.com') self.assertEquals(res, [(ADDR1, TAG1)]) # remove the remaining wildcard mapping n.remove(WILD1, TAG1) res = n.get('abc.foo.com') self.assertEquals(res, None)
def test_tagging(self): n = Node() n.put(HOST1, ADDR1, TAG1) res = n.get(HOST1) self.assertEquals(res, [(ADDR1, TAG1)])
def test_todict(self): n = Node() n.put(HOST1, ADDR1, TAG1) self.assertIsNotNone(n.to_dict())
def __init__(self): self._mappings = {} self._active = {} self._domains = Node() self._lock = threading.Lock()