forked from scylladb/scylla-rust-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_session.rs
98 lines (82 loc) · 3.22 KB
/
new_session.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use std::net::Ipv4Addr;
use crate::utils::{create_new_session_builder, find_local_ip_for_destination, setup_tracing};
use assert_matches::assert_matches;
use scylla::client::session_builder::SessionBuilder;
use scylla::errors::{ConnectionError, ConnectionPoolError, MetadataError, NewSessionError};
#[cfg_attr(scylla_cloud_tests, ignore)]
#[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();
session
.query_unpaged("SELECT host_id FROM system.local WHERE key='local'", &[])
.await
.unwrap();
}
#[cfg_attr(scylla_cloud_tests, ignore)]
#[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(_))
);
}
/// This test assumes that there is no interface configured on 1.1.1.1 address.
/// This should be true for most standard setups.
/// It is based on https://github.com/scylladb/cpp-rust-driver/blob/v0.3.0/tests/src/integration/tests/test_control_connection.cpp#L203-L216.
#[tokio::test]
async fn invalid_local_ip_address() {
setup_tracing();
let session_builder =
create_new_session_builder().local_ip_address(Some(Ipv4Addr::new(1, 1, 1, 1)));
let session_result = session_builder.build().await;
match session_result {
Err(NewSessionError::MetadataError(MetadataError::ConnectionPoolError(
ConnectionPoolError::Broken {
last_connection_error: ConnectionError::IoError(err),
},
))) => {
assert_matches!(err.kind(), std::io::ErrorKind::AddrNotAvailable)
}
_ => panic!("Expected EADDRNOTAVAIL error"),
}
}
#[tokio::test]
async fn valid_local_ip_address() {
setup_tracing();
// Create a dummy session to retrieve the address of one of the nodes.
// We could obviously use SCYLLA_URI environment variable, but this would work
// only for non-cloud cluster in CI.
let dummy_session = create_new_session_builder().build().await.unwrap();
let first_node_ip = dummy_session
.get_cluster_state()
.get_nodes_info()
.first()
.unwrap()
.address
.ip();
let local_ip_address =
find_local_ip_for_destination(first_node_ip).expect("Failed to find local IP");
tracing::info!(
"Found local IP address {} for destination address {}",
local_ip_address,
first_node_ip,
);
let session_builder = create_new_session_builder().local_ip_address(Some(local_ip_address));
let session = session_builder.build().await.unwrap();
session
.query_unpaged("SELECT host_id FROM system.local WHERE key='local'", &[])
.await
.unwrap();
}