Skip to content

Commit 3e2f616

Browse files
committed
merged tests/integration/standard/test_metadata.py
1 parent d38a17e commit 3e2f616

File tree

1 file changed

+88
-51
lines changed

1 file changed

+88
-51
lines changed

tests/integration/standard/test_metadata.py

Lines changed: 88 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434
from cassandra.metadata import (IndexMetadata, Token, murmur3, Function, Aggregate, protect_name, protect_names,
3535
RegisteredTableExtension, _RegisteredExtensionType, get_schema_parser,
3636
group_keys_by_replica, NO_VALID_REPLICA)
37+
from cassandra.util import SortedSet
3738

3839
from tests.integration import (get_cluster, use_singledc, PROTOCOL_VERSION, execute_until_pass,
3940
BasicSegregatedKeyspaceUnitTestCase, BasicSharedKeyspaceUnitTestCase,
4041
BasicExistingKeyspaceUnitTestCase, drop_keyspace_shutdown_cluster, CASSANDRA_VERSION,
41-
get_supported_protocol_versions, greaterthanorequalcass30, lessthancass30, local,
42-
greaterthancass20, greaterthanorequalcass40)
43-
44-
from tests.integration import greaterthancass21
42+
greaterthanorequaldse51, greaterthanorequalcass30, lessthancass30, local,
43+
get_supported_protocol_versions, greaterthancass20,
44+
greaterthancass21, assert_startswith, greaterthanorequalcass40,
45+
greaterthanorequaldse67, lessthancass40
46+
)
4547

4648

4749
log = logging.getLogger(__name__)
@@ -94,7 +96,8 @@ def test_host_release_version(self):
9496
@test_category metadata
9597
"""
9698
for host in self.cluster.metadata.all_hosts():
97-
self.assertTrue(host.release_version.startswith(CASSANDRA_VERSION.base_version))
99+
assert_startswith(host.release_version, CASSANDRA_VERSION.base_version)
100+
98101

99102

100103
@local
@@ -225,7 +228,12 @@ def test_basic_table_meta_properties(self):
225228
self.assertEqual([u'a', u'b', u'c'], sorted(tablemeta.columns.keys()))
226229

227230
cc = self.cluster.control_connection._connection
228-
parser = get_schema_parser(cc, CASSANDRA_VERSION.base_version, 1)
231+
parser = get_schema_parser(
232+
cc,
233+
self.cluster.metadata.get_host(cc.host).release_version,
234+
self.cluster.metadata.get_host(cc.host).dse_version,
235+
1
236+
)
229237

230238
for option in tablemeta.options:
231239
self.assertIn(option, parser.recognized_table_options)
@@ -405,6 +413,7 @@ def test_composite_in_compound_primary_key_ordering(self):
405413
tablemeta = self.get_table_metadata()
406414
self.check_create_statement(tablemeta, create_statement)
407415

416+
@lessthancass40
408417
def test_compact_storage(self):
409418
create_statement = self.make_create_statement(["a"], [], ["b"])
410419
create_statement += " WITH COMPACT STORAGE"
@@ -413,6 +422,7 @@ def test_compact_storage(self):
413422
tablemeta = self.get_table_metadata()
414423
self.check_create_statement(tablemeta, create_statement)
415424

425+
@lessthancass40
416426
def test_dense_compact_storage(self):
417427
create_statement = self.make_create_statement(["a"], ["b"], ["c"])
418428
create_statement += " WITH COMPACT STORAGE"
@@ -431,6 +441,7 @@ def test_counter(self):
431441
tablemeta = self.get_table_metadata()
432442
self.check_create_statement(tablemeta, create_statement)
433443

444+
@lessthancass40
434445
def test_counter_with_compact_storage(self):
435446
""" PYTHON-1100 """
436447
create_statement = (
@@ -442,6 +453,7 @@ def test_counter_with_compact_storage(self):
442453
tablemeta = self.get_table_metadata()
443454
self.check_create_statement(tablemeta, create_statement)
444455

456+
@lessthancass40
445457
def test_counter_with_dense_compact_storage(self):
446458
create_statement = (
447459
"CREATE TABLE {keyspace}.{table} ("
@@ -558,7 +570,6 @@ def test_refresh_schema_metadata(self):
558570
559571
@test_category metadata
560572
"""
561-
562573
cluster2 = Cluster(protocol_version=PROTOCOL_VERSION, schema_event_refresh_window=-1)
563574
cluster2.connect()
564575

