Skip to content

Commit 0f73700

Browse files
absurdfarcedkropachev
authored andcommitted
PYTHON-1393 Add support for Cassandra 4.1.x and 5.0 releases to CI (datastax#1220)
1 parent 2d93898 commit 0f73700

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

tests/integration/__init__.py

Lines changed: 45 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

@@ -627,18 +628,24 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
627628
# This allows `test_metadata_with_quoted_identifiers` to run
628629
CCM_CLUSTER.set_configuration_options({'strict_is_not_null_in_views': False})
629630
else:
630-
CCM_CLUSTER = CCMCluster(path, cluster_name, **ccm_options)
631+
ccm_cluster_clz = CCMCluster if Version(cassandra_version) < Version(
632+
'4.1') else Cassandra41CCMCluster
633+
CCM_CLUSTER = ccm_cluster_clz(path, cluster_name, **ccm_options)
631634
CCM_CLUSTER.set_configuration_options({'start_native_transport': True})
632635
if Version(cassandra_version) >= Version('2.2'):
633636
CCM_CLUSTER.set_configuration_options({'enable_user_defined_functions': True})
634637
if Version(cassandra_version) >= Version('3.0'):
635-
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
636-
if Version(cassandra_version) >= Version('4.0-a'):
638+
# The config.yml option below is deprecated in C* 4.0 per CASSANDRA-17280
639+
if Version(cassandra_version) < Version('4.0'):
640+
CCM_CLUSTER.set_configuration_options({'enable_scripted_user_defined_functions': True})
641+
else:
642+
# Cassandra version >= 4.0
637643
CCM_CLUSTER.set_configuration_options({
638644
'enable_materialized_views': True,
639645
'enable_sasi_indexes': True,
640646
'enable_transient_replication': True,
641647
})
648+
642649
common.switch_cluster(path, cluster_name)
643650
CCM_CLUSTER.set_configuration_options(configuration_options)
644651
# Since scylla CCM doesn't yet support this options, we skip it
@@ -1111,3 +1118,38 @@ def __new__(cls, **kwargs):
11111118
kwargs['allow_beta_protocol_version'] = cls.DEFAULT_ALLOW_BETA
11121119
return Cluster(**kwargs)
11131120

1121+
# Subclass of CCMCluster (i.e. ccmlib.cluster.Cluster) which transparently performs
1122+
# conversion of cassandra.yml directives into something matching the new syntax
1123+
# introduced by CASSANDRA-15234
1124+
class Cassandra41CCMCluster(CCMCluster):
1125+
__test__ = False
1126+
IN_MS_REGEX = re.compile('^(\w+)_in_ms$')
1127+
IN_KB_REGEX = re.compile('^(\w+)_in_kb$')
1128+
ENABLE_REGEX = re.compile('^enable_(\w+)$')
1129+
1130+
def _get_config_key(self, k, v):
1131+
if "." in k:
1132+
return k
1133+
m = self.IN_MS_REGEX.match(k)
1134+
if m:
1135+
return m.group(1)
1136+
m = self.ENABLE_REGEX.search(k)
1137+
if m:
1138+
return "%s_enabled" % (m.group(1))
1139+
m = self.IN_KB_REGEX.match(k)
1140+
if m:
1141+
return m.group(1)
1142+
return k
1143+
1144+
def _get_config_val(self, k, v):
1145+
m = self.IN_MS_REGEX.match(k)
1146+
if m:
1147+
return "%sms" % (v)
1148+
m = self.IN_KB_REGEX.match(k)
1149+
if m:
1150+
return "%sKiB" % (v)
1151+
return v
1152+
1153+
def set_configuration_options(self, values=None, *args, **kwargs):
1154+
new_values = {self._get_config_key(k, str(v)):self._get_config_val(k, str(v)) for (k,v) in values.items()}
1155+
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
@@ -1375,11 +1375,21 @@ def tearDownClass(cls):
13751375
super(TestModelQueryWithFetchSize, cls).tearDownClass()
13761376
drop_table(TestModelSmall)
13771377

1378-
@execute_count(9)
1378+
@execute_count(19)
13791379
def test_defaultFetchSize(self):
1380+
# Use smaller batch sizes to avoid hitting the max. We trigger an InvalidRequest
1381+
# response for Cassandra 4.1.x and 5.0.x if we just do the whole thing as one
1382+
# large batch. We're just using this to populate values for a test, however,
1383+
# so shifting to smaller batches should be fine.
1384+
for i in range(0, 5000, 500):
1385+
with BatchQuery() as b:
1386+
range_max = i + 500
1387+
for j in range(i, range_max):
1388+
TestModelSmall.batch(b).create(test_id=j)
13801389
with BatchQuery() as b:
1381-
for i in range(5100):
1390+
for i in range(5000, 5100):
13821391
TestModelSmall.batch(b).create(test_id=i)
1392+
13831393
self.assertEqual(len(TestModelSmall.objects.fetch_size(1)), 5100)
13841394
self.assertEqual(len(TestModelSmall.objects.fetch_size(500)), 5100)
13851395
self.assertEqual(len(TestModelSmall.objects.fetch_size(4999)), 5100)

0 commit comments

Comments
 (0)