Skip to content

Commit 04e6b7a

Browse files
committed
More integration tests
1 parent b16c479 commit 04e6b7a

File tree

5 files changed

+91
-35
lines changed

5 files changed

+91
-35
lines changed

tests/integration/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def _id_and_mark(f):
333333
greaterthanorequalcass31 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.1'), 'Cassandra version 3.1 or greater required')
334334
greaterthanorequalcass36 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.6'), 'Cassandra version 3.6 or greater required')
335335
greaterthanorequalcass3_10 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.10'), 'Cassandra version 3.10 or greater required')
336-
greaterthanorequalcass3_11 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.11'), 'Cassandra version 3.10 or greater required')
336+
greaterthanorequalcass3_11 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.11'), 'Cassandra version 3.11 or greater required')
337337
greaterthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION >= Version('4.0'), 'Cassandra version 4.0 or greater required')
338338
lessthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION <= Version('4.0'), 'Cassandra version less or equal to 4.0 required')
339339
lessthancass40 = unittest.skipUnless(CASSANDRA_VERSION < Version('4.0'), 'Cassandra version less than 4.0 required')
@@ -350,7 +350,7 @@ def _id_and_mark(f):
350350
requiresmallclockgranularity = unittest.skipIf("Windows" in platform.system() or "asyncore" in EVENT_LOOP_MANAGER,
351351
"This test is not suitible for environments with large clock granularity")
352352
requiressimulacron = unittest.skipIf(SIMULACRON_JAR is None or CASSANDRA_VERSION < Version("2.1"), "Simulacron jar hasn't been specified or C* version is 2.0")
353-
353+
requirecassandra = unittest.skipIf(DSE_VERSION, "Cassandra required")
354354

355355
def wait_for_node_socket(node, timeout):
356356
binary_itf = node.network_interfaces['binary']

tests/integration/standard/test_metrics.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
from cassandra import ConsistencyLevel, WriteTimeout, Unavailable, ReadTimeout
2727
from cassandra.protocol import SyntaxException
2828

29-
from cassandra.cluster import Cluster, NoHostAvailable
29+
from cassandra.cluster import Cluster, NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT
3030
from tests.integration import get_cluster, get_node, use_singledc, PROTOCOL_VERSION, execute_until_pass
3131
from greplin import scales
3232
from tests.integration import BasicSharedKeyspaceUnitTestCaseRF3WM, BasicExistingKeyspaceUnitTestCase, local
3333

34+
import pprint as pp
35+
36+
3437
def setup_module():
3538
use_singledc()
3639

@@ -40,10 +43,15 @@ class MetricsTests(unittest.TestCase):
4043
def setUp(self):
4144
contact_point = ['127.0.0.2']
4245
self.cluster = Cluster(contact_points=contact_point, metrics_enabled=True, protocol_version=PROTOCOL_VERSION,
43-
load_balancing_policy=HostFilterPolicy(
44-
RoundRobinPolicy(), lambda host: host.address in contact_point
45-
),
46-
default_retry_policy=FallthroughRetryPolicy())
46+
execution_profiles=
47+
{EXEC_PROFILE_DEFAULT:
48+
ExecutionProfile(
49+
load_balancing_policy=HostFilterPolicy(
50+
RoundRobinPolicy(), lambda host: host.address in contact_point),
51+
retry_policy=FallthroughRetryPolicy()
52+
)
53+
}
54+
)
4755
self.session = self.cluster.connect("test3rf", wait_for_all_pools=True)
4856

4957
def tearDown(self):
@@ -196,7 +204,7 @@ def test_metrics_per_cluster(self):
196204
"""
197205

198206
cluster2 = Cluster(metrics_enabled=True, protocol_version=PROTOCOL_VERSION,
199-
default_retry_policy=FallthroughRetryPolicy())
207+
execution_profiles={EXEC_PROFILE_DEFAULT: ExecutionProfile(retry_policy=FallthroughRetryPolicy())})
200208
cluster2.connect(self.ks_name, wait_for_all_pools=True)
201209

202210
self.assertEqual(len(cluster2.metadata.all_hosts()), 3)
@@ -248,10 +256,12 @@ def test_duplicate_metrics_per_cluster(self):
248256
@test_category metrics
249257
"""
250258
cluster2 = Cluster(metrics_enabled=True, protocol_version=PROTOCOL_VERSION,
251-
default_retry_policy=FallthroughRetryPolicy())
259+
monitor_reporting_enabled=False,
260+
execution_profiles={EXEC_PROFILE_DEFAULT: ExecutionProfile(retry_policy=FallthroughRetryPolicy())})
252261

253262
cluster3 = Cluster(metrics_enabled=True, protocol_version=PROTOCOL_VERSION,
254-
default_retry_policy=FallthroughRetryPolicy())
263+
monitor_reporting_enabled=False,
264+
execution_profiles={EXEC_PROFILE_DEFAULT: ExecutionProfile(retry_policy=FallthroughRetryPolicy())})
255265

256266
# Ensure duplicate metric names are not allowed
257267
cluster2.metrics.set_stats_name("appcluster")
@@ -334,6 +344,10 @@ def __str__(self):
334344

335345
class MetricsRequestSize(BasicExistingKeyspaceUnitTestCase):
336346

347+
@classmethod
348+
def setUpClass(cls):
349+
cls.common_setup(1, keyspace_creation=False, monitor_reporting_enabled=False)
350+
337351
def wait_for_count(self, ra, expected_count, error=False):
338352
for _ in range(10):
339353
if not error:

tests/integration/standard/test_policies.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
except ImportError:
1818
import unittest # noqa
1919

20-
from cassandra.cluster import Cluster, ExecutionProfile, ResponseFuture
20+
from cassandra.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT
2121
from cassandra.policies import HostFilterPolicy, RoundRobinPolicy, SimpleConvictionPolicy, \
2222
WhiteListRoundRobinPolicy
2323
from cassandra.pool import Host
@@ -27,6 +27,7 @@
2727

2828
from concurrent.futures import wait as wait_futures
2929

30+
3031
def setup_module():
3132
use_singledc()
3233

@@ -51,8 +52,10 @@ def test_predicate_changes(self):
5152
all_hosts = {Host(DefaultEndPoint("127.0.0.{}".format(i)), SimpleConvictionPolicy) for i in (1, 2, 3)}
5253

5354
predicate = lambda host: host.endpoint == contact_point if external_event else True
54-
cluster = Cluster((contact_point,), load_balancing_policy=HostFilterPolicy(RoundRobinPolicy(),
55-
predicate=predicate),
55+
hfp = ExecutionProfile(
56+
load_balancing_policy=HostFilterPolicy(RoundRobinPolicy(), predicate=predicate)
57+
)
58+
cluster = Cluster((contact_point,), execution_profiles={EXEC_PROFILE_DEFAULT: hfp},
5659
protocol_version=PROTOCOL_VERSION, topology_event_refresh_window=0,
5760
status_event_refresh_window=0)
5861
session = cluster.connect(wait_for_all_pools=True)

tests/integration/standard/test_prepared_statements.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323

2424
from cassandra import ConsistencyLevel, ProtocolVersion
2525
from cassandra.cluster import Cluster
26-
from cassandra.query import PreparedStatement, UNSET_VALUE, tuple_factory
27-
from tests.integration import (get_server_versions, greaterthanorequalcass40,
28-
set_default_beta_flag_true,
29-
BasicSharedKeyspaceUnitTestCase)
26+
from cassandra.query import PreparedStatement, UNSET_VALUE
27+
from tests.integration import (get_server_versions, greaterthanorequalcass40, greaterthanorequaldse50,
28+
requirecassandra, BasicSharedKeyspaceUnitTestCase)
3029

3130
import logging
3231

3332

3433
LOG = logging.getLogger(__name__)
3534

35+
3636
def setup_module():
3737
use_singledc()
3838

@@ -546,12 +546,12 @@ def test_id_is_not_updated_conditional_v4(self):
546546
self.addCleanup(cluster.shutdown)
547547
self._test_updated_conditional(session, 9)
548548

549+
@requirecassandra
549550
def test_id_is_not_updated_conditional_v5(self):
550551
"""
551552
Test that verifies that the result_metadata and the
552553
result_metadata_id are udpated correctly in conditional statements
553554
in protocol V5
554-
555555
@since 3.13
556556
@jira_ticket PYTHON-847
557557
"""
@@ -560,6 +560,36 @@ def test_id_is_not_updated_conditional_v5(self):
560560
self.addCleanup(cluster.shutdown)
561561
self._test_updated_conditional(session, 10)
562562

563+
@greaterthanorequaldse50
564+
def test_id_is_not_updated_conditional_dsev1(self):
565+
"""
566+
Test that verifies that the result_metadata and the
567+
result_metadata_id are udpated correctly in conditional statements
568+
in protocol DSE V1
569+
570+
@since 3.13
571+
@jira_ticket PYTHON-847
572+
"""
573+
cluster = Cluster(protocol_version=ProtocolVersion.DSE_V1)
574+
session = cluster.connect()
575+
self.addCleanup(cluster.shutdown)
576+
self._test_updated_conditional(session, 10)
577+
578+
@greaterthanorequaldse50
579+
def test_id_is_not_updated_conditional_dsev2(self):
580+
"""
581+
Test that verifies that the result_metadata and the
582+
result_metadata_id are udpated correctly in conditional statements
583+
in protocol DSE V2
584+
585+
@since 3.13
586+
@jira_ticket PYTHON-847
587+
"""
588+
cluster = Cluster(protocol_version=ProtocolVersion.DSE_V2)
589+
session = cluster.connect()
590+
self.addCleanup(cluster.shutdown)
591+
self._test_updated_conditional(session, 10)
592+
563593
def _test_updated_conditional(self, session, value):
564594
prepared_statement = session.prepare(
565595
"INSERT INTO {}(a, b, d) VALUES "
@@ -573,7 +603,7 @@ def check_result_and_metadata(expected):
573603
expected
574604
)
575605
self.assertEqual(prepared_statement.result_metadata_id, first_id)
576-
self.assertEqual(prepared_statement.result_metadata, [])
606+
self.assertIsNone(prepared_statement.result_metadata)
577607

578608
# Successful conditional update
579609
check_result_and_metadata((True,))

tests/integration/standard/test_query.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from cassandra.policies import HostDistance, RoundRobinPolicy, WhiteListRoundRobinPolicy
2929
from tests.integration import use_singledc, PROTOCOL_VERSION, BasicSharedKeyspaceUnitTestCase, \
3030
greaterthanprotocolv3, MockLoggingHandler, get_supported_protocol_versions, local, get_cluster, setup_keyspace, \
31-
USE_CASS_EXTERNAL, greaterthanorequalcass40
31+
USE_CASS_EXTERNAL, greaterthanorequalcass40, DSE_VERSION
3232
from tests import notwindows
3333
from tests.integration import greaterthanorequalcass30, get_node
3434

@@ -122,18 +122,20 @@ def test_trace_id_to_resultset(self):
122122
self.assertListEqual([rs_trace], rs.get_all_query_traces())
123123

124124
def test_trace_ignores_row_factory(self):
125-
self.session.row_factory = dict_factory
125+
with Cluster(protocol_version=PROTOCOL_VERSION,
126+
execution_profiles={EXEC_PROFILE_DEFAULT: ExecutionProfile(row_factory=dict_factory)}) as cluster:
126127

127-
query = "SELECT * FROM system.local"
128-
statement = SimpleStatement(query)
129-
rs = self.session.execute(statement, trace=True)
128+
s = cluster.connect()
129+
query = "SELECT * FROM system.local"
130+
statement = SimpleStatement(query)
131+
rs = s.execute(statement, trace=True)
130132

131-
# Ensure this does not throw an exception
132-
trace = rs.get_query_trace()
133-
self.assertTrue(trace.events)
134-
str(trace)
135-
for event in trace.events:
136-
str(event)
133+
# Ensure this does not throw an exception
134+
trace = rs.get_query_trace()
135+
self.assertTrue(trace.events)
136+
str(trace)
137+
for event in trace.events:
138+
str(event)
137139

138140
@local
139141
@greaterthanprotocolv3
@@ -773,15 +775,19 @@ def test_unicode(self):
773775
self.session.execute("DROP TABLE test3rf.testtext")
774776

775777
def test_too_many_statements(self):
778+
# The actual max # of statements is 0xFFFF, but this can occasionally cause a server write timeout.
779+
large_batch = 0xFFF
776780
max_statements = 0xFFFF
777781
ss = SimpleStatement("INSERT INTO test3rf.test (k, v) VALUES (0, 0)")
778782
b = BatchStatement(batch_type=BatchType.UNLOGGED, consistency_level=ConsistencyLevel.ONE)
779783

780-
# max works
781-
b.add_all([ss] * max_statements, [None] * max_statements)
782-
self.session.execute(b)
784+
# large number works works
785+
b.add_all([ss] * large_batch, [None] * large_batch)
786+
self.session.execute(b, timeout=30.0)
783787

788+
b = BatchStatement(batch_type=BatchType.UNLOGGED, consistency_level=ConsistencyLevel.ONE)
784789
# max + 1 raises
790+
b.add_all([ss] * max_statements, [None] * max_statements)
785791
self.assertRaises(ValueError, b.add, ss)
786792

787793
# also would have bombed trying to encode
@@ -1392,6 +1398,7 @@ def tearDownClass(cls):
13921398
cls.session.execute(ddl)
13931399
cls.cluster.shutdown()
13941400

1401+
13951402
class QueryKeyspaceTests(BaseKeyspaceTests):
13961403

13971404
def test_setting_keyspace(self):
@@ -1435,7 +1442,8 @@ def test_setting_keyspace_and_session_after_created(self):
14351442
14361443
@test_category query
14371444
"""
1438-
cluster = Cluster(protocol_version=ProtocolVersion.V5, allow_beta_protocol_version=True)
1445+
pv = ProtocolVersion.DSE_V2 if DSE_VERSION else ProtocolVersion.V5
1446+
cluster = Cluster(protocol_version=pv, allow_beta_protocol_version=True)
14391447
session = cluster.connect()
14401448
self.addCleanup(cluster.shutdown)
14411449

@@ -1453,7 +1461,8 @@ def test_setting_keyspace_and_same_session(self):
14531461
14541462
@test_category query
14551463
"""
1456-
cluster = Cluster(protocol_version=ProtocolVersion.V5, allow_beta_protocol_version=True)
1464+
pv = ProtocolVersion.DSE_V2 if DSE_VERSION else ProtocolVersion.V5
1465+
cluster = Cluster(protocol_version=pv, allow_beta_protocol_version=True)
14571466
session = cluster.connect(self.ks_name)
14581467
self.addCleanup(cluster.shutdown)
14591468

0 commit comments

Comments
 (0)