11use futures:: Future ;
2+ use scylla:: frame:: response:: result:: Row ;
3+ use scylla:: transport:: session_builder:: { GenericSessionBuilder , SessionBuilderKind } ;
4+ use scylla:: Session ;
25use std:: collections:: HashMap ;
36use std:: env;
47use std:: net:: SocketAddr ;
8+ use std:: num:: NonZeroU32 ;
59use std:: str:: FromStr ;
10+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
11+ use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
612
713use scylla_proxy:: { Node , Proxy , ProxyError , RunningProxy , ShardAwareness } ;
814
@@ -14,6 +20,23 @@ pub(crate) fn setup_tracing() {
1420 . try_init ( ) ;
1521}
1622
23+ static UNIQUE_COUNTER : AtomicUsize = AtomicUsize :: new ( 0 ) ;
24+
25+ #[ allow( unused) ]
26+ pub ( crate ) fn unique_keyspace_name ( ) -> String {
27+ let cnt = UNIQUE_COUNTER . fetch_add ( 1 , Ordering :: SeqCst ) ;
28+ let name = format ! (
29+ "test_rust_{}_{}" ,
30+ SystemTime :: now( )
31+ . duration_since( UNIX_EPOCH )
32+ . unwrap( )
33+ . as_secs( ) ,
34+ cnt
35+ ) ;
36+ println ! ( "Unique name: {}" , name) ;
37+ name
38+ }
39+
1740pub ( crate ) async fn test_with_3_node_cluster < F , Fut > (
1841 shard_awareness : ShardAwareness ,
1942 test : F ,
6386
6487 running_proxy. finish ( ) . await
6588}
89+
90+ #[ allow( unused) ]
91+ pub ( crate ) async fn supports_feature ( session : & Session , feature : & str ) -> bool {
92+ // Cassandra doesn't have a concept of features, so first detect
93+ // if there is the `supported_features` column in system.local
94+
95+ let meta = session. get_cluster_data ( ) ;
96+ let system_local = meta
97+ . get_keyspace_info ( )
98+ . get ( "system" )
99+ . unwrap ( )
100+ . tables
101+ . get ( "local" )
102+ . unwrap ( ) ;
103+
104+ if !system_local. columns . contains_key ( "supported_features" ) {
105+ return false ;
106+ }
107+
108+ let result = session
109+ . query_unpaged ( "SELECT supported_features FROM system.local" , ( ) )
110+ . await
111+ . unwrap ( )
112+ . into_rows_result ( )
113+ . unwrap ( ) ;
114+
115+ let ( features, ) : ( Option < & str > , ) = result. single_row ( ) . unwrap ( ) ;
116+
117+ features
118+ . unwrap_or_default ( )
119+ . split ( ',' )
120+ . any ( |f| f == feature)
121+ }
122+
123+ #[ allow( unused) ]
124+ pub ( crate ) async fn scylla_supports_tablets ( session : & Session ) -> bool {
125+ let result = session
126+ . query_unpaged (
127+ "select column_name from system_schema.columns where
128+ keyspace_name = 'system_schema'
129+ and table_name = 'scylla_keyspaces'
130+ and column_name = 'initial_tablets'" ,
131+ & [ ] ,
132+ )
133+ . await
134+ . unwrap ( )
135+ . into_rows_result ( ) ;
136+
137+ result. is_ok_and ( |rows_result| rows_result. single_row :: < Row > ( ) . is_ok ( ) )
138+ }
139+
140+ // Creates a generic session builder based on conditional compilation configuration
141+ // For SessionBuilder of DefaultMode type, adds localhost to known hosts, as all of the tests
142+ // connect to localhost.
143+ #[ allow( unused) ]
144+ pub ( crate ) fn create_new_session_builder ( ) -> GenericSessionBuilder < impl SessionBuilderKind > {
145+ let session_builder = {
146+ #[ cfg( not( scylla_cloud_tests) ) ]
147+ {
148+ use scylla:: SessionBuilder ;
149+
150+ let uri = std:: env:: var ( "SCYLLA_URI" ) . unwrap_or_else ( |_| "127.0.0.1:9042" . to_string ( ) ) ;
151+
152+ SessionBuilder :: new ( ) . known_node ( uri)
153+ }
154+
155+ #[ cfg( scylla_cloud_tests) ]
156+ {
157+ use scylla:: transport:: session_builder:: CloudMode ;
158+ use scylla:: CloudSessionBuilder ;
159+ use std:: path:: Path ;
160+
161+ std:: env:: var ( "CLOUD_CONFIG_PATH" )
162+ . map ( |config_path| CloudSessionBuilder :: new ( Path :: new ( & config_path) ) )
163+ . expect ( "Failed to initialize CloudSessionBuilder" )
164+ . expect ( "CLOUD_CONFIG_PATH environment variable is missing" )
165+ }
166+ } ;
167+
168+ // The reason why we enable so long waiting for TracingInfo is... Cassandra. (Yes, again.)
169+ // In Cassandra Java Driver, the wait time for tracing info is 10 seconds, so here we do the same.
170+ // However, as Scylla usually gets TracingInfo ready really fast (our default interval is hence 3ms),
171+ // we stick to a not-so-much-terribly-long interval here.
172+ session_builder
173+ . tracing_info_fetch_attempts ( NonZeroU32 :: new ( 200 ) . unwrap ( ) )
174+ . tracing_info_fetch_interval ( Duration :: from_millis ( 50 ) )
175+ }
0 commit comments