def test_cluster_reset(self): hosts = [URI.address("db1.pilosa.com"), URI.address("db2.pilosa.com")] c = Cluster(*hosts) target1 = [(host, True) for host in hosts] self.assertEqual(target1, c.hosts) c.remove_host(URI.address("db1.pilosa.com")) c.remove_host(URI.address("db2.pilosa.com")) target2 = [(host, False) for host in hosts] self.assertEqual(target2, c.hosts) c._reset() self.assertEqual(target1, c.hosts)
def test_add_remove_host(self): target = [(URI.address("http://localhost:3000"), True)] c = Cluster() c.add_host(URI.address("http://localhost:3000")) # add the same host, the list of hosts should be the same c.add_host(URI.address("http://localhost:3000")) self.assertEquals(target, c.hosts) target = [(URI.address("http://localhost:3000"), True), (URI(), True)] c.add_host(URI()) self.assertEquals(target, c.hosts) target = [(URI.address("http://localhost:3000"), False), (URI(), True)] c.remove_host(URI.address("http://localhost:3000")) self.assertEquals(target, c.hosts)
def test_get_host(self): target1 = URI.address("db1.pilosa.com") target2 = URI.address("db2.pilosa.com") c = Cluster() c.add_host(URI.address("db1.pilosa.com")) c.add_host(URI.address("db2.pilosa.com")) addr = c.get_host() self.assertEquals(target1, addr) addr = c.get_host() self.assertEquals(target1, addr) c.get_host() c.remove_host(URI.address("db1.pilosa.com")) addr = c.get_host() self.assertEquals(target2, addr)