@@ -599,7 +610,7 @@ def test_refresh_schema_metadata(self):
599610
self.session.execute("""CREATE FUNCTION {0}.sum_int(key int, val int)
600611
RETURNS NULL ON NULL INPUT
601612
RETURNS int
602-
LANGUAGE javascript AS 'key + val';""".format(self.keyspace_name))
613+
LANGUAGE java AS 'return key+val;';""".format(self.keyspace_name))
603614

604615
self.assertEqual(cluster2.metadata.keyspaces[self.keyspace_name].functions, {})
605616
cluster2.refresh_schema_metadata()
@@ -837,7 +848,7 @@ def test_refresh_user_function_metadata(self):
837848
self.session.execute("""CREATE FUNCTION {0}.sum_int(key int, val int)
838849
RETURNS NULL ON NULL INPUT
839850
RETURNS int
840-
LANGUAGE javascript AS 'key + val';""".format(self.keyspace_name))
851+
LANGUAGE java AS ' return key + val;';""".format(self.keyspace_name))
841852

842853
self.assertEqual(cluster2.metadata.keyspaces[self.keyspace_name].functions, {})
843854
cluster2.refresh_user_function_metadata(self.keyspace_name, UserFunctionDescriptor("sum_int", ["int", "int"]))
@@ -873,7 +884,7 @@ def test_refresh_user_aggregate_metadata(self):
873884
self.session.execute("""CREATE FUNCTION {0}.sum_int(key int, val int)
874885
RETURNS NULL ON NULL INPUT
875886
RETURNS int
876-
LANGUAGE javascript AS 'key + val';""".format(self.keyspace_name))
887+
LANGUAGE java AS 'return key + val;';""".format(self.keyspace_name))
877888

878889
self.session.execute("""CREATE AGGREGATE {0}.sum_agg(int)
879890
SFUNC sum_int
@@ -956,7 +967,8 @@ class Ext1(Ext0):
956967
self.assertFalse(view_meta.extensions)
957968
self.assertIn(Ext0.name, _RegisteredExtensionType._extension_registry)
958969
self.assertIn(Ext1.name, _RegisteredExtensionType._extension_registry)
959-
self.assertEqual(len(_RegisteredExtensionType._extension_registry), 2)
970+
# There will bee the RLAC extension here.
971+
self.assertEqual(len(_RegisteredExtensionType._extension_registry), 3)
960972

961973
self.cluster.refresh_table_metadata(ks, t)
962974
table_meta = ks_meta.tables[t]
@@ -1481,7 +1493,10 @@ def make_function_kwargs(self, called_on_null=True):
14811493
'return_type': 'double',
14821494
'language': 'java',
14831495
'body': 'return new Double(0.0);',
1484-
'called_on_null_input': called_on_null}
1496+
'called_on_null_input': called_on_null,
1497+
'deterministic': False,
1498+
'monotonic': False,
1499+
'monotonic_on': []}
14851500

