|
27 | 27 | from packaging.version import Version
|
28 | 28 |
|
29 | 29 | import cassandra
|
30 |
| -from cassandra.cluster import Cluster, Session, NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT |
| 30 | +from cassandra.cluster import Cluster, NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT |
31 | 31 | from cassandra.concurrent import execute_concurrent
|
32 | 32 | from cassandra.policies import (RoundRobinPolicy, ExponentialReconnectionPolicy,
|
33 | 33 | RetryPolicy, SimpleConvictionPolicy, HostDistance,
|
34 | 34 | AddressTranslator, TokenAwarePolicy, HostFilterPolicy)
|
35 | 35 | from cassandra import ConsistencyLevel
|
36 | 36 |
|
37 |
| -from cassandra.pool import Host |
38 | 37 | from cassandra.query import SimpleStatement, TraceUnavailable, tuple_factory
|
39 | 38 | from cassandra.auth import PlainTextAuthProvider, SaslAuthProvider
|
40 | 39 | from cassandra import connection
|
@@ -200,23 +199,31 @@ def test_session_host_parameter(self):
|
200 | 199 |
|
201 | 200 | @test_category connection
|
202 | 201 | """
|
| 202 | + def cleanup(): |
| 203 | + """ |
| 204 | + When this test fails, the inline .shutdown() calls don't get |
| 205 | + called, so we register this as a cleanup. |
| 206 | + """ |
| 207 | + self.cluster_to_shutdown.shutdown() |
| 208 | + self.addCleanup(cleanup) |
| 209 | + |
203 | 210 | # Test with empty list
|
204 |
| - cluster = Cluster(protocol_version=PROTOCOL_VERSION) |
| 211 | + self.cluster_to_shutdown = Cluster([], protocol_version=PROTOCOL_VERSION) |
205 | 212 | with self.assertRaises(NoHostAvailable):
|
206 |
| - Session(cluster, []) |
207 |
| - cluster.shutdown() |
| 213 | + self.cluster_to_shutdown.connect() |
| 214 | + self.cluster_to_shutdown.shutdown() |
208 | 215 |
|
209 | 216 | # Test with only invalid
|
210 |
| - cluster = Cluster(protocol_version=PROTOCOL_VERSION) |
| 217 | + self.cluster_to_shutdown = Cluster(('1.2.3.4',), protocol_version=PROTOCOL_VERSION) |
211 | 218 | with self.assertRaises(NoHostAvailable):
|
212 |
| - Session(cluster, [Host("1.2.3.4", SimpleConvictionPolicy)]) |
213 |
| - cluster.shutdown() |
| 219 | + self.cluster_to_shutdown.connect() |
| 220 | + self.cluster_to_shutdown.shutdown() |
214 | 221 |
|
215 | 222 | # Test with valid and invalid hosts
|
216 |
| - cluster = Cluster(protocol_version=PROTOCOL_VERSION) |
217 |
| - Session(cluster, [Host(x, SimpleConvictionPolicy) for x in |
218 |
| - ("127.0.0.1", "127.0.0.2", "1.2.3.4")]) |
219 |
| - cluster.shutdown() |
| 223 | + self.cluster_to_shutdown = Cluster(("127.0.0.1", "127.0.0.2", "1.2.3.4"), |
| 224 | + protocol_version=PROTOCOL_VERSION) |
| 225 | + self.cluster_to_shutdown.connect() |
| 226 | + self.cluster_to_shutdown.shutdown() |
220 | 227 |
|
221 | 228 | def test_protocol_negotiation(self):
|
222 | 229 | """
|
|
0 commit comments