MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / SniEndPointTest

Class SniEndPointTest

tests/unit/test_endpoints.py:27–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26@patch('socket.getaddrinfo', socket_getaddrinfo)
27class SniEndPointTest(unittest.TestCase):
28
29 endpoint_factory = SniEndPointFactory("proxy.datastax.com", 30002)
30
31 def test_sni_endpoint_properties(self):
32
33 endpoint = self.endpoint_factory.create_from_sni('test')
34 self.assertEqual(endpoint.address, 'proxy.datastax.com')
35 self.assertEqual(endpoint.port, 30002)
36 self.assertEqual(endpoint._server_name, 'test')
37 self.assertEqual(str(endpoint), 'proxy.datastax.com:30002:test')
38
39 def test_endpoint_equality(self):
40 self.assertNotEqual(
41 DefaultEndPoint('10.0.0.1'),
42 self.endpoint_factory.create_from_sni('10.0.0.1')
43 )
44
45 self.assertEqual(
46 self.endpoint_factory.create_from_sni('10.0.0.1'),
47 self.endpoint_factory.create_from_sni('10.0.0.1')
48 )
49
50 self.assertNotEqual(
51 self.endpoint_factory.create_from_sni('10.0.0.1'),
52 self.endpoint_factory.create_from_sni('10.0.0.0')
53 )
54
55 self.assertNotEqual(
56 self.endpoint_factory.create_from_sni('10.0.0.1'),
57 SniEndPointFactory("proxy.datastax.com", 9999).create_from_sni('10.0.0.1')
58 )
59
60 def test_endpoint_resolve(self):
61 ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3']
62 it = itertools.cycle(ips)
63
64 endpoint = self.endpoint_factory.create_from_sni('test')
65 for i in range(10):
66 (address, _) = endpoint.resolve()
67 self.assertEqual(address, next(it))
68
69 def test_sni_resolution_start_index(self):
70 factory = SniEndPointFactory("proxy.datastax.com", 9999)
71 initial_index = factory._init_index
72
73 endpoint1 = factory.create_from_sni('sni1')
74 self.assertEqual(factory._init_index, initial_index + 1)
75 self.assertEqual(endpoint1._index, factory._init_index)
76
77 endpoint2 = factory.create_from_sni('sni2')
78 self.assertEqual(factory._init_index, initial_index + 2)
79 self.assertEqual(endpoint2._index, factory._init_index)

Callers

nothing calls this directly

Calls 1

SniEndPointFactoryClass · 0.90

Tested by

no test coverage detected