|
| 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 | +} |
0 commit comments