From d89b5688052d337e54f81bd05115900bd6f35d0b Mon Sep 17 00:00:00 2001 From: GregBestland Date: Tue, 12 Apr 2016 19:39:39 -0500 Subject: [PATCH] PYTHON-103, PYTHON-415, Adding tests for host resolution, and duplication --- tests/integration/standard/test_cluster.py | 32 ++++++++++++++++++++++ tests/unit/test_cluster.py | 14 +++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/tests/integration/standard/test_cluster.py b/tests/integration/standard/test_cluster.py index 003c78a9..77cd666c 100644 --- a/tests/integration/standard/test_cluster.py +++ b/tests/integration/standard/test_cluster.py @@ -41,6 +41,38 @@ def setup_module(): class ClusterTests(unittest.TestCase): + def test_host_resolution(self): + """ + Test to insure A records are resolved appropriately. + + @since 3.3 + @jira_ticket PYTHON-415 + @expected_result hostname will be transformed into IP + + @test_category connection + """ + cluster = Cluster(contact_points=["localhost"], protocol_version=PROTOCOL_VERSION, connect_timeout=1) + self.assertTrue('127.0.0.1' in cluster.contact_points_resolved) + + def test_host_duplication(self): + """ + Ensure that duplicate hosts in the contact points are surfaced in the cluster metadata + + @since 3.3 + @jira_ticket PYTHON-103 + @expected_result duplicate hosts aren't surfaced in cluster.metadata + + @test_category connection + """ + cluster = Cluster(contact_points=["localhost", "127.0.0.1", "localhost", "localhost", "localhost"], protocol_version=PROTOCOL_VERSION, connect_timeout=1) + cluster.connect() + self.assertEqual(len(cluster.metadata.all_hosts()), 3) + cluster.shutdown() + cluster = Cluster(contact_points=["127.0.0.1", "localhost"], protocol_version=PROTOCOL_VERSION, connect_timeout=1) + cluster.connect() + self.assertEqual(len(cluster.metadata.all_hosts()), 3) + cluster.shutdown() + def test_raise_error_on_control_connection_timeout(self): """ Test for initial control connection timeout diff --git a/tests/unit/test_cluster.py b/tests/unit/test_cluster.py index 763875c9..ec3516ca 100644 --- a/tests/unit/test_cluster.py +++ b/tests/unit/test_cluster.py @@ -20,10 +20,19 @@ except ImportError: from mock import patch, Mock from cassandra import ConsistencyLevel -from cassandra.cluster import _Scheduler, Session +from cassandra.cluster import _Scheduler, Session, Cluster from cassandra.query import SimpleStatement +class ContactListTest(unittest.TestCase): + + def test_invalid_types(self, *args): + with self.assertRaises(ValueError): + Cluster(contact_points=[None], protocol_version=4, connect_timeout=1) + with self.assertRaises(TypeError): + Cluster(contact_points="not a sequence", protocol_version=4, connect_timeout=1) + + class SchedulerTest(unittest.TestCase): # TODO: this suite could be expanded; for now just adding a test covering a ticket @@ -35,9 +44,6 @@ class SchedulerTest(unittest.TestCase): PYTHON-473 """ - sched = _Scheduler(None) - sched.schedule(0, lambda: None) - sched.schedule(0, lambda: None) # pre-473: "TypeError: unorderable types: function() < function()"t class SessionTest(unittest.TestCase):