Skip to content

Commit afb475b

Browse files
authored
Merge pull request apache#850 from datastax/python-839-tests
Added tests for PYTHON-839
2 parents 3c5000b + 0f3b5be commit afb475b

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

tests/integration/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def set_default_cass_ip():
162162

163163
def set_default_beta_flag_true():
164164
defaults = list(Cluster.__init__.__defaults__)
165-
defaults = defaults[:-3] + [True] + defaults[-2:]
165+
defaults = (defaults[:28] + [True] + defaults[29:])
166166
try:
167167
Cluster.__init__.__defaults__ = tuple(defaults)
168168
except:
@@ -255,6 +255,7 @@ def get_unsupported_upper_protocol():
255255
greaterthanorequalcass3_10 = unittest.skipUnless(CASSANDRA_VERSION >= '3.10', 'Cassandra version 3.10 or greater required')
256256
greaterthanorequalcass3_11 = unittest.skipUnless(CASSANDRA_VERSION >= '3.11', 'Cassandra version 3.10 or greater required')
257257
greaterthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION >= '4.0', 'Cassandra version 4.0 or greater required')
258+
lessthanorequalcass40 = unittest.skipIf(CASSANDRA_VERSION >= '4.0', 'Cassandra version 4.0 or greater required')
258259
lessthancass30 = unittest.skipUnless(CASSANDRA_VERSION < '3.0', 'Cassandra version less then 3.0 required')
259260
dseonly = unittest.skipUnless(DSE_VERSION, "Test is only applicalbe to DSE clusters")
260261
pypy = unittest.skipUnless(platform.python_implementation() == "PyPy", "Test is skipped unless it's on PyPy")

tests/integration/standard/test_cluster.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from tests import notwindows
3939
from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions, CASSANDRA_VERSION, \
4040
execute_until_pass, execute_with_long_wait_retry, get_node, MockLoggingHandler, get_unsupported_lower_protocol, \
41-
get_unsupported_upper_protocol, protocolv5, local, CASSANDRA_IP
41+
get_unsupported_upper_protocol, protocolv5, local, CASSANDRA_IP, greaterthanorequalcass30, lessthanorequalcass40
4242
from tests.integration.util import assert_quiescent_pool_state
4343
import sys
4444

@@ -1062,6 +1062,63 @@ def test_replicas_are_queried(self):
10621062

10631063
session.execute('''DROP TABLE test1rf.table_with_big_key''')
10641064

1065+
@unittest.skip
1066+
@greaterthanorequalcass30
1067+
@lessthanorequalcass40
1068+
def test_compact_option(self):
1069+
"""
1070+
Test the driver can connect with the no_compact option and the results
1071+
are as expected. This test is very similar to the corresponding dtest
1072+
1073+
@since 3.12
1074+
@jira_ticket PYTHON-366
1075+
@expected_result only one hosts' metadata will be populated
1076+
1077+
@test_category connection
1078+
"""
1079+
nc_cluster = Cluster(protocol_version=PROTOCOL_VERSION, no_compact=True)
1080+
nc_session = nc_cluster.connect()
1081+
1082+
cluster = Cluster(protocol_version=PROTOCOL_VERSION, no_compact=False)
1083+
session = cluster.connect()
1084+
1085+
self.addCleanup(cluster.shutdown)
1086+
self.addCleanup(nc_cluster.shutdown)
1087+
1088+
nc_session.set_keyspace("test3rf")
1089+
session.set_keyspace("test3rf")
1090+
1091+
nc_session.execute(
1092+
"CREATE TABLE IF NOT EXISTS compact_table (k int PRIMARY KEY, v1 int, v2 int) WITH COMPACT STORAGE;")
1093+
1094+
for i in range(1, 5):
1095+
nc_session.execute(
1096+
"INSERT INTO compact_table (k, column1, v1, v2, value) VALUES "
1097+
"({i}, 'a{i}', {i}, {i}, textAsBlob('b{i}'))".format(i=i))
1098+
nc_session.execute(
1099+
"INSERT INTO compact_table (k, column1, v1, v2, value) VALUES "
1100+
"({i}, 'a{i}{i}', {i}{i}, {i}{i}, textAsBlob('b{i}{i}'))".format(i=i))
1101+
1102+
nc_results = nc_session.execute("SELECT * FROM compact_table")
1103+
self.assertEqual(
1104+
set(nc_results.current_rows),
1105+
{(1, u'a1', 11, 11, 'b1'),
1106+
(1, u'a11', 11, 11, 'b11'),
1107+
(2, u'a2', 22, 22, 'b2'),
1108+
(2, u'a22', 22, 22, 'b22'),
1109+
(3, u'a3', 33, 33, 'b3'),
1110+
(3, u'a33', 33, 33, 'b33'),
1111+
(4, u'a4', 44, 44, 'b4'),
1112+
(4, u'a44', 44, 44, 'b44')})
1113+
1114+
results = session.execute("SELECT * FROM compact_table")
1115+
self.assertEqual(
1116+
set(results.current_rows),
1117+
{(1, 11, 11),
1118+
(2, 22, 22),
1119+
(3, 33, 33),
1120+
(4, 44, 44)})
1121+
10651122
def _assert_replica_queried(self, trace, only_replicas=True):
10661123
queried_hosts = set()
10671124
for row in trace.events:
@@ -1255,6 +1312,7 @@ def test_down_event_with_active_connection(self):
12551312
time.sleep(.01)
12561313
self.assertTrue(was_marked_down)
12571314

1315+
12581316
@local
12591317
class DontPrepareOnIgnoredHostsTest(unittest.TestCase):
12601318
ignored_addresses = ['127.0.0.3']
@@ -1292,6 +1350,7 @@ def test_prepare_on_ignored_hosts(self):
12921350
self.assertEqual(call(unignored_address), c)
12931351
cluster.shutdown()
12941352

1353+
12951354
@local
12961355
class DuplicateRpcTest(unittest.TestCase):
12971356

@@ -1331,7 +1390,6 @@ def test_duplicate(self):
13311390
test_cluster.shutdown()
13321391

13331392

1334-
13351393
@protocolv5
13361394
class BetaProtocolTest(unittest.TestCase):
13371395

0 commit comments

Comments
 (0)