-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dusan Malusev <dusan.malusev@scylladb.com>
- Loading branch information
1 parent
86efc40
commit 1764bfe
Showing
6 changed files
with
208 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mod new_session; | ||
#[path = "../common/retry_policy.rs"] | ||
mod retry_policy; | ||
|
||
#[path = "../common/utils.rs"] | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
use std::sync::Arc; | ||
use assert_matches::assert_matches; | ||
use scylla::client::execution_profile::ExecutionProfile; | ||
use scylla::client::session_builder::SessionBuilder; | ||
use scylla::errors::{ConnectionError, ConnectionPoolError, ExecutionError, NewSessionError}; | ||
use scylla::policies::retry::DefaultRetryPolicy; | ||
|
||
use crate::retry_policy::NoRetryPolicy; | ||
use crate::utils::setup_tracing; | ||
|
||
fn get_scylla() -> (String, String, String) { | ||
let uri1 = std::env::var("SCYLLA_URI1").unwrap_or_else(|_| "127.0.0.1:9042".to_string()); | ||
let uri2 = std::env::var("SCYLLA_URI2").unwrap_or_else(|_| "127.0.0.2:9042".to_string()); | ||
let uri3 = std::env::var("SCYLLA_URI3").unwrap_or_else(|_| "127.0.0.3:9042".to_string()); | ||
|
||
(uri1, uri2, uri3) | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn proceed_if_only_some_hostnames_are_invalid() { | ||
setup_tracing(); | ||
// on purpose left without port | ||
let uri1 = "scylladbisthefastestdb.invalid".to_owned(); | ||
// correctly provided port, but unknown domain | ||
let uri2 = "cassandrasuckssomuch.invalid:9042".to_owned(); | ||
let uri3 = std::env::var("SCYLLA_URI3").unwrap_or_else(|_| "127.0.0.3:9042".to_string()); | ||
|
||
let session = SessionBuilder::new() | ||
.known_nodes([uri1, uri2, uri3]) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
assert!(session | ||
.query_unpaged("SELECT host_id FROM system.local", &[]) | ||
.await | ||
.is_ok()); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn all_hostnames_invalid() { | ||
setup_tracing(); | ||
let uri = "cassandrasuckssomuch.invalid:9042".to_owned(); | ||
|
||
assert_matches!( | ||
SessionBuilder::new().known_node(uri).build().await, | ||
Err(NewSessionError::FailedToResolveAnyHostname(_)) | ||
); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn no_nodes_available_reconnection_enabled() { | ||
setup_tracing(); | ||
|
||
let execution_profile = ExecutionProfile::builder() | ||
.retry_policy(Arc::new(DefaultRetryPolicy::default())) | ||
.build(); | ||
|
||
assert!(SessionBuilder::new() | ||
.default_execution_profile_handle(execution_profile.into_handle()) | ||
.build() | ||
.await | ||
.is_ok()); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn no_nodes_available_reconnection_disabled() { | ||
setup_tracing(); | ||
// TODO: Replace with CCM | ||
let (uri1, uri2, uri3) = get_scylla(); | ||
|
||
let execution_profile = ExecutionProfile::builder() | ||
.retry_policy(Arc::new(NoRetryPolicy)) | ||
.build(); | ||
|
||
assert_matches!( | ||
SessionBuilder::new() | ||
.known_nodes([uri1, uri2, uri3]) | ||
.default_execution_profile_handle(execution_profile.into_handle()) | ||
.build() | ||
.await, | ||
Err(NewSessionError::FailedToResolveAnyHostname(_)) | ||
); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn no_nodes_available_reconnection_enabled_nodes_coming_back() { | ||
setup_tracing(); | ||
// TODO: Setup CCM | ||
|
||
let execution_profile = ExecutionProfile::builder() | ||
.retry_policy(Arc::new(DefaultRetryPolicy::default())) | ||
.build(); | ||
|
||
assert!(SessionBuilder::new() | ||
.default_execution_profile_handle(execution_profile.into_handle()) | ||
.build() | ||
.await | ||
.is_ok()); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn session_created_nodes_away_reconnection_enabled() { | ||
setup_tracing(); | ||
|
||
let execution_profile = ExecutionProfile::builder() | ||
.retry_policy(Arc::new(DefaultRetryPolicy::default())) | ||
.build(); | ||
|
||
let _session = SessionBuilder::new() | ||
.default_execution_profile_handle(execution_profile.into_handle()) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
assert!(true); | ||
} | ||
|
||
#[cfg(not(scylla_cloud_tests))] | ||
#[tokio::test] | ||
async fn session_created_nodes_away_reconnection_disabled() { | ||
setup_tracing(); | ||
|
||
// TODO: Replace with CCM | ||
let (uri1, uri2, uri3) = get_scylla(); | ||
|
||
let execution_profile = ExecutionProfile::builder() | ||
.retry_policy(Arc::new(NoRetryPolicy)) | ||
.build(); | ||
|
||
let session = SessionBuilder::new() | ||
.known_nodes([uri1, uri2, uri3]) | ||
.default_execution_profile_handle(execution_profile.into_handle()) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
// TODO: Everything should be fine | ||
assert!(session | ||
.query_unpaged("SELECT host_id FROM system.local", &[]) | ||
.await | ||
.is_ok()); | ||
|
||
// TODO: Stop the nodes | ||
|
||
// TODO: Check the connection -> fails to execute query | ||
assert_matches!( | ||
session | ||
.query_unpaged("SELECT host_id FROM system.local", &[]) | ||
.await, | ||
Err(ExecutionError::ConnectionPoolError( | ||
ConnectionPoolError::Broken { | ||
last_connection_error: ConnectionError::BrokenConnection(_), | ||
} | ||
)) | ||
); | ||
|
||
assert!(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use scylla::policies::retry::{RequestInfo, RetryDecision, RetryPolicy, RetrySession}; | ||
use std::fmt::Debug; | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) struct NoRetryPolicy; | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) struct NoRetrySession; | ||
|
||
|
||
impl RetryPolicy for NoRetryPolicy { | ||
fn new_session(&self) -> Box<dyn RetrySession> { | ||
Box::new(NoRetrySession) | ||
} | ||
} | ||
|
||
impl RetrySession for NoRetrySession { | ||
fn decide_should_retry(&mut self, _request_info: RequestInfo) -> RetryDecision { | ||
RetryDecision::DontRetry | ||
} | ||
|
||
fn reset(&mut self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.