Skip to content

Commit 6649f5d

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

File tree

6 files changed

+196
-41
lines changed

6 files changed

+196
-41
lines changed

scylla/tests/ccm_integration/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mod new_session;
2+
#[path = "../common/retry_policy.rs"]
3+
mod retry_policy;
4+
5+
#[path = "../common/utils.rs"]
6+
mod utils;
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::retry_policy::NoRetryPolicy;
9+
use crate::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::default()))
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::default()))
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::default()))
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/retry_policy.rs

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct SchemaQueriesRetryPolicy;
246246

247247
impl RetryPolicy for SchemaQueriesRetryPolicy {
248248
fn new_session(&self) -> Box<dyn RetrySession> {
249-
Box::new(SchemaQueriesRetrySession::default())
249+
Box::<SchemaQueriesRetrySession>::default()
250250
}
251251
}
252252

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)