34
34
from cassandra .metadata import (IndexMetadata , Token , murmur3 , Function , Aggregate , protect_name , protect_names ,
35
35
RegisteredTableExtension , _RegisteredExtensionType , get_schema_parser ,
36
36
group_keys_by_replica , NO_VALID_REPLICA )
37
+ from cassandra .util import SortedSet
37
38
38
39
from tests .integration import (get_cluster , use_singledc , PROTOCOL_VERSION , execute_until_pass ,
39
40
BasicSegregatedKeyspaceUnitTestCase , BasicSharedKeyspaceUnitTestCase ,
40
41
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
+ )
45
47
46
48
47
49
log = logging .getLogger (__name__ )
@@ -94,7 +96,8 @@ def test_host_release_version(self):
94
96
@test_category metadata
95
97
"""
96
98
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
+
98
101
99
102
100
103
@local
@@ -225,7 +228,12 @@ def test_basic_table_meta_properties(self):
225
228
self .assertEqual ([u'a' , u'b' , u'c' ], sorted (tablemeta .columns .keys ()))
226
229
227
230
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
+ )
229
237
230
238
for option in tablemeta .options :
231
239
self .assertIn (option , parser .recognized_table_options )
@@ -405,6 +413,7 @@ def test_composite_in_compound_primary_key_ordering(self):
405
413
tablemeta = self .get_table_metadata ()
406
414
self .check_create_statement (tablemeta , create_statement )
407
415
416
+ @lessthancass40
408
417
def test_compact_storage (self ):
409
418
create_statement = self .make_create_statement (["a" ], [], ["b" ])
410
419
create_statement += " WITH COMPACT STORAGE"
@@ -413,6 +422,7 @@ def test_compact_storage(self):
413
422
tablemeta = self .get_table_metadata ()
414
423
self .check_create_statement (tablemeta , create_statement )
415
424
425
+ @lessthancass40
416
426
def test_dense_compact_storage (self ):
417
427
create_statement = self .make_create_statement (["a" ], ["b" ], ["c" ])
418
428
create_statement += " WITH COMPACT STORAGE"
@@ -431,6 +441,7 @@ def test_counter(self):
431
441
tablemeta = self .get_table_metadata ()
432
442
self .check_create_statement (tablemeta , create_statement )
433
443
444
+ @lessthancass40
434
445
def test_counter_with_compact_storage (self ):
435
446
""" PYTHON-1100 """
436
447
create_statement = (
@@ -442,6 +453,7 @@ def test_counter_with_compact_storage(self):
442
453
tablemeta = self .get_table_metadata ()
443
454
self .check_create_statement (tablemeta , create_statement )
444
455
456
+ @lessthancass40
445
457
def test_counter_with_dense_compact_storage (self ):
446
458
create_statement = (
447
459
"CREATE TABLE {keyspace}.{table} ("
@@ -558,7 +570,6 @@ def test_refresh_schema_metadata(self):
558
570
559
571
@test_category metadata
560
572
"""
561
-
562
573
cluster2 = Cluster (protocol_version = PROTOCOL_VERSION , schema_event_refresh_window = - 1 )
563
574
cluster2 .connect ()
564
575
@@ -599,7 +610,7 @@ def test_refresh_schema_metadata(self):
599
610
self .session .execute ("""CREATE FUNCTION {0}.sum_int(key int, val int)
600
611
RETURNS NULL ON NULL INPUT
601
612
RETURNS int
602
- LANGUAGE javascript AS 'key + val';""" .format (self .keyspace_name ))
613
+ LANGUAGE java AS 'return key+ val; ';""" .format (self .keyspace_name ))
603
614
604
615
self .assertEqual (cluster2 .metadata .keyspaces [self .keyspace_name ].functions , {})
605
616
cluster2 .refresh_schema_metadata ()
@@ -837,7 +848,7 @@ def test_refresh_user_function_metadata(self):
837
848
self .session .execute ("""CREATE FUNCTION {0}.sum_int(key int, val int)
838
849
RETURNS NULL ON NULL INPUT
839
850
RETURNS int
840
- LANGUAGE javascript AS 'key + val';""" .format (self .keyspace_name ))
851
+ LANGUAGE java AS ' return key + val; ';""" .format (self .keyspace_name ))
841
852
842
853
self .assertEqual (cluster2 .metadata .keyspaces [self .keyspace_name ].functions , {})
843
854
cluster2 .refresh_user_function_metadata (self .keyspace_name , UserFunctionDescriptor ("sum_int" , ["int" , "int" ]))
@@ -873,7 +884,7 @@ def test_refresh_user_aggregate_metadata(self):
873
884
self .session .execute ("""CREATE FUNCTION {0}.sum_int(key int, val int)
874
885
RETURNS NULL ON NULL INPUT
875
886
RETURNS int
876
- LANGUAGE javascript AS 'key + val';""" .format (self .keyspace_name ))
887
+ LANGUAGE java AS 'return key + val; ';""" .format (self .keyspace_name ))
877
888
878
889
self .session .execute ("""CREATE AGGREGATE {0}.sum_agg(int)
879
890
SFUNC sum_int
@@ -956,7 +967,8 @@ class Ext1(Ext0):
956
967
self .assertFalse (view_meta .extensions )
957
968
self .assertIn (Ext0 .name , _RegisteredExtensionType ._extension_registry )
958
969
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 )
960
972
961
973
self .cluster .refresh_table_metadata (ks , t )
962
974
table_meta = ks_meta .tables [t ]
@@ -1481,7 +1493,10 @@ def make_function_kwargs(self, called_on_null=True):
1481
1493
'return_type' : 'double' ,
1482
1494
'language' : 'java' ,
1483
1495
'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' : []}
1485
1500
1486
1501
def test_functions_after_udt (self ):
1487
1502
"""
@@ -1632,15 +1647,15 @@ def setup_class(cls):
1632
1647
cls .session .execute ("""CREATE OR REPLACE FUNCTION sum_int(s int, i int)
1633
1648
RETURNS NULL ON NULL INPUT
1634
1649
RETURNS int
1635
- LANGUAGE javascript AS 's + i';""" )
1650
+ LANGUAGE java AS 'return s + i; ';""" )
1636
1651
cls .session .execute ("""CREATE OR REPLACE FUNCTION sum_int_two(s int, i int, j int)
1637
1652
RETURNS NULL ON NULL INPUT
1638
1653
RETURNS int
1639
- LANGUAGE javascript AS 's + i + j';""" )
1654
+ LANGUAGE java AS 'return s + i + j; ';""" )
1640
1655
cls .session .execute ("""CREATE OR REPLACE FUNCTION "List_As_String"(l list<text>)
1641
1656
RETURNS NULL ON NULL INPUT
1642
1657
RETURNS int
1643
- LANGUAGE javascript AS ''''' + l ';""" )
1658
+ LANGUAGE java AS 'return l.size(); ';""" )
1644
1659
cls .session .execute ("""CREATE OR REPLACE FUNCTION extend_list(s list<text>, i int)
1645
1660
CALLED ON NULL INPUT
1646
1661
RETURNS list<text>
@@ -1663,7 +1678,8 @@ def make_aggregate_kwargs(self, state_func, state_type, final_func=None, init_co
1663
1678
'state_type' : state_type ,
1664
1679
'final_func' : final_func ,
1665
1680
'initial_condition' : init_cond ,
1666
- 'return_type' : "does not matter for creation" }
1681
+ 'return_type' : "does not matter for creation" ,
1682
+ 'deterministic' : False }
1667
1683
1668
1684
def test_return_type_meta (self ):
1669
1685
"""
@@ -1887,7 +1903,13 @@ def setup_class(cls):
1887
1903
cls .session .execute ("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" % cls .keyspace_name )
1888
1904
cls .session .set_keyspace (cls .keyspace_name )
1889
1905
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__
1891
1913
cls .cluster .control_connection .reconnect = Mock ()
1892
1914
1893
1915
@classmethod
@@ -1932,28 +1954,36 @@ def test_bad_user_function(self):
1932
1954
self .session .execute ("""CREATE FUNCTION IF NOT EXISTS %s (key int, val int)
1933
1955
RETURNS NULL ON NULL INPUT
1934
1956
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 ("/*\n Warning:" , 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 ("/*\n Warning:" , m .export_as_string ())
1941
1969
1942
1970
@greaterthancass21
1943
1971
def test_bad_user_aggregate (self ):
1944
1972
self .session .execute ("""CREATE FUNCTION IF NOT EXISTS sum_int (key int, val int)
1945
1973
RETURNS NULL ON NULL INPUT
1946
1974
RETURNS int
1947
- LANGUAGE javascript AS 'key + val';""" )
1975
+ LANGUAGE java AS 'return key + val; ';""" )
1948
1976
self .session .execute ("""CREATE AGGREGATE %s(int)
1949
1977
SFUNC sum_int
1950
1978
STYPE int
1951
1979
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 ("/*\n Warning:" , 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 ("/*\n Warning:" , m .export_as_string ())
1957
1987
1958
1988
1959
1989
class DynamicCompositeTypeTest (BasicSharedKeyspaceUnitTestCase ):
@@ -2244,6 +2274,8 @@ def test_base_table_type_alter_mv(self):
2244
2274
test_create_view_metadata tests that materialized views metadata is properly updated when the type of base table
2245
2275
column is changed.
2246
2276
2277
+ Support for alter type was removed in CASSANDRA-12443
2278
+
2247
2279
@since 3.0.0
2248
2280
@jira_ticket CASSANDRA-10424
2249
2281
@expected_result Materialized view metadata should be updated correctly
@@ -2363,6 +2395,21 @@ def test_metadata_with_quoted_identifiers(self):
2363
2395
self .assertIsNotNone (value_column )
2364
2396
self .assertEqual (value_column .name , 'the Value' )
2365
2397
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
+
2366
2413
2367
2414
class GroupPerHost (BasicSharedKeyspaceUnitTestCase ):
2368
2415
@classmethod
@@ -2416,30 +2463,18 @@ class VirtualKeypaceTest(BasicSharedKeyspaceUnitTestCase):
2416
2463
virtual_ks_names = ('system_virtual_schema' , 'system_views' )
2417
2464
2418
2465
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
2437
2467
'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
2441
2469
'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' }
2443
2478
}
2444
2479
}
2445
2480
@@ -2457,6 +2492,7 @@ def test_existing_keyspaces_have_correct_virtual_tags(self):
2457
2492
)
2458
2493
2459
2494
@greaterthanorequalcass40
2495
+ @greaterthanorequaldse67
2460
2496
def test_expected_keyspaces_exist_and_are_virtual (self ):
2461
2497
for name in self .virtual_ks_names :
2462
2498
self .assertTrue (
@@ -2465,6 +2501,7 @@ def test_expected_keyspaces_exist_and_are_virtual(self):
2465
2501
)
2466
2502
2467
2503
@greaterthanorequalcass40
2504
+ @greaterthanorequaldse67
2468
2505
def test_virtual_keyspaces_have_expected_schema_structure (self ):
2469
2506
self .maxDiff = None
2470
2507
0 commit comments