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_create_client(self): # create default client c = Client() self.assertEquals(URI(), c.cluster.hosts[0][0]) # create with cluster c = Client(Cluster(URI.address(":15000"))) self.assertEquals(URI.address(":15000"), c.cluster.hosts[0][0]) # create with URI c = Client(URI.address(":20000")) self.assertEquals(URI.address(":20000"), c.cluster.hosts[0][0]) # create with invalid type self.assertRaises(PilosaError, Client, 15000)
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)
def test_fetch_coordinator_node(self): client = self.get_client() node = client._fetch_coordinator_node() uri = URI.address(self.get_server_address()) self.assertEquals(uri.scheme, node.scheme) self.assertEquals(uri.host, node.host) self.assertEquals(uri.port, node.port)
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_ipv6(self): addresses = [ ("[::1]", "http", "[::1]", 10101), ("[::1]:3333", "http", "[::1]", 3333), ("[fd42:4201:f86b:7e09:216:3eff:fefa:ed80]:3333", "http", "[fd42:4201:f86b:7e09:216:3eff:fefa:ed80]", 3333), ("https://[fd42:4201:f86b:7e09:216:3eff:fefa:ed80]:3333", "https", "[fd42:4201:f86b:7e09:216:3eff:fefa:ed80]", 3333), ] for address, scheme, host, port in addresses: uri = URI.address(address) self.assertEquals(scheme, uri.scheme) self.assertEquals(host, uri.host) self.assertEquals(port, uri.port)
def uri(self): return URI(host=self.host, port=self.port)
def test_port_only(self): uri = URI.address(":5888") self.compare(uri, "http", "localhost", 5888)
def test_full_with_ipv4_host(self): uri = URI.address("http+protobuf://192.168.1.26:3333") self.compare(uri, "http+protobuf", "192.168.1.26", 3333)
def test_full(self): uri = URI.address("http+protobuf://db1.pilosa.com:3333") self.compare(uri, "http+protobuf", "db1.pilosa.com", 3333)
def test_equals(self): uri1 = URI(host="pilosa.com", port=1337) uri2 = URI.address("http://pilosa.com:1337") self.assertTrue(uri1 == uri2)
def test_to_string(self): uri = URI() self.assertEquals("http://localhost:10101", "%s" % uri)
def test_normalized_address(self): uri = URI.address("https+pb://big-data.pilosa.com:6888") self.assertEquals("https://big-data.pilosa.com:6888", uri._normalize()) uri = URI.address("https://big-data.pilosa.com:6888") self.assertEquals("https://big-data.pilosa.com:6888", uri._normalize())
def test_scheme_port(self): uri = URI.address("https://:5553") self.compare(uri, "https", "localhost", 5553)
def test_scheme_host(self): uri = URI.address("https://db1.big-data.com") self.compare(uri, "https", "db1.big-data.com", 10101)
def test_host_port(self): uri = URI.address("db1.big-data.com:5888") self.compare(uri, "http", "db1.big-data.com", 5888)
def test_default(self): uri = URI() self.compare(uri, "http", "localhost", 10101)
def test_equals_fails_with_other_object(self): self.assertFalse(URI() == "http://localhost:10101")
def test_host_port_alternative(self): uri = URI(host="db1.pilosa.com", port=3333) self.compare(uri, "http", "db1.pilosa.com", 3333)
def test_equals_same_object(self): uri = URI.address("https://pilosa.com:1337") self.assertEquals(uri, uri)
def test_host_only(self): uri = URI.address("db1.pilosa.com") self.compare(uri, "http", "db1.pilosa.com", 10101)
def test_repr(self): uri = URI.address("https://pilosa.com:1337") self.assertEquals("<URI https://pilosa.com:1337>", repr(uri))
def test_failover_fail(self): uris = [URI.address("nonexistent%s" % i) for i in range(20)] client = Client(Cluster(*uris)) self.assertRaises(PilosaError, client.query, self.frame.bitmap(5))
def test_create_with_host(self): target = [(URI.address("http://localhost:3000"), True)] c = Cluster(URI.address("http://localhost:3000")) self.assertEquals(target, c.hosts)