Skip to content

Commit 3341fcc

Browse files
wip
Signed-off-by: Dusan Malusev <[email protected]>
1 parent 86efc40 commit 3341fcc

File tree

7 files changed

+209
-41
lines changed

7 files changed

+209
-41
lines changed

scylla/tests/ccm_integration/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[path = "../common/mod.rs"]
2+
mod common;
3+
mod new_session;
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
use assert_matches::assert_matches;
2+
use scylla::client::execution_profile::ExecutionProfile;
3+
use scylla::client::session_builder::SessionBuilder;
4+
use scylla::errors::{ConnectionError, ConnectionPoolError, ExecutionError, NewSessionError};
5+
use scylla::policies::retry::DefaultRetryPolicy;
6+
use std::sync::Arc;
7+
8+
use crate::common::retry_policy::NoRetryPolicy;
9+
use crate::common::utils::setup_tracing;
10+
11+
fn get_scylla() -> (String, String, String) {
12+
let uri1 = std::env::var("SCYLLA_URI1").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
13+
let uri2 = std::env::var("SCYLLA_URI2").unwrap_or_else(|_| "127.0.0.2:9042".to_string());
14+
let uri3 = std::env::var("SCYLLA_URI3").unwrap_or_else(|_| "127.0.0.3:9042".to_string());
15+
16+
(uri1, uri2, uri3)
17+
}
18+
19+
#[cfg(not(scylla_cloud_tests))]
20+
#[tokio::test]
21+
async fn proceed_if_only_some_hostnames_are_invalid() {
22+
setup_tracing();
23+
// on purpose left without port
24+
let uri1 = "scylladbisthefastestdb.invalid".to_owned();
25+
// correctly provided port, but unknown domain
26+
let uri2 = "cassandrasuckssomuch.invalid:9042".to_owned();
27+
let uri3 = std::env::var("SCYLLA_URI3").unwrap_or_else(|_| "127.0.0.3:9042".to_string());
28+
29+
let session = SessionBuilder::new()
30+
.known_nodes([uri1, uri2, uri3])
31+
.build()
32+
.await
33+
.unwrap();
34+
35+
assert!(session
36+
.query_unpaged("SELECT host_id FROM system.local", &[])
37+
.await
38+
.is_ok());
39+
}
40+
41+
#[cfg(not(scylla_cloud_tests))]
42+
#[tokio::test]
43+
async fn all_hostnames_invalid() {
44+
setup_tracing();
45+
let uri = "cassandrasuckssomuch.invalid:9042".to_owned();
46+
47+
assert_matches!(
48+
SessionBuilder::new().known_node(uri).build().await,
49+
Err(NewSessionError::FailedToResolveAnyHostname(_))
50+
);
51+
}
52+
53+
#[cfg(not(scylla_cloud_tests))]
54+
#[tokio::test]
55+
async fn no_nodes_available_reconnection_enabled() {
56+
setup_tracing();
57+
58+
let execution_profile = ExecutionProfile::builder()
59+
.retry_policy(Arc::new(DefaultRetryPolicy))
60+
.build();
61+
62+
assert!(SessionBuilder::new()
63+
.default_execution_profile_handle(execution_profile.into_handle())
64+
.build()
65+
.await
66+
.is_ok());
67+
}
68+
69+
#[cfg(not(scylla_cloud_tests))]
70+
#[tokio::test]
71+
async fn no_nodes_available_reconnection_disabled() {
72+
setup_tracing();
73+
// TODO: Replace with CCM
74+
let (uri1, uri2, uri3) = get_scylla();
75+
76+
let execution_profile = ExecutionProfile::builder()
77+
.retry_policy(Arc::new(NoRetryPolicy))
78+
.build();
79+
80+
assert_matches!(
81+
SessionBuilder::new()
82+
.known_nodes([uri1, uri2, uri3])
83+
.default_execution_profile_handle(execution_profile.into_handle())
84+
.build()
85+
.await,
86+
Err(NewSessionError::FailedToResolveAnyHostname(_))
87+
);
88+
}
89+
90+
#[cfg(not(scylla_cloud_tests))]
91+
#[tokio::test]
92+
async fn no_nodes_available_reconnection_enabled_nodes_coming_back() {
93+
setup_tracing();
94+
// TODO: Setup CCM
95+
96+
let execution_profile = ExecutionProfile::builder()
97+
.retry_policy(Arc::new(DefaultRetryPolicy))
98+
.build();
99+
100+
assert!(SessionBuilder::new()
101+
.default_execution_profile_handle(execution_profile.into_handle())
102+
.build()
103+
.await
104+
.is_ok());
105+
}
106+
107+
#[cfg(not(scylla_cloud_tests))]
108+
#[tokio::test]
109+
async fn session_created_nodes_away_reconnection_enabled() {
110+
setup_tracing();
111+
112+
let execution_profile = ExecutionProfile::builder()
113+
.retry_policy(Arc::new(DefaultRetryPolicy))
114+
.build();
115+
116+
let _session = SessionBuilder::new()
117+
.default_execution_profile_handle(execution_profile.into_handle())
118+
.build()
119+
.await
120+
.unwrap();
121+
122+
assert!(true);
123+
}
124+
125+
#[cfg(not(scylla_cloud_tests))]
126+
#[tokio::test]
127+
async fn session_created_nodes_away_reconnection_disabled() {
128+
setup_tracing();
129+
130+
// TODO: Replace with CCM
131+
let (uri1, uri2, uri3) = get_scylla();
132+
133+
let execution_profile = ExecutionProfile::builder()
134+
.retry_policy(Arc::new(NoRetryPolicy))
135+
.build();
136+
137+
let session = SessionBuilder::new()
138+
.known_nodes([uri1, uri2, uri3])
139+
.default_execution_profile_handle(execution_profile.into_handle())
140+
.build()
141+
.await
142+
.unwrap();
143+
144+
// TODO: Everything should be fine
145+
assert!(session
146+
.query_unpaged("SELECT host_id FROM system.local", &[])
147+
.await
148+
.is_ok());
149+
150+
// TODO: Stop the nodes
151+
152+
// TODO: Check the connection -> fails to execute query
153+
assert_matches!(
154+
session
155+
.query_unpaged("SELECT host_id FROM system.local", &[])
156+
.await,
157+
Err(ExecutionError::ConnectionPoolError(
158+
ConnectionPoolError::Broken {
159+
last_connection_error: ConnectionError::BrokenConnection(_),
160+
}
161+
))
162+
);
163+
164+
assert!(true);
165+
}

