forked from apache/cassandra-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_endpoints.py
More file actions
70 lines (54 loc) · 2.13 KB
/
test_endpoints.py
File metadata and controls
70 lines (54 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright DataStax, Inc.
#
# Licensed under the DataStax DSE Driver License;
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.datastax.com/terms/datastax-dse-driver-license-terms
try:
import unittest2 as unittest
except ImportError:
import unittest # noqa
import itertools
from cassandra.connection import DefaultEndPoint, SniEndPoint, SniEndPointFactory
from mock import patch
def socket_getaddrinfo(*args):
return [
(0, 0, 0, '', ('127.0.0.1', 30002)),
(0, 0, 0, '', ('127.0.0.2', 30002)),
(0, 0, 0, '', ('127.0.0.3', 30002))
]
@patch('socket.getaddrinfo', socket_getaddrinfo)
class SniEndPointTest(unittest.TestCase):
endpoint_factory = SniEndPointFactory("proxy.datastax.com", 30002)
def test_sni_endpoint_properties(self):
endpoint = self.endpoint_factory.create_from_sni('test')
self.assertEqual(endpoint.address, 'proxy.datastax.com')
self.assertEqual(endpoint.port, 30002)
self.assertEqual(endpoint._server_name, 'test')
self.assertEqual(str(endpoint), 'proxy.datastax.com:30002:test')
def test_endpoint_equality(self):
self.assertNotEqual(
DefaultEndPoint('10.0.0.1'),
self.endpoint_factory.create_from_sni('10.0.0.1')
)
self.assertEqual(
self.endpoint_factory.create_from_sni('10.0.0.1'),
self.endpoint_factory.create_from_sni('10.0.0.1')
)
self.assertNotEqual(
self.endpoint_factory.create_from_sni('10.0.0.1'),
self.endpoint_factory.create_from_sni('10.0.0.0')
)
self.assertNotEqual(
self.endpoint_factory.create_from_sni('10.0.0.1'),
SniEndPointFactory("proxy.datastax.com", 9999).create_from_sni('10.0.0.1')
)
def test_endpoint_resolve(self):
ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3']
it = itertools.cycle(ips)
endpoint = self.endpoint_factory.create_from_sni('test')
for i in range(10):
(address, _) = endpoint.resolve()
self.assertEqual(address, next(it))