|
32 | 32 | RetryPolicy, SimpleConvictionPolicy, HostDistance,
|
33 | 33 | AddressTranslator, TokenAwarePolicy, HostFilterPolicy)
|
34 | 34 | from cassandra import ConsistencyLevel
|
| 35 | +from cassandra.protocol import ProtocolHandler, QueryMessage |
35 | 36 |
|
36 | 37 | from cassandra.query import SimpleStatement, TraceUnavailable, tuple_factory
|
37 | 38 | from cassandra.auth import PlainTextAuthProvider, SaslAuthProvider
|
@@ -484,6 +485,47 @@ def test_refresh_schema_table(self):
|
484 | 485 | self.assertEqual(original_system_schema_meta.as_cql_query(), current_system_schema_meta.as_cql_query())
|
485 | 486 | cluster.shutdown()
|
486 | 487 |
|
| 488 | + def test_use_keyspace_blocking(self): |
| 489 | + ks = "test_refresh_schema_type" |
| 490 | + |
| 491 | + cluster = TestCluster() |
| 492 | + |
| 493 | + class ConnectionWrapper(cluster.connection_class): |
| 494 | + def __init__(self, *args, **kwargs): |
| 495 | + super(ConnectionWrapper, self).__init__(*args, **kwargs) |
| 496 | + |
| 497 | + def send_msg(self, msg, request_id, cb, encoder=ProtocolHandler.encode_message, |
| 498 | + decoder=ProtocolHandler.decode_message, result_metadata=None): |
| 499 | + if isinstance(msg, QueryMessage) and f'USE "{ks}"' in msg.query: |
| 500 | + orig_decoder = decoder |
| 501 | + |
| 502 | + def decode_patched(protocol_version, protocol_features, user_type_map, stream_id, flags, opcode, |
| 503 | + body, |
| 504 | + decompressor, result_metadata): |
| 505 | + time.sleep(cluster.control_connection_timeout + 0.1) |
| 506 | + return orig_decoder(protocol_version, protocol_features, user_type_map, stream_id, flags, |
| 507 | + opcode, body, decompressor, result_metadata) |
| 508 | + |
| 509 | + decoder = decode_patched |
| 510 | + |
| 511 | + return super(ConnectionWrapper, self).send_msg(msg, request_id, cb, encoder, decoder, result_metadata) |
| 512 | + |
| 513 | + cluster.connection_class = ConnectionWrapper |
| 514 | + |
| 515 | + cluster.connect().execute(""" |
| 516 | + CREATE KEYSPACE IF NOT EXISTS %s |
| 517 | + WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '2' } |
| 518 | + """ % ks) |
| 519 | + |
| 520 | + try: |
| 521 | + cluster.connect(ks) |
| 522 | + except NoHostAvailable: |
| 523 | + pass |
| 524 | + except Exception as e: |
| 525 | + self.fail(f"got unexpected exception {e}") |
| 526 | + else: |
| 527 | + self.fail("connection should fail, but was not") |
| 528 | + |
487 | 529 | def test_refresh_schema_type(self):
|
488 | 530 | if get_server_versions()[0] < (2, 1, 0):
|
489 | 531 | raise unittest.SkipTest('UDTs were introduced in Cassandra 2.1')
|
|
0 commit comments