14861501
def test_functions_after_udt(self):
14871502
"""
@@ -1632,15 +1647,15 @@ def setup_class(cls):
16321647
cls.session.execute("""CREATE OR REPLACE FUNCTION sum_int(s int, i int)
16331648
RETURNS NULL ON NULL INPUT
16341649
RETURNS int
1635-
LANGUAGE javascript AS 's + i';""")
1650+
LANGUAGE java AS 'return s + i;';""")
16361651
cls.session.execute("""CREATE OR REPLACE FUNCTION sum_int_two(s int, i int, j int)
16371652
RETURNS NULL ON NULL INPUT
16381653
RETURNS int
1639-
LANGUAGE javascript AS 's + i + j';""")
1654+
LANGUAGE java AS 'return s + i + j;';""")
16401655
cls.session.execute("""CREATE OR REPLACE FUNCTION "List_As_String"(l list<text>)
16411656
RETURNS NULL ON NULL INPUT
16421657
RETURNS int
1643-
LANGUAGE javascript AS ''''' + l';""")
1658+
LANGUAGE java AS 'return l.size();';""")
16441659
cls.session.execute("""CREATE OR REPLACE FUNCTION extend_list(s list<text>, i int)
16451660
CALLED ON NULL INPUT
16461661
RETURNS list<text>
@@ -1663,7 +1678,8 @@ def make_aggregate_kwargs(self, state_func, state_type, final_func=None, init_co
16631678
'state_type': state_type,
16641679
'final_func': final_func,
16651680
'initial_condition': init_cond,
1666-
'return_type': "does not matter for creation"}
1681+
'return_type': "does not matter for creation",
1682+
'deterministic': False}
16671683

16681684
def test_return_type_meta(self):
16691685
"""
@@ -1887,7 +1903,13 @@ def setup_class(cls):
18871903
cls.session.execute("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" % cls.keyspace_name)
18881904
cls.session.set_keyspace(cls.keyspace_name)
18891905
connection = cls.cluster.control_connection._connection
1890-
cls.parser_class = get_schema_parser(connection, CASSANDRA_VERSION.base_version, timeout=20).__class__
1906+
1907+
cls.parser_class = get_schema_parser(
1908+
connection,
1909+
cls.cluster.metadata.get_host(connection.host).release_version,
1910+
cls.cluster.metadata.get_host(connection.host).dse_version,
1911+
timeout=20
1912+
).__class__
18911913
cls.cluster.control_connection.reconnect = Mock()
18921914

18931915
@classmethod
@@ -1932,28 +1954,36 @@ def test_bad_user_function(self):
19321954
self.session.execute("""CREATE FUNCTION IF NOT EXISTS %s (key int, val int)
19331955
RETURNS NULL ON NULL INPUT
19341956
RETURNS int
1935-
LANGUAGE javascript AS 'key + val';""" % self.function_name)
1936-
with patch.object(self.parser_class, '_build_function', side_effect=self.BadMetaException):
1937-
self.cluster.refresh_schema_metadata() # presently do not capture these errors on udt direct refresh -- make sure it's contained during full refresh
1938-
m = self.cluster.metadata.keyspaces[self.keyspace_name]
1939-
self.assertIs(m._exc_info[0], self.BadMetaException)
1940-
self.assertIn("/*\nWarning:", m.export_as_string())
1957+
LANGUAGE java AS 'return key + val;';""" % self.function_name)
1958+
1959+
#We need to patch as well the reconnect function because after patching the _build_function
1960+
#there will an Error refreshing schema which will trigger a reconnection. If this happened
1961+
#in a timely manner in the call self.cluster.refresh_schema_metadata() it would return an exception
1962+
#due to that a connection would be closed
1963+
with patch.object(self.cluster.control_connection, 'reconnect'):
1964+
with patch.object(self.parser_class, '_build_function', side_effect=self.BadMetaException):
1965+
self.cluster.refresh_schema_metadata() # presently do not capture these errors on udt direct refresh -- make sure it's contained during full refresh
1966+
m = self.cluster.metadata.keyspaces[self.keyspace_name]
1967+
self.assertIs(m._exc_info[0], self.BadMetaException)
1968+
self.assertIn("/*\nWarning:", m.export_as_string())
19411969

19421970
@greaterthancass21
19431971
def test_bad_user_aggregate(self):
19441972
self.session.execute("""CREATE FUNCTION IF NOT EXISTS sum_int (key int, val int)
19451973
RETURNS NULL ON NULL INPUT
19461974
RETURNS int
1947-
LANGUAGE javascript AS 'key + val';""")
1975+
LANGUAGE java AS 'return key + val;';""")
19481976
self.session.execute("""CREATE AGGREGATE %s(int)
19491977
SFUNC sum_int
19501978
STYPE int
19511979
INITCOND 0""" % self.function_name)
1952-
with patch.object(self.parser_class, '_build_aggregate', side_effect=self.BadMetaException):
1953-
self.cluster.refresh_schema_metadata() # presently do not capture these errors on udt direct refresh -- make sure it's contained during full refresh
1954-
m = self.cluster.metadata.keyspaces[self.keyspace_name]
1955-
self.assertIs(m._exc_info[0], self.BadMetaException)
1956-
self.assertIn("/*\nWarning:", m.export_as_string())
1980+
#We have the same issue here as in test_bad_user_function
1981+
with patch.object(self.cluster.control_connection, 'reconnect'):
1982+
with patch.object(self.parser_class, '_build_aggregate', side_effect=self.BadMetaException):
1983+
self.cluster.refresh_schema_metadata() # presently do not capture these errors on udt direct refresh -- make sure it's contained during full refresh
1984+
m = self.cluster.metadata.keyspaces[self.keyspace_name]
1985+
self.assertIs(m._exc_info[0], self.BadMetaException)
1986+
self.assertIn("/*\nWarning:", m.export_as_string())
19571987

19581988

19591989
class DynamicCompositeTypeTest(BasicSharedKeyspaceUnitTestCase):
@@ -2244,6 +2274,8 @@ def test_base_table_type_alter_mv(self):
22442274
test_create_view_metadata tests that materialized views metadata is properly updated when the type of base table
22452275
column is changed.
22462276
2277+
Support for alter type was removed in CASSANDRA-12443
2278+
22472279
@since 3.0.0
22482280
@jira_ticket CASSANDRA-10424
22492281
@expected_result Materialized view metadata should be updated correctly
@@ -2363,6 +2395,21 @@ def test_metadata_with_quoted_identifiers(self):
23632395
self.assertIsNotNone(value_column)
23642396
self.assertEqual(value_column.name, 'the Value')
23652397

2398+
@greaterthanorequaldse51
2399+
def test_dse_workloads(self):
2400+
"""
2401+
Test to ensure dse_workloads is populated appropriately.
2402+
Field added in DSE 5.1
2403+
2404+
@jira_ticket PYTHON-667
2405+
@expected_result dse_workloads set is set on host model
2406+
2407+
@test_category metadata
2408+
"""
2409+
for host in self.cluster.metadata.all_hosts():
2410+
self.assertIsInstance(host.dse_workloads, SortedSet)
2411+
self.assertIn("Cassandra", host.dse_workloads)
2412+
23662413

23672414
class GroupPerHost(BasicSharedKeyspaceUnitTestCase):
23682415
@classmethod
@@ -2416,30 +2463,18 @@ class VirtualKeypaceTest(BasicSharedKeyspaceUnitTestCase):
24162463
virtual_ks_names = ('system_virtual_schema', 'system_views')
24172464

24182465
virtual_ks_structure = {
2419-
'system_views': {
2420-
# map from table names to sets of column names for unordered
2421-
# comparison
2422-
'caches': {'capacity_bytes', 'entry_count', 'hit_count',
2423-
'hit_ratio', 'name', 'recent_hit_rate_per_second',
2424-
'recent_request_rate_per_second', 'request_count',
2425-
'size_bytes'},
2426-
'clients': {'address', 'connection_stage', 'driver_name',
2427-
'driver_version', 'hostname', 'port',
2428-
'protocol_version', 'request_count',
2429-
'ssl_cipher_suite', 'ssl_enabled', 'ssl_protocol',
2430-
'username'},
2431-
'sstable_tasks': {'keyspace_name', 'kind', 'progress',
2432-
'table_name', 'task_id', 'total', 'unit'},
2433-
'thread_pools': {'active_tasks', 'active_tasks_limit',
2434-
'blocked_tasks', 'blocked_tasks_all_time',
2435-
'completed_tasks', 'name', 'pending_tasks'}
2436-
},
2466+
# keyspaces
24372467
'system_virtual_schema': {
2438-
'columns': {'clustering_order', 'column_name',
2439-
'column_name_bytes', 'keyspace_name', 'kind',
2440-
'position', 'table_name', 'type'},
2468+
# tables: columns. columns are a set because we're comparing unordered
24412469
'keyspaces': {'keyspace_name'},
2442-
'tables': {'comment', 'keyspace_name', 'table_name'}
2470+
'tables': {'comment', 'keyspace_name', 'table_name'},
2471+
'columns': {'clustering_order', 'column_name', 'column_name_bytes',
2472+
'keyspace_name', 'kind', 'position', 'table_name',
2473+
'type'}
2474+
},
2475+
'system_views': {
2476+
'sstable_tasks': {'keyspace_name', 'kind', 'progress',
2477+
'table_name', 'task_id', 'total', 'unit'}
24432478
}
24442479
}
24452480

@@ -2457,6 +2492,7 @@ def test_existing_keyspaces_have_correct_virtual_tags(self):
24572492
)
24582493

24592494
@greaterthanorequalcass40
2495+
@greaterthanorequaldse67
24602496
def test_expected_keyspaces_exist_and_are_virtual(self):
24612497
for name in self.virtual_ks_names:
24622498
self.assertTrue(
@@ -2465,6 +2501,7 @@ def test_expected_keyspaces_exist_and_are_virtual(self):
24652501
)
24662502

24672503
@greaterthanorequalcass40
2504+
@greaterthanorequaldse67
24682505
def test_virtual_keyspaces_have_expected_schema_structure(self):
24692506
self.maxDiff = None
24702507

0 commit comments

Comments
 (0)