scylla/tests/common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub(crate) mod retry_policy;
2+
pub(crate) mod utils;

scylla/tests/common/retry_policy.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use scylla::policies::retry::{RequestInfo, RetryDecision, RetryPolicy, RetrySession};
2+
use std::fmt::Debug;
3+
4+
#[derive(Debug, Clone, Default)]
5+
#[allow(dead_code)]
6+
pub(crate) struct NoRetryPolicy;
7+
8+
#[derive(Debug, Clone, Default)]
9+
#[allow(dead_code)]
10+
pub(crate) struct NoRetrySession;
11+
12+
impl RetryPolicy for NoRetryPolicy {
13+
fn new_session(&self) -> Box<dyn RetrySession> {
14+
Box::new(NoRetrySession)
15+
}
16+
}
17+
18+
impl RetrySession for NoRetrySession {
19+
fn decide_should_retry(&mut self, _request_info: RequestInfo) -> RetryDecision {
20+
RetryDecision::DontRetry
21+
}
22+
23+
fn reset(&mut self) { *self = Default::default() }
24+
}

scylla/tests/integration/utils.rs renamed to scylla/tests/common/utils.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ pub(crate) fn setup_tracing() {
2929
.try_init();
3030
}
3131

32+
#[allow(dead_code)]
3233
static UNIQUE_COUNTER: AtomicUsize = AtomicUsize::new(0);
3334

