Skip to content

Commit dfd88ac

Browse files
Merge pull request apache#1072 from datastax/test-40
Cassandra 4.0 test changes
2 parents f59be8d + 291ae2e commit dfd88ac

49 files changed

Lines changed: 491 additions & 481 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/integration/__init__.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_server_versions():
7575
if cass_version is not None:
7676
return (cass_version, cql_version)
7777

78-
c = Cluster()
78+
c = TestCluster()
7979
s = c.connect()
8080
row = s.execute('SELECT cql_version, release_version FROM system.local')[0]
8181

@@ -199,33 +199,14 @@ def _get_dse_version_from_cass(cass_version):
199199
CCM_KWARGS['version'] = CCM_VERSION
200200

201201

202-
#This changes the default contact_point parameter in Cluster
203-
def set_default_cass_ip():
204-
if CASSANDRA_IP.startswith("127.0.0."):
205-
return
206-
defaults = list(Cluster.__init__.__defaults__)
207-
defaults = [[CASSANDRA_IP]] + defaults[1:]
208-
try:
209-
Cluster.__init__.__defaults__ = tuple(defaults)
210-
except:
211-
Cluster.__init__.__func__.__defaults__ = tuple(defaults)
212-
213-
214-
def set_default_beta_flag_true():
215-
defaults = list(Cluster.__init__.__defaults__)
216-
defaults = (defaults[:28] + [True] + defaults[29:])
217-
try:
218-
Cluster.__init__.__defaults__ = tuple(defaults)
219-
except:
220-
Cluster.__init__.__func__.__defaults__ = tuple(defaults)
221-
222-
202+
ALLOW_BETA_PROTOCOL = False
223203
def get_default_protocol():
224-
if CASSANDRA_VERSION >= Version('4.0'):
204+
if CASSANDRA_VERSION >= Version('4.0-a'):
225205
if DSE_VERSION:
226206
return ProtocolVersion.DSE_V2
227207
else:
228-
set_default_beta_flag_true()
208+
global ALLOW_BETA_PROTOCOL
209+
ALLOW_BETA_PROTOCOL = True
229210
return ProtocolVersion.V5
230211
if CASSANDRA_VERSION >= Version('3.10'):
231212
if DSE_VERSION:
@@ -254,7 +235,7 @@ def get_supported_protocol_versions():
254235
4.0(C*) -> 5(beta),4,3
255236
4.0(DSE) -> DSE_v2, DSE_V1,4,3
256237
` """
257-
if CASSANDRA_VERSION >= Version('4.0'):
238+
if CASSANDRA_VERSION >= Version('4.0-a'):
258239
if DSE_VERSION:
259240
return (3, 4, ProtocolVersion.DSE_V1, ProtocolVersion.DSE_V2)
260241
else:
@@ -293,7 +274,7 @@ def get_unsupported_upper_protocol():
293274
supported by the version of C* running
294275
"""
295276

296-
if CASSANDRA_VERSION >= Version('4.0'):
277+
if CASSANDRA_VERSION >= Version('4.0-a'):
297278
if DSE_VERSION:
298279
return None
299280
else:
@@ -341,9 +322,9 @@ def _id_and_mark(f):
341322
greaterthanorequalcass36 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.6'), 'Cassandra version 3.6 or greater required')
342323
greaterthanorequalcass3_10 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.10'), 'Cassandra version 3.10 or greater required')
343324
greaterthanorequalcass3_11 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.11'), 'Cassandra version 3.11 or greater required')
344-
greaterthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION >= Version('4.0'), 'Cassandra version 4.0 or greater required')
345-
lessthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION <= Version('4.0'), 'Cassandra version less or equal to 4.0 required')
346-
lessthancass40 = unittest.skipUnless(CASSANDRA_VERSION < Version('4.0'), 'Cassandra version less than 4.0 required')
325+
greaterthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION >= Version('4.0-a'), 'Cassandra version 4.0 or greater required')
326+
lessthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION <= Version('4.0-a'), 'Cassandra version less or equal to 4.0 required')
327+
lessthancass40 = unittest.skipUnless(CASSANDRA_VERSION < Version('4.0-a'), 'Cassandra version less than 4.0 required')
347328
lessthancass30 = unittest.skipUnless(CASSANDRA_VERSION < Version('3.0'), 'Cassandra version less then 3.0 required')
348329
greaterthanorequaldse68 = unittest.skipUnless(DSE_VERSION and DSE_VERSION >= Version('6.8'), "DSE 6.8 or greater required for this test")
349330
greaterthanorequaldse67 = unittest.skipUnless(DSE_VERSION and DSE_VERSION >= Version('6.7'), "DSE 6.7 or greater required for this test")
@@ -469,7 +450,6 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
469450
dse_cluster = True if DSE_VERSION else False
470451
if not workloads:
471452
workloads = []
472-
set_default_cass_ip()
473453

474454
if ccm_options is None and DSE_VERSION:
475455
ccm_options = {"version": CCM_VERSION}
@@ -527,9 +507,6 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
527507
CCM_CLUSTER = DseCluster(path, cluster_name, **ccm_options)
528508
CCM_CLUSTER.set_configuration_options({'start_native_transport': True})
529509
CCM_CLUSTER.set_configuration_options({'batch_size_warn_threshold_in_kb': 5})
530-
if Version(dse_version) >= Version('5.0'):
531-
CCM_CLUSTER.set_configuration_options({'enable_user_defined_functions': True})
532-
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
533510
if Version(dse_version) >= Version('5.1'):
534511
# For Inet4Address
535512
CCM_CLUSTER.set_dse_configuration_options({
@@ -565,6 +542,12 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
565542
CCM_CLUSTER.set_configuration_options({'enable_user_defined_functions': True})
566543
if Version(cassandra_version) >= Version('3.0'):
567544
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
545+
if Version(cassandra_version) >= Version('4.0-a'):
546+
CCM_CLUSTER.set_configuration_options({
547+
'enable_materialized_views': True,
548+
'enable_sasi_indexes': True,
549+
'enable_transient_replication': True,
550+
})
568551
common.switch_cluster(path, cluster_name)
569552
CCM_CLUSTER.set_configuration_options(configuration_options)
570553
CCM_CLUSTER.populate(nodes, ipformat=ipformat)
@@ -699,9 +682,9 @@ def setup_keyspace(ipformat=None, wait=True, protocol_version=None):
699682
_protocol_version = PROTOCOL_VERSION
700683

701684
if not ipformat:
702-
cluster = Cluster(protocol_version=_protocol_version)
685+
cluster = TestCluster(protocol_version=_protocol_version)
703686
else:
704-
cluster = Cluster(contact_points=["::1"], protocol_version=_protocol_version)
687+
cluster = TestCluster(contact_points=["::1"], protocol_version=_protocol_version)
705688
session = cluster.connect()
706689

707690
try:
@@ -795,7 +778,7 @@ def create_keyspace(cls, rf):
795778

796779
@classmethod
797780
def common_setup(cls, rf, keyspace_creation=True, create_class_table=False, **cluster_kwargs):
798-
cls.cluster = Cluster(protocol_version=PROTOCOL_VERSION, **cluster_kwargs)
781+
cls.cluster = TestCluster(**cluster_kwargs)
799782
cls.session = cls.cluster.connect(wait_for_all_pools=True)
800783
cls.ks_name = cls.__name__.lower()
801784
if keyspace_creation:
@@ -981,3 +964,19 @@ def assert_startswith(s, prefix):
981964
raise AssertionError(
982965
'{} does not start with {}'.format(repr(s), repr(prefix))
983966
)
967+
968+
969+
class TestCluster(object):
970+
DEFAULT_PROTOCOL_VERSION = default_protocol_version
971+
DEFAULT_CASSANDRA_IP = CASSANDRA_IP
972+
DEFAULT_ALLOW_BETA = ALLOW_BETA_PROTOCOL
973+
974+
def __new__(cls, **kwargs):
975+
if 'protocol_version' not in kwargs:
976+
kwargs['protocol_version'] = cls.DEFAULT_PROTOCOL_VERSION
977+
if 'contact_points' not in kwargs:
978+
kwargs['contact_points'] = [cls.DEFAULT_CASSANDRA_IP]
979+
if 'allow_beta_protocol_version' not in kwargs:
980+
kwargs['allow_beta_protocol_version'] = cls.DEFAULT_ALLOW_BETA
981+
return Cluster(**kwargs)
982+

tests/integration/advanced/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
from ccmlib import common
2727

28-
from cassandra.cluster import Cluster
29-
30-
from tests.integration import PROTOCOL_VERSION, get_server_versions, BasicKeyspaceUnitTestCase, \
31-
drop_keyspace_shutdown_cluster, get_node, USE_CASS_EXTERNAL, set_default_cass_ip
28+
from tests.integration import get_server_versions, BasicKeyspaceUnitTestCase, \
29+
drop_keyspace_shutdown_cluster, get_node, USE_CASS_EXTERNAL, TestCluster
3230
from tests.integration import use_singledc, use_single_node, wait_for_node_socket, CASSANDRA_IP
3331

3432
home = expanduser('~')
@@ -97,7 +95,6 @@ def use_cluster_with_graph(num_nodes):
9795
when started all at once.
9896
"""
9997
if USE_CASS_EXTERNAL:
100-
set_default_cass_ip()
10198
return
10299

103100
# Create the cluster but don't start it.
@@ -109,7 +106,7 @@ def use_cluster_with_graph(num_nodes):
109106
# Wait for spark master to start up
110107
spark_master_http = ("localhost", 7080)
111108
common.check_socket_listening(spark_master_http, timeout=60)
112-
tmp_cluster = Cluster(protocol_version=PROTOCOL_VERSION)
109+
tmp_cluster = TestCluster()
113110

114111
# Start up remaining nodes.
115112
try:
@@ -137,7 +134,7 @@ class BasicGeometricUnitTestCase(BasicKeyspaceUnitTestCase):
137134

138135
@classmethod
139136
def common_dse_setup(cls, rf, keyspace_creation=True):
140-
cls.cluster = Cluster(protocol_version=PROTOCOL_VERSION)
137+
cls.cluster = TestCluster()
141138
cls.session = cls.cluster.connect()
142139
cls.ks_name = cls.__name__.lower()
143140
if keyspace_creation:

tests/integration/advanced/graph/__init__.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,13 @@ def session_setup(self):
160160
)
161161
)
162162

163-
self.cluster = Cluster(protocol_version=PROTOCOL_VERSION,
164-
execution_profiles={
165-
EXEC_PROFILE_GRAPH_DEFAULT: ep_graphson1,
166-
EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT: ep_analytics,
167-
"graphson1": ep_graphson1,
168-
"graphson2": ep_graphson2,
169-
"graphson3": ep_graphson3
170-
})
163+
self.cluster = TestCluster(execution_profiles={
164+
EXEC_PROFILE_GRAPH_DEFAULT: ep_graphson1,
165+
EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT: ep_analytics,
166+
"graphson1": ep_graphson1,
167+
"graphson2": ep_graphson2,
168+
"graphson3": ep_graphson3
169+
})
171170

172171
self.session = self.cluster.connect()
173172
self.ks_name = self._testMethodName.lower()
@@ -276,14 +275,13 @@ def session_setup(self):
276275
)
277276
)
278277

279-
self.cluster = Cluster(protocol_version=PROTOCOL_VERSION,
280-
execution_profiles={
281-
EXEC_PROFILE_GRAPH_DEFAULT: ep_graphson1,
282-
EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT: ep_analytics,
283-
"graphson1": ep_graphson1,
284-
"graphson2": ep_graphson2,
285-
"graphson3": ep_graphson3
286-
})
278+
self.cluster = TestCluster(execution_profiles={
279+
EXEC_PROFILE_GRAPH_DEFAULT: ep_graphson1,
280+
EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT: ep_analytics,
281+
"graphson1": ep_graphson1,
282+
"graphson2": ep_graphson2,
283+
"graphson3": ep_graphson3
284+
})
287285

288286
self.session = self.cluster.connect()
289287
self.ks_name = self._testMethodName.lower()
@@ -362,7 +360,7 @@ class BasicSharedGraphUnitTestCase(BasicKeyspaceUnitTestCase):
362360

363361
@classmethod
364362
def session_setup(cls):
365-
cls.cluster = Cluster(protocol_version=PROTOCOL_VERSION)
363+
cls.cluster = TestCluster()
366364
cls.session = cls.cluster.connect()
367365
cls.ks_name = cls.__name__.lower()
368366
cls.cass_version, cls.cql_version = get_server_versions()

tests/integration/advanced/graph/test_graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
from cassandra.protocol import SyntaxException
2020
from cassandra.policies import WhiteListRoundRobinPolicy
2121
from cassandra.cluster import NoHostAvailable
22-
from cassandra.cluster import EXEC_PROFILE_GRAPH_DEFAULT, GraphExecutionProfile, Cluster
22+
from cassandra.cluster import EXEC_PROFILE_GRAPH_DEFAULT, GraphExecutionProfile,
2323
from cassandra.graph import single_object_row_factory, Vertex, graph_object_row_factory, \
2424
graph_graphson2_row_factory, graph_graphson3_row_factory
2525
from cassandra.util import SortedSet
2626

27-
from tests.integration import PROTOCOL_VERSION, DSE_VERSION, greaterthanorequaldse51, greaterthanorequaldse68, requiredse
27+
from tests.integration import DSE_VERSION, greaterthanorequaldse51, greaterthanorequaldse68, \
28+
requiredse, TestCluster
2829
from tests.integration.advanced.graph import BasicGraphUnitTestCase, GraphUnitTestCase, \
2930
GraphProtocol, ClassicGraphSchema, CoreGraphSchema, use_single_node_with_graph
3031

@@ -149,8 +150,7 @@ def test_graph_profile(self):
149150
exec_short_timeout.graph_options.graph_name = self.graph_name
150151

151152
# Add a single execution policy on cluster creation
152-
local_cluster = Cluster(protocol_version=PROTOCOL_VERSION,
153-
execution_profiles={"exec_dif_factory": exec_dif_factory})
153+
local_cluster = TestCluster(execution_profiles={"exec_dif_factory": exec_dif_factory})
154154
local_session = local_cluster.connect()
155155
self.addCleanup(local_cluster.shutdown)
156156

tests/integration/advanced/test_adv_metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
from packaging.version import Version
1616

17-
from cassandra.cluster import Cluster
1817
from tests.integration import (BasicExistingKeyspaceUnitTestCase, BasicSharedKeyspaceUnitTestCase,
1918
BasicSharedKeyspaceUnitTestCaseRF1,
2019
greaterthanorequaldse51, greaterthanorequaldse60,
2120
greaterthanorequaldse68, use_single_node,
22-
DSE_VERSION, requiredse, PROTOCOL_VERSION)
21+
DSE_VERSION, requiredse, TestCluster)
2322

2423
try:
2524
import unittest2 as unittest
@@ -393,4 +392,4 @@ def test_connection_on_graph_schema_error(self):
393392
""" % (self.ks_name,))
394393

395394
self.session.execute('TRUNCATE system_schema.vertices')
396-
Cluster(protocol_version=PROTOCOL_VERSION).connect().shutdown()
395+
TestCluster().connect().shutdown()

tests/integration/advanced/test_auth.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
from cassandra.auth import (DSEGSSAPIAuthProvider, DSEPlainTextAuthProvider,
2828
SaslAuthProvider, TransitionalModePlainTextAuthProvider)
29-
from cassandra.cluster import EXEC_PROFILE_GRAPH_DEFAULT, Cluster, NoHostAvailable
29+
from cassandra.cluster import EXEC_PROFILE_GRAPH_DEFAULT, NoHostAvailable
3030
from cassandra.protocol import Unauthorized
3131
from cassandra.query import SimpleStatement
3232
from tests.integration import (get_cluster, greaterthanorequaldse51,
33-
remove_cluster, requiredse, DSE_VERSION)
33+
remove_cluster, requiredse, DSE_VERSION, TestCluster)
3434
from tests.integration.advanced import ADS_HOME, use_single_node_with_graph
3535
from tests.integration.advanced.graph import reset_graph, ClassicGraphFixtures
3636

@@ -157,7 +157,7 @@ def connect_and_query(self, auth_provider, query=None):
157157
Runs a simple system query with the auth_provided specified.
158158
"""
159159
os.environ['KRB5_CONFIG'] = self.krb_conf
160-
self.cluster = Cluster(auth_provider=auth_provider)
160+
self.cluster = TestCluster(auth_provider=auth_provider)
161161
self.session = self.cluster.connect()
162162
query = query if query else "SELECT * FROM system.local"
163163
statement = SimpleStatement(query)
@@ -320,7 +320,7 @@ def _remove_proxy_setup(self):
320320
os.environ['KRB5_CONFIG'] = self.krb_conf
321321
self.refresh_kerberos_tickets(self.cassandra_keytab, "cassandra@DATASTAX.COM", self.krb_conf)
322322
auth_provider = DSEGSSAPIAuthProvider(service='dse', qops=["auth"], principal='cassandra@DATASTAX.COM')
323-
cluster = Cluster(auth_provider=auth_provider)
323+
cluster = TestCluster(auth_provider=auth_provider)
324324
session = cluster.connect()
325325

326326
session.execute("REVOKE PROXY.LOGIN ON ROLE '{0}' FROM '{1}'".format('charlie@DATASTAX.COM', 'bob@DATASTAX.COM'))
@@ -338,7 +338,7 @@ def _setup_for_proxy(self, grant=True):
338338
os.environ['KRB5_CONFIG'] = self.krb_conf
339339
self.refresh_kerberos_tickets(self.cassandra_keytab, "cassandra@DATASTAX.COM", self.krb_conf)
340340
auth_provider = DSEGSSAPIAuthProvider(service='dse', qops=["auth"], principal='cassandra@DATASTAX.COM')
341-
cluster = Cluster(auth_provider=auth_provider)
341+
cluster = TestCluster(auth_provider=auth_provider)
342342
session = cluster.connect()
343343

344344
stmts = [
@@ -403,7 +403,7 @@ def setUpClass(self):
403403
# Create users and test keyspace
404404
self.user_role = 'user1'
405405
self.server_role = 'server'
406-
self.root_cluster = Cluster(auth_provider=DSEPlainTextAuthProvider('cassandra', 'cassandra'))
406+
self.root_cluster = TestCluster(auth_provider=DSEPlainTextAuthProvider('cassandra', 'cassandra'))
407407
self.root_session = self.root_cluster.connect()
408408

409409
stmts = [
@@ -469,7 +469,7 @@ def get_sasl_options(self, mechanism='PLAIN'):
469469
return sasl_options
470470

471471
def connect_and_query(self, auth_provider, execute_as=None, query="SELECT * FROM testproxy.testproxy"):
472-
self.cluster = Cluster(auth_provider=auth_provider)
472+
self.cluster = TestCluster(auth_provider=auth_provider)
473473
self.session = self.cluster.connect()
474474
rs = self.session.execute(query, execute_as=execute_as)
475475
return rs

tests/integration/advanced/test_cont_paging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from tests.integration import use_singledc, greaterthanorequaldse51, BasicSharedKeyspaceUnitTestCaseRF3WM, \
16-
DSE_VERSION, ProtocolVersion, greaterthanorequaldse60, requiredse
16+
DSE_VERSION, ProtocolVersion, greaterthanorequaldse60, requiredse, TestCluster
1717

1818
import logging
1919
log = logging.getLogger(__name__)
@@ -28,7 +28,7 @@
2828
from packaging.version import Version
2929
import time
3030

31-
from cassandra.cluster import Cluster, ExecutionProfile, ContinuousPagingOptions
31+
from cassandra.cluster import ExecutionProfile, ContinuousPagingOptions
3232
from cassandra.concurrent import execute_concurrent
3333
from cassandra.query import SimpleStatement
3434

@@ -64,7 +64,7 @@ def tearDownClass(cls):
6464
@classmethod
6565
def create_cluster(cls):
6666

67-
cls.cluster_with_profiles = Cluster(protocol_version=cls.protocol_version, execution_profiles=cls.execution_profiles)
67+
cls.cluster_with_profiles = TestCluster(protocol_version=cls.protocol_version, execution_profiles=cls.execution_profiles)
6868

6969
cls.session_with_profiles = cls.cluster_with_profiles.connect(wait_for_all_pools=True)
7070
statements_and_params = zip(

0 commit comments

Comments
 (0)