Skip to content

Commit 421b01e

Browse files
authored
PYTHON-1393 Add support for Cassandra 4.1.x and 5.0 releases to CI (#1220)
1 parent 9952e2a commit 421b01e

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

Jenkinsfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import com.datastax.jenkins.drivers.python.Slack
3030

3131
slack = new Slack()
3232

33-
DEFAULT_CASSANDRA = ['3.0', '3.11', '4.0']
33+
DEFAULT_CASSANDRA = ['3.0', '3.11', '4.0', '4.1', '5.0-beta1']
3434
DEFAULT_DSE = ['dse-5.1.35', 'dse-6.8.30']
3535
DEFAULT_RUNTIME = ['3.8.16', '3.9.16', '3.10.11', '3.11.3', '3.12.0']
3636
DEFAULT_CYTHON = ["True", "False"]
@@ -557,6 +557,10 @@ pipeline {
557557
<td><strong>4.0</strong></td>
558558
<td>Apache CassandraⓇ v4.0.x</td>
559559
</tr>
560+
<tr>
561+
<td><strong>5.0-beta1</strong></td>
562+
<td>Apache CassandraⓇ v5.0-beta1</td>
563+
</tr>
560564
<tr>
561565
<td><strong>dse-5.1.35</strong></td>
562566
<td>DataStax Enterprise v5.1.x</td>
@@ -644,7 +648,7 @@ pipeline {
644648
parameterizedCron(branchPatternCron().matcher(env.BRANCH_NAME).matches() ? """
645649
# Every weeknight (Monday - Friday) around 4:00 AM
646650
# These schedules will run with and without Cython enabled for Python 3.8.16 and 3.12.0
647-
H 4 * * 1-5 %CI_SCHEDULE=WEEKNIGHTS;EVENT_LOOP=LIBEV;CI_SCHEDULE_PYTHON_VERSION=3.8.16 3.12.0;CI_SCHEDULE_SERVER_VERSION=3.11 4.0 dse-5.1.35 dse-6.8.30
651+
H 4 * * 1-5 %CI_SCHEDULE=WEEKNIGHTS;EVENT_LOOP=LIBEV;CI_SCHEDULE_PYTHON_VERSION=3.8.16 3.12.0;CI_SCHEDULE_SERVER_VERSION=3.11 4.0 5.0-beta1 dse-5.1.35 dse-6.8.30
648652
""" : "")
649653
}
650654

tests/integration/__init__.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import re
1516
import os
1617
from cassandra.cluster import Cluster
1718

@@ -561,18 +562,23 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
561562

562563
CCM_CLUSTER.set_dse_configuration_options(dse_options)
563564
else:
564-
CCM_CLUSTER = CCMCluster(path, cluster_name, **ccm_options)
565+
ccm_cluster_clz = CCMCluster if Version(cassandra_version) < Version('4.1') else Cassandra41CCMCluster
566+
CCM_CLUSTER = ccm_cluster_clz(path, cluster_name, **ccm_options)
565567
CCM_CLUSTER.set_configuration_options({'start_native_transport': True})
566568
if Version(cassandra_version) >= Version('2.2'):
567569
CCM_CLUSTER.set_configuration_options({'enable_user_defined_functions': True})
568570
if Version(cassandra_version) >= Version('3.0'):
569-
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
570-
if Version(cassandra_version) >= Version('4.0-a'):
571+
# The config.yml option below is deprecated in C* 4.0 per CASSANDRA-17280
572+
if Version(cassandra_version) < Version('4.0'):
573+
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
574+
else:
575+
# Cassandra version >= 4.0
571576
CCM_CLUSTER.set_configuration_options({
572577
'enable_materialized_views': True,
573578
'enable_sasi_indexes': True,
574579
'enable_transient_replication': True,
575580
})
581+
576582
common.switch_cluster(path, cluster_name)
577583
CCM_CLUSTER.set_configuration_options(configuration_options)
578584
CCM_CLUSTER.populate(nodes, ipformat=ipformat, use_single_interface=use_single_interface)
@@ -1011,3 +1017,38 @@ def __new__(cls, **kwargs):
10111017
kwargs['allow_beta_protocol_version'] = cls.DEFAULT_ALLOW_BETA
10121018
return Cluster(**kwargs)
10131019

1020+
# Subclass of CCMCluster (i.e. ccmlib.cluster.Cluster) which transparently performs
1021+
# conversion of cassandra.yml directives into something matching the new syntax
1022+
# introduced by CASSANDRA-15234
1023+
class Cassandra41CCMCluster(CCMCluster):
1024+
__test__ = False
1025+
IN_MS_REGEX = re.compile('^(\w+)_in_ms$')
1026+
IN_KB_REGEX = re.compile('^(\w+)_in_kb$')
1027+
ENABLE_REGEX = re.compile('^enable_(\w+)$')
1028+
1029+
def _get_config_key(self, k, v):
1030+
if "." in k:
1031+
return k
1032+
m = self.IN_MS_REGEX.match(k)
1033+
if m:
1034+
return m.group(1)
1035+
m = self.ENABLE_REGEX.search(k)
1036+
if m:
1037+
return "%s_enabled" % (m.group(1))
1038+
m = self.IN_KB_REGEX.match(k)
1039+
if m:
1040+
return m.group(1)
1041+
return k
1042+
1043+
def _get_config_val(self, k, v):
1044+
m = self.IN_MS_REGEX.match(k)
1045+
if m:
1046+
return "%sms" % (v)
1047+
m = self.IN_KB_REGEX.match(k)
1048+
if m:
1049+
return "%sKiB" % (v)
1050+
return v
1051+
1052+
def set_configuration_options(self, values=None, *args, **kwargs):
1053+
new_values = {self._get_config_key(k, str(v)):self._get_config_val(k, str(v)) for (k,v) in values.items()}
1054+
super(Cassandra41CCMCluster, self).set_configuration_options(values=new_values, *args, **kwargs)

tests/integration/cqlengine/query/test_queryset.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,11 +1362,21 @@ def tearDownClass(cls):
13621362
super(TestModelQueryWithFetchSize, cls).tearDownClass()
13631363
drop_table(TestModelSmall)
13641364

1365-
@execute_count(9)
1365+
@execute_count(19)
13661366
def test_defaultFetchSize(self):
1367+
# Use smaller batch sizes to avoid hitting the max. We trigger an InvalidRequest
1368+
# response for Cassandra 4.1.x and 5.0.x if we just do the whole thing as one
1369+
# large batch. We're just using this to populate values for a test, however,
1370+
# so shifting to smaller batches should be fine.
1371+
for i in range(0, 5000, 500):
1372+
with BatchQuery() as b:
1373+
range_max = i + 500
1374+
for j in range(i, range_max):
1375+
TestModelSmall.batch(b).create(test_id=j)
13671376
with BatchQuery() as b:
1368-
for i in range(5100):
1377+
for i in range(5000, 5100):
13691378
TestModelSmall.batch(b).create(test_id=i)
1379+
13701380
self.assertEqual(len(TestModelSmall.objects.fetch_size(1)), 5100)
13711381
self.assertEqual(len(TestModelSmall.objects.fetch_size(500)), 5100)
13721382
self.assertEqual(len(TestModelSmall.objects.fetch_size(4999)), 5100)

0 commit comments

Comments
 (0)