From 418f369231d05f7e4a8e914ff47024675f7d6e2d Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 1 Sep 2022 13:04:21 +1000 Subject: [PATCH] test_cluster_single_rack: split into v3 and v4 variants --- .../cassandra-cluster-tls/docker-compose.yml | 6 +- ...se.yml => docker-compose-cassandra-v3.yml} | 0 .../docker-compose-cassandra-v4.yml | 52 ++++ .../tests/cassandra_int_tests/cluster.rs | 149 ----------- .../cluster_single_rack_v3.rs | 107 ++++++++ .../cluster_single_rack_v4.rs | 233 ++++++++++++++++++ .../tests/cassandra_int_tests/mod.rs | 57 ++++- test-helpers/src/docker_compose.rs | 3 +- 8 files changed, 447 insertions(+), 160 deletions(-) rename shotover-proxy/example-configs/cassandra-cluster/{docker-compose.yml => docker-compose-cassandra-v3.yml} (100%) create mode 100644 shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml create mode 100644 shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v3.rs create mode 100644 shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs diff --git a/shotover-proxy/example-configs/cassandra-cluster-tls/docker-compose.yml b/shotover-proxy/example-configs/cassandra-cluster-tls/docker-compose.yml index 4f8050f3e..13bc0f042 100644 --- a/shotover-proxy/example-configs/cassandra-cluster-tls/docker-compose.yml +++ b/shotover-proxy/example-configs/cassandra-cluster-tls/docker-compose.yml @@ -11,7 +11,7 @@ networks: services: cassandra-one: - image: bitnami/cassandra:3.11 + image: bitnami/cassandra:4.0.6 networks: cluster_subnet: ipv4_address: 172.16.1.2 @@ -43,7 +43,7 @@ services: - ../cassandra-tls/certs/truststore.p12:/bitnami/cassandra/secrets/truststore cassandra-two: - image: bitnami/cassandra:3.11 + image: bitnami/cassandra:4.0.6 networks: cluster_subnet: ipv4_address: 172.16.1.3 @@ -52,7 +52,7 @@ services: volumes: *volumes cassandra-three: - image: bitnami/cassandra:3.11 + image: bitnami/cassandra:4.0.6 networks: cluster_subnet: ipv4_address: 172.16.1.4 diff --git a/shotover-proxy/example-configs/cassandra-cluster/docker-compose.yml b/shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v3.yml similarity index 100% rename from shotover-proxy/example-configs/cassandra-cluster/docker-compose.yml rename to shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v3.yml diff --git a/shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml b/shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml new file mode 100644 index 000000000..4dd636ce9 --- /dev/null +++ b/shotover-proxy/example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml @@ -0,0 +1,52 @@ +version: "3.3" +networks: + cluster_subnet: + name: cluster_subnet + driver: bridge + ipam: + driver: default + config: + - subnet: 172.16.1.0/24 + gateway: 172.16.1.1 + +services: + cassandra-one: + image: bitnami/cassandra:4.0.6 + networks: + cluster_subnet: + ipv4_address: 172.16.1.2 + healthcheck: + &healthcheck + test: [ "CMD", "cqlsh", "-e", "describe keyspaces" ] + interval: 5s + timeout: 5s + retries: 60 + environment: + &environment + CASSANDRA_SEEDS: "cassandra-one,cassandra-two" + CASSANDRA_CLUSTER_NAME: TestCluster + CASSANDRA_DC: dc1 + CASSANDRA_RACK: rack1 + CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch + CASSANDRA_NUM_TOKENS: 128 + MAX_HEAP_SIZE: "400M" + MIN_HEAP_SIZE: "400M" + HEAP_NEWSIZE: "48M" + CASSANDRA_ENABLE_SCRIPTED_USER_DEFINED_FUNCTIONS: "true" + CASSANDRA_ENABLE_USER_DEFINED_FUNCTIONS: "true" + + cassandra-two: + image: bitnami/cassandra:4.0.6 + networks: + cluster_subnet: + ipv4_address: 172.16.1.3 + healthcheck: *healthcheck + environment: *environment + + cassandra-three: + image: bitnami/cassandra:4.0.6 + networks: + cluster_subnet: + ipv4_address: 172.16.1.4 + healthcheck: *healthcheck + environment: *environment diff --git a/shotover-proxy/tests/cassandra_int_tests/cluster.rs b/shotover-proxy/tests/cassandra_int_tests/cluster.rs index 8e4e4c319..03166bb09 100644 --- a/shotover-proxy/tests/cassandra_int_tests/cluster.rs +++ b/shotover-proxy/tests/cassandra_int_tests/cluster.rs @@ -1,4 +1,3 @@ -use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue}; use cassandra_protocol::frame::Version; use shotover_proxy::frame::{CassandraFrame, CassandraOperation, Frame}; use shotover_proxy::message::Message; @@ -8,157 +7,9 @@ use shotover_proxy::transforms::cassandra::sink_cluster::{ node::{CassandraNode, ConnectionFactory}, TaskConnectionInfo, }; -use std::net::IpAddr; use std::sync::Arc; use tokio::sync::{mpsc, RwLock}; -async fn test_rewrite_system_peers(connection: &CassandraConnection) { - let all_columns = "peer, data_center, host_id, preferred_ip, rack, release_version, rpc_address, schema_version, tokens"; - assert_query_result(connection, "SELECT * FROM system.peers;", &[]).await; - assert_query_result( - connection, - &format!("SELECT {all_columns} FROM system.peers;"), - &[], - ) - .await; - assert_query_result( - connection, - &format!("SELECT {all_columns}, {all_columns} FROM system.peers;"), - &[], - ) - .await; -} -async fn test_rewrite_system_peers_dummy_peers(connection: &CassandraConnection) { - let star_results1 = [ - ResultValue::Inet("127.0.0.1".parse().unwrap()), - ResultValue::Varchar("dc1".into()), - ResultValue::Uuid("3c3c4e2d-ba74-4f76-b52e-fb5bcee6a9f4".parse().unwrap()), - ResultValue::Inet("255.255.255.255".into()), - ResultValue::Varchar("rack1".into()), - ResultValue::Varchar("3.11.13".into()), - ResultValue::Inet("255.255.255.255".into()), - // schema_version is non deterministic so we cant assert on it. - ResultValue::Any, - // Unfortunately token generation appears to be non-deterministic but we can at least assert that - // there are 128 tokens per node - ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), - ]; - let star_results2 = [ - ResultValue::Inet("127.0.0.1".parse().unwrap()), - ResultValue::Varchar("dc1".into()), - ResultValue::Uuid("fa74d7ec-1223-472b-97de-04a32ccdb70b".parse().unwrap()), - ResultValue::Inet("255.255.255.255".into()), - ResultValue::Varchar("rack1".into()), - ResultValue::Varchar("3.11.13".into()), - ResultValue::Inet("255.255.255.255".into()), - // schema_version is non deterministic so we cant assert on it. - ResultValue::Any, - // Unfortunately token generation appears to be non-deterministic but we can at least assert that - // there are 128 tokens per node - ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), - ]; - - let all_columns = "peer, data_center, host_id, preferred_ip, rack, release_version, rpc_address, schema_version, tokens"; - assert_query_result( - connection, - "SELECT * FROM system.peers;", - &[&star_results1, &star_results2], - ) - .await; - assert_query_result( - connection, - &format!("SELECT {all_columns} FROM system.peers;"), - &[&star_results1, &star_results2], - ) - .await; - assert_query_result( - connection, - &format!("SELECT {all_columns}, {all_columns} FROM system.peers;"), - &[ - &[star_results1.as_slice(), star_results1.as_slice()].concat(), - &[star_results2.as_slice(), star_results2.as_slice()].concat(), - ], - ) - .await; -} - -async fn test_rewrite_system_local(connection: &CassandraConnection) { - let star_results = [ - ResultValue::Varchar("local".into()), - ResultValue::Varchar("COMPLETED".into()), - ResultValue::Inet("127.0.0.1".parse().unwrap()), - ResultValue::Varchar("TestCluster".into()), - ResultValue::Varchar("3.4.4".into()), - ResultValue::Varchar("dc1".into()), - // gossip_generation is non deterministic cant assert on it - ResultValue::Any, - ResultValue::Uuid("2dd022d6-2937-4754-89d6-02d2933a8f7a".parse().unwrap()), - ResultValue::Inet("127.0.0.1".parse().unwrap()), - ResultValue::Varchar("4".into()), - ResultValue::Varchar("org.apache.cassandra.dht.Murmur3Partitioner".into()), - ResultValue::Varchar("rack1".into()), - ResultValue::Varchar("3.11.13".into()), - ResultValue::Inet("0.0.0.0".parse().unwrap()), - // schema_version is non deterministic so we cant assert on it. - ResultValue::Any, - // thrift_version isnt used anymore so I dont really care what it maps to - ResultValue::Any, - // Unfortunately token generation appears to be non-deterministic but we can at least assert that - // there are 128 tokens per node - ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), - ResultValue::Map(vec![]), - ]; - - let all_columns = - "key, bootstrapped, broadcast_address, cluster_name, cql_version, data_center, - gossip_generation, host_id, listen_address, native_protocol_version, partitioner, rack, - release_version, rpc_address, schema_version, thrift_version, tokens, truncated_at"; - - assert_query_result(connection, "SELECT * FROM system.local;", &[&star_results]).await; - assert_query_result( - connection, - &format!("SELECT {all_columns} FROM system.local;"), - &[&star_results], - ) - .await; - assert_query_result( - connection, - &format!("SELECT {all_columns}, {all_columns} FROM system.local;"), - &[&[star_results.as_slice(), star_results.as_slice()].concat()], - ) - .await; -} - -pub async fn test(connection: &CassandraConnection) { - test_rewrite_system_local(connection).await; - test_rewrite_system_peers(connection).await; -} - -pub async fn test_dummy_peers(connection: &CassandraConnection) { - test_rewrite_system_local(connection).await; - test_rewrite_system_peers_dummy_peers(connection).await; -} - -pub async fn test_topology_task(ca_path: Option<&str>) { - let nodes = run_topology_task(ca_path).await; - - assert_eq!(nodes.len(), 3); - let mut possible_addresses: Vec = vec![ - "172.16.1.2".parse().unwrap(), - "172.16.1.3".parse().unwrap(), - "172.16.1.4".parse().unwrap(), - ]; - for node in &nodes { - let address_index = possible_addresses - .iter() - .position(|x| *x == node.address) - .expect("Node did not contain a unique expected address"); - possible_addresses.remove(address_index); - - assert_eq!(node.rack, "rack1"); - assert_eq!(node._tokens.len(), 128); - } -} pub async fn run_topology_task(ca_path: Option<&str>) -> Vec { let nodes_shared = Arc::new(RwLock::new(vec![])); let (task_handshake_tx, task_handshake_rx) = mpsc::channel(1); diff --git a/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v3.rs b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v3.rs new file mode 100644 index 000000000..b07f78b0d --- /dev/null +++ b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v3.rs @@ -0,0 +1,107 @@ +use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue}; + +async fn test_rewrite_system_peers_dummy_peers(connection: &CassandraConnection) { + let star_results1 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("3c3c4e2d-ba74-4f76-b52e-fb5bcee6a9f4".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("3.11.13".into()), + ResultValue::Inet("255.255.255.255".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + let star_results2 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("fa74d7ec-1223-472b-97de-04a32ccdb70b".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("3.11.13".into()), + ResultValue::Inet("255.255.255.255".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + + let all_columns = "peer, data_center, host_id, preferred_ip, rack, release_version, rpc_address, schema_version, tokens"; + assert_query_result( + connection, + "SELECT * FROM system.peers;", + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.peers;"), + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.peers;"), + &[ + &[star_results1.as_slice(), star_results1.as_slice()].concat(), + &[star_results2.as_slice(), star_results2.as_slice()].concat(), + ], + ) + .await; +} + +async fn test_rewrite_system_local(connection: &CassandraConnection) { + let star_results = [ + ResultValue::Varchar("local".into()), + ResultValue::Varchar("COMPLETED".into()), + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("TestCluster".into()), + ResultValue::Varchar("3.4.4".into()), + ResultValue::Varchar("dc1".into()), + // gossip_generation is non deterministic cant assert on it + ResultValue::Any, + ResultValue::Uuid("2dd022d6-2937-4754-89d6-02d2933a8f7a".parse().unwrap()), + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("4".into()), + ResultValue::Varchar("org.apache.cassandra.dht.Murmur3Partitioner".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("3.11.13".into()), + ResultValue::Inet("0.0.0.0".parse().unwrap()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // thrift_version isnt used anymore so I dont really care what it maps to + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ResultValue::Map(vec![]), + ]; + + let all_columns = + "key, bootstrapped, broadcast_address, cluster_name, cql_version, data_center, + gossip_generation, host_id, listen_address, native_protocol_version, partitioner, rack, + release_version, rpc_address, schema_version, thrift_version, tokens, truncated_at"; + + assert_query_result(connection, "SELECT * FROM system.local;", &[&star_results]).await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.local;"), + &[&star_results], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.local;"), + &[&[star_results.as_slice(), star_results.as_slice()].concat()], + ) + .await; +} + +pub async fn test_dummy_peers(connection: &CassandraConnection) { + test_rewrite_system_local(connection).await; + test_rewrite_system_peers_dummy_peers(connection).await; +} diff --git a/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs new file mode 100644 index 000000000..2801b4d56 --- /dev/null +++ b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs @@ -0,0 +1,233 @@ +use crate::cassandra_int_tests::cluster::run_topology_task; +use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue}; +use std::net::IpAddr; + +async fn test_rewrite_system_peers(connection: &CassandraConnection) { + let all_columns = "peer, data_center, host_id, preferred_ip, rack, release_version, rpc_address, schema_version, tokens"; + assert_query_result(connection, "SELECT * FROM system.peers;", &[]).await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.peers;"), + &[], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.peers;"), + &[], + ) + .await; +} + +async fn test_rewrite_system_peers_v2(connection: &CassandraConnection) { + let all_columns = "peer, peer_port, data_center, host_id, native_address, native_port, preferred_ip, preferred_port, rack, release_version, schema_version, tokens"; + assert_query_result(connection, "SELECT * FROM system.peers_v2;", &[]).await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.peers_v2;"), + &[], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.peers_v2;"), + &[], + ) + .await; +} + +async fn test_rewrite_system_peers_dummy_peers(connection: &CassandraConnection) { + let star_results1 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("3c3c4e2d-ba74-4f76-b52e-fb5bcee6a9f4".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("4.0.6".into()), + ResultValue::Inet("255.255.255.255".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + let star_results2 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("fa74d7ec-1223-472b-97de-04a32ccdb70b".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("4.0.6".into()), + ResultValue::Inet("255.255.255.255".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + + let all_columns = "peer, data_center, host_id, preferred_ip, rack, release_version, rpc_address, schema_version, tokens"; + assert_query_result( + connection, + "SELECT * FROM system.peers;", + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.peers;"), + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.peers;"), + &[ + &[star_results1.as_slice(), star_results1.as_slice()].concat(), + &[star_results2.as_slice(), star_results2.as_slice()].concat(), + ], + ) + .await; +} + +async fn test_rewrite_system_peers_v2_dummy_peers(connection: &CassandraConnection) { + let star_results1 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Int(9042), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("3c3c4e2d-ba74-4f76-b52e-fb5bcee6a9f4".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Int(-1), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Int(-1), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("4.0.6".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + let star_results2 = [ + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Int(9042), + ResultValue::Varchar("dc1".into()), + ResultValue::Uuid("fa74d7ec-1223-472b-97de-04a32ccdb70b".parse().unwrap()), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Int(-1), + ResultValue::Inet("255.255.255.255".into()), + ResultValue::Int(-1), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("4.0.6".into()), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + ]; + + let all_columns = "peer, peer_port, data_center, host_id, native_address, native_port, preferred_ip, preferred_port, rack, release_version, schema_version, tokens"; + assert_query_result( + connection, + "SELECT * FROM system.peers_v2;", + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.peers_v2;"), + &[&star_results1, &star_results2], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.peers_v2;"), + &[ + &[star_results1.as_slice(), star_results1.as_slice()].concat(), + &[star_results2.as_slice(), star_results2.as_slice()].concat(), + ], + ) + .await; +} + +async fn test_rewrite_system_local(connection: &CassandraConnection) { + let star_results = [ + ResultValue::Varchar("local".into()), + ResultValue::Varchar("COMPLETED".into()), + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Int(7000), + ResultValue::Varchar("TestCluster".into()), + ResultValue::Varchar("3.4.5".into()), + ResultValue::Varchar("dc1".into()), + // gossip_generation is non deterministic cant assert on it + ResultValue::Any, + ResultValue::Uuid("2dd022d6-2937-4754-89d6-02d2933a8f7a".parse().unwrap()), + ResultValue::Inet("127.0.0.1".parse().unwrap()), + ResultValue::Int(7000), + ResultValue::Varchar("5".into()), + ResultValue::Varchar("org.apache.cassandra.dht.Murmur3Partitioner".into()), + ResultValue::Varchar("rack1".into()), + ResultValue::Varchar("4.0.6".into()), + ResultValue::Inet("0.0.0.0".parse().unwrap()), + ResultValue::Int(9042), + // schema_version is non deterministic so we cant assert on it. + ResultValue::Any, + // Unfortunately token generation appears to be non-deterministic but we can at least assert that + // there are 128 tokens per node + ResultValue::Set(std::iter::repeat(ResultValue::Any).take(3 * 128).collect()), + // truncated_at is non deterministic so we cant assert on it. + ResultValue::Any, + ]; + + let all_columns = + "key, bootstrapped, broadcast_address, broadcast_port, cluster_name, cql_version, data_center, + gossip_generation, host_id, listen_address, listen_port, native_protocol_version, partitioner, rack, + release_version, rpc_address, rpc_port, schema_version, tokens, truncated_at"; + + assert_query_result(connection, "SELECT * FROM system.local;", &[&star_results]).await; + assert_query_result( + connection, + &format!("SELECT {all_columns} FROM system.local;"), + &[&star_results], + ) + .await; + assert_query_result( + connection, + &format!("SELECT {all_columns}, {all_columns} FROM system.local;"), + &[&[star_results.as_slice(), star_results.as_slice()].concat()], + ) + .await; +} + +pub async fn test(connection: &CassandraConnection) { + test_rewrite_system_local(connection).await; + test_rewrite_system_peers(connection).await; + test_rewrite_system_peers_v2(connection).await; +} + +pub async fn test_dummy_peers(connection: &CassandraConnection) { + test_rewrite_system_local(connection).await; + test_rewrite_system_peers_dummy_peers(connection).await; + test_rewrite_system_peers_v2_dummy_peers(connection).await; +} + +pub async fn test_topology_task(ca_path: Option<&str>) { + let nodes = run_topology_task(ca_path).await; + + assert_eq!(nodes.len(), 3); + let mut possible_addresses: Vec = vec![ + "172.16.1.2".parse().unwrap(), + "172.16.1.3".parse().unwrap(), + "172.16.1.4".parse().unwrap(), + ]; + for node in &nodes { + let address_index = possible_addresses + .iter() + .position(|x| *x == node.address) + .expect("Node did not contain a unique expected address"); + possible_addresses.remove(address_index); + + assert_eq!(node.rack, "rack1"); + assert_eq!(node._tokens.len(), 128); + } +} diff --git a/shotover-proxy/tests/cassandra_int_tests/mod.rs b/shotover-proxy/tests/cassandra_int_tests/mod.rs index 5b770931d..4d8f16607 100644 --- a/shotover-proxy/tests/cassandra_int_tests/mod.rs +++ b/shotover-proxy/tests/cassandra_int_tests/mod.rs @@ -19,6 +19,8 @@ mod batch_statements; mod cache; mod cluster; mod cluster_multi_rack; +mod cluster_single_rack_v3; +mod cluster_single_rack_v4; mod collections; mod functions; mod keyspace; @@ -88,8 +90,49 @@ async fn test_source_tls_and_single_tls() { #[tokio::test(flavor = "multi_thread")] #[serial] -async fn test_cluster_single_rack() { - let _compose = DockerCompose::new("example-configs/cassandra-cluster/docker-compose.yml"); +async fn test_cluster_single_rack_v3() { + let _compose = + DockerCompose::new("example-configs/cassandra-cluster/docker-compose-cassandra-v3.yml"); + + { + let shotover_manager = ShotoverManager::from_topology_file( + "example-configs/cassandra-cluster/topology-dummy-peers.yaml", + ); + + let mut connection1 = shotover_manager + .cassandra_connection("127.0.0.1", 9042) + .await; + connection1 + .enable_schema_awaiter("172.16.1.2:9042", None) + .await; + keyspace::test(&connection1).await; + table::test(&connection1).await; + udt::test(&connection1).await; + native_types::test(&connection1).await; + collections::test(&connection1).await; + functions::test(&connection1).await; + prepared_statements::test(&connection1).await; + batch_statements::test(&connection1).await; + cluster_single_rack_v3::test_dummy_peers(&connection1).await; + + //Check for bugs in cross connection state + let mut connection2 = shotover_manager + .cassandra_connection("127.0.0.1", 9042) + .await; + connection2 + .enable_schema_awaiter("172.16.1.2:9042", None) + .await; + native_types::test(&connection2).await; + } + + cluster_single_rack_v4::test_topology_task(None).await; +} + +#[tokio::test(flavor = "multi_thread")] +#[serial] +async fn test_cluster_single_rack_v4() { + let _compose = + DockerCompose::new("example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml"); { let shotover_manager = @@ -109,7 +152,7 @@ async fn test_cluster_single_rack() { functions::test(&connection1).await; prepared_statements::test(&connection1).await; batch_statements::test(&connection1).await; - cluster::test(&connection1).await; + cluster_single_rack_v4::test(&connection1).await; //Check for bugs in cross connection state let mut connection2 = shotover_manager @@ -132,10 +175,10 @@ async fn test_cluster_single_rack() { connection .enable_schema_awaiter("172.16.1.2:9042", None) .await; - cluster::test_dummy_peers(&connection).await; + cluster_single_rack_v4::test_dummy_peers(&connection).await; } - cluster::test_topology_task(None).await; + cluster_single_rack_v4::test_topology_task(None).await; } #[tokio::test(flavor = "multi_thread")] @@ -220,10 +263,10 @@ async fn test_source_tls_and_cluster_tls() { collections::test(&connection).await; prepared_statements::test(&connection).await; batch_statements::test(&connection).await; - cluster::test(&connection).await; + cluster_single_rack_v4::test(&connection).await; } - cluster::test_topology_task(Some(ca_cert)).await; + cluster_single_rack_v4::test_topology_task(Some(ca_cert)).await; } #[tokio::test(flavor = "multi_thread")] diff --git a/test-helpers/src/docker_compose.rs b/test-helpers/src/docker_compose.rs index 8fdbcc25a..094a01703 100644 --- a/test-helpers/src/docker_compose.rs +++ b/test-helpers/src/docker_compose.rs @@ -126,7 +126,8 @@ impl DockerCompose { self.wait_for_log("Startup complete", 2, 110) } "example-configs-docker/cassandra-peers-rewrite/docker-compose.yml" - | "example-configs/cassandra-cluster/docker-compose.yml" + | "example-configs/cassandra-cluster/docker-compose-cassandra-v4.yml" + | "example-configs/cassandra-cluster/docker-compose-cassandra-v3.yml" | "example-configs/cassandra-cluster-multi-rack/docker-compose.yml" | "example-configs/cassandra-cluster-tls/docker-compose.yml" => { self.wait_for_log("Startup complete", 3, 180)