35+
#[allow(dead_code)]
3436
pub(crate) fn unique_keyspace_name() -> String {
3537
let cnt = UNIQUE_COUNTER.fetch_add(1, Ordering::SeqCst);
3638
let name = format!(
@@ -45,6 +47,7 @@ pub(crate) fn unique_keyspace_name() -> String {
4547
name
4648
}
4749

50+
#[allow(dead_code)]
4851
pub(crate) async fn test_with_3_node_cluster<F, Fut>(
4952
shard_awareness: ShardAwareness,
5053
test: F,
@@ -95,6 +98,7 @@ where
9598
running_proxy.finish().await
9699
}
97100

101+
#[allow(dead_code)]
98102
pub(crate) async fn supports_feature(session: &Session, feature: &str) -> bool {
99103
// Cassandra doesn't have a concept of features, so first detect
100104
// if there is the `supported_features` column in system.local
@@ -127,13 +131,15 @@ pub(crate) async fn supports_feature(session: &Session, feature: &str) -> bool {
127131
.any(|f| f == feature)
128132
}
129133

134+
#[allow(dead_code)]
130135
pub(crate) async fn scylla_supports_tablets(session: &Session) -> bool {
131136
supports_feature(session, "TABLETS").await
132137
}
133138

134139
// Creates a generic session builder based on conditional compilation configuration
135140
// For SessionBuilder of DefaultMode type, adds localhost to known hosts, as all of the tests
136141
// connect to localhost.
142+
#[allow(dead_code)]
137143
pub(crate) fn create_new_session_builder() -> GenericSessionBuilder<impl SessionBuilderKind> {
138144
let session_builder = {
139145
#[cfg(not(scylla_cloud_tests))]
@@ -168,6 +174,7 @@ pub(crate) fn create_new_session_builder() -> GenericSessionBuilder<impl Session
168174

169175
// Shorthands for better readability.
170176
// Copied from Scylla because we don't want to make it public there.
177+
#[allow(dead_code)]
171178
pub(crate) trait DeserializeOwnedValue:
172179
for<'frame, 'metadata> DeserializeValue<'frame, 'metadata>
173180
{
@@ -182,6 +189,7 @@ impl<T> DeserializeOwnedValue for T where
182189
// This is to make sure that all DDL queries land on the same node,
183190
// to prevent errors from concurrent DDL queries executed on different nodes.
184191
#[derive(Debug)]
192+
#[allow(dead_code)]
185193
struct SchemaQueriesLBP;
186194

187195
impl LoadBalancingPolicy for SchemaQueriesLBP {
@@ -210,6 +218,7 @@ impl LoadBalancingPolicy for SchemaQueriesLBP {
210218
}
211219

212220
#[derive(Debug, Default)]
221+
#[allow(dead_code)]
213222
struct SchemaQueriesRetrySession {
214223
count: usize,
215224
}
@@ -242,14 +251,16 @@ impl RetrySession for SchemaQueriesRetrySession {
242251
}
243252

244253
#[derive(Debug)]
254+
#[allow(dead_code)]
245255
struct SchemaQueriesRetryPolicy;
246256

247257
impl RetryPolicy for SchemaQueriesRetryPolicy {
248258
fn new_session(&self) -> Box<dyn RetrySession> {
249-
Box::new(SchemaQueriesRetrySession::default())
259+
Box::<SchemaQueriesRetrySession>::default()
250260
}
251261
}
252262

263+
#[allow(dead_code)]
253264
fn apply_ddl_lbp(query: &mut Query) {
254265
let policy = query
255266
.get_execution_profile_handle()
@@ -265,6 +276,7 @@ fn apply_ddl_lbp(query: &mut Query) {
265276
// we'll be able to do session.ddl(...) instead of perform_ddl(&session, ...)
266277
// or something like that.
267278
#[async_trait::async_trait]
279+
#[allow(dead_code)]
268280
pub(crate) trait PerformDDL {
269281
async fn ddl(&self, query: impl Into<Query> + Send) -> Result<(), ExecutionError>;
270282
}

scylla/tests/integration/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ mod history;
1010
mod hygiene;
1111
mod large_batch_statements;
1212
mod lwt_optimisation;
13-
mod new_session;
1413
mod retries;
1514
mod self_identity;
1615
mod shards;
1716
mod silent_prepare_batch;
1817
mod silent_prepare_query;
1918
mod skip_metadata_optimization;
2019
mod tablets;
21-
pub(crate) mod utils;
20+
#[path = "../common/utils.rs"]
21+
mod utils;

scylla/tests/integration/new_session.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)