From 333eb5e21b63a7d8462ca93150970b027c9d7bef Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Fri, 23 Feb 2024 16:49:16 +1100 Subject: [PATCH] Add kafka int tests with 2 racks --- shotover-proxy/tests/kafka_int_tests/mod.rs | 68 +++++++++++++-- .../docker-compose.yaml | 0 .../topology-single.yaml | 0 .../topology1.yaml | 0 .../topology2.yaml | 0 .../topology3.yaml | 0 .../kafka/cluster-2-racks/docker-compose.yaml | 86 +++++++++++++++++++ .../kafka/cluster-2-racks/topology-rack1.yaml | 12 +++ .../kafka/cluster-2-racks/topology-rack2.yaml | 12 +++ .../cluster-2-racks/topology-single.yaml | 10 +++ 10 files changed, 182 insertions(+), 6 deletions(-) rename shotover-proxy/tests/test-configs/kafka/{cluster => cluster-1-rack}/docker-compose.yaml (100%) rename shotover-proxy/tests/test-configs/kafka/{cluster => cluster-1-rack}/topology-single.yaml (100%) rename shotover-proxy/tests/test-configs/kafka/{cluster => cluster-1-rack}/topology1.yaml (100%) rename shotover-proxy/tests/test-configs/kafka/{cluster => cluster-1-rack}/topology2.yaml (100%) rename shotover-proxy/tests/test-configs/kafka/{cluster => cluster-1-rack}/topology3.yaml (100%) create mode 100644 shotover-proxy/tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml create mode 100644 shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack1.yaml create mode 100644 shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack2.yaml create mode 100644 shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-single.yaml diff --git a/shotover-proxy/tests/kafka_int_tests/mod.rs b/shotover-proxy/tests/kafka_int_tests/mod.rs index e6ff541f2..ecc8b647c 100644 --- a/shotover-proxy/tests/kafka_int_tests/mod.rs +++ b/shotover-proxy/tests/kafka_int_tests/mod.rs @@ -103,9 +103,10 @@ async fn passthrough_sasl_encode() { #[cfg(feature = "rdkafka-driver-tests")] #[tokio::test] -async fn cluster_single_shotover() { - let _docker_compose = docker_compose("tests/test-configs/kafka/cluster/docker-compose.yaml"); - let shotover = shotover_process("tests/test-configs/kafka/cluster/topology-single.yaml") +async fn cluster_1_rack_single_shotover() { + let _docker_compose = + docker_compose("tests/test-configs/kafka/cluster-1-rack/docker-compose.yaml"); + let shotover = shotover_process("tests/test-configs/kafka/cluster-1-rack/topology-single.yaml") .start() .await; @@ -122,13 +123,68 @@ async fn cluster_single_shotover() { #[cfg(feature = "rdkafka-driver-tests")] #[tokio::test] -async fn cluster_multi_shotover() { - let _docker_compose = docker_compose("tests/test-configs/kafka/cluster/docker-compose.yaml"); +async fn cluster_1_rack_multi_shotover() { + let _docker_compose = + docker_compose("tests/test-configs/kafka/cluster-1-rack/docker-compose.yaml"); let mut shotovers = vec![]; for i in 1..4 { shotovers.push( shotover_process(&format!( - "tests/test-configs/kafka/cluster/topology{i}.yaml" + "tests/test-configs/kafka/cluster-1-rack/topology{i}.yaml" + )) + .with_config(&format!( + "tests/test-configs/shotover-config/config{i}.yaml" + )) + .with_log_name(&format!("shotover{i}")) + .start() + .await, + ); + } + + let connection_builder = KafkaConnectionBuilder::new("127.0.0.1:9192"); + test_cases::basic(connection_builder).await; + + for shotover in shotovers { + tokio::time::timeout( + Duration::from_secs(10), + shotover.shutdown_and_then_consume_events(&[]), + ) + .await + .expect("Shotover did not shutdown within 10s"); + } +} + +#[cfg(feature = "rdkafka-driver-tests")] +#[tokio::test] +async fn cluster_2_racks_single_shotover() { + let _docker_compose = + docker_compose("tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml"); + let shotover = + shotover_process("tests/test-configs/kafka/cluster-2-racks/topology-single.yaml") + .start() + .await; + + let connection_builder = KafkaConnectionBuilder::new("127.0.0.1:9192"); + test_cases::basic(connection_builder).await; + + tokio::time::timeout( + Duration::from_secs(10), + shotover.shutdown_and_then_consume_events(&[]), + ) + .await + .expect("Shotover did not shutdown within 10s"); +} + +#[cfg(feature = "rdkafka-driver-tests")] +#[tokio::test] +async fn cluster_2_racks_multi_shotover() { + let _docker_compose = + docker_compose("tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml"); + let mut shotovers = vec![]; + for i in 1..3 { + shotovers.push( + shotover_process(&format!( + "tests/test-configs/kafka/cluster-2-racks/topology-rack{i}.yaml" )) .with_config(&format!( "tests/test-configs/shotover-config/config{i}.yaml" diff --git a/shotover-proxy/tests/test-configs/kafka/cluster/docker-compose.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-1-rack/docker-compose.yaml similarity index 100% rename from shotover-proxy/tests/test-configs/kafka/cluster/docker-compose.yaml rename to shotover-proxy/tests/test-configs/kafka/cluster-1-rack/docker-compose.yaml diff --git a/shotover-proxy/tests/test-configs/kafka/cluster/topology-single.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology-single.yaml similarity index 100% rename from shotover-proxy/tests/test-configs/kafka/cluster/topology-single.yaml rename to shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology-single.yaml diff --git a/shotover-proxy/tests/test-configs/kafka/cluster/topology1.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology1.yaml similarity index 100% rename from shotover-proxy/tests/test-configs/kafka/cluster/topology1.yaml rename to shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology1.yaml diff --git a/shotover-proxy/tests/test-configs/kafka/cluster/topology2.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology2.yaml similarity index 100% rename from shotover-proxy/tests/test-configs/kafka/cluster/topology2.yaml rename to shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology2.yaml diff --git a/shotover-proxy/tests/test-configs/kafka/cluster/topology3.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology3.yaml similarity index 100% rename from shotover-proxy/tests/test-configs/kafka/cluster/topology3.yaml rename to shotover-proxy/tests/test-configs/kafka/cluster-1-rack/topology3.yaml diff --git a/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml new file mode 100644 index 000000000..c82bd9101 --- /dev/null +++ b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/docker-compose.yaml @@ -0,0 +1,86 @@ +version: "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: + kafka0: + image: &image 'bitnami/kafka:3.6.1-debian-11-r24' + networks: + cluster_subnet: + ipv4_address: 172.16.1.2 + environment: &environment + KAFKA_CFG_LISTENERS: "BROKER://:9092,CONTROLLER://:9093" + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.2:9092" + KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,BROKER:PLAINTEXT" + KAFKA_CFG_INTER_BROKER_LISTENER_NAME: "BROKER" + KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER" + KAFKA_CFG_PROCESS_ROLES: "controller,broker" + KAFKA_KRAFT_CLUSTER_ID: "abcdefghijklmnopqrstuv" + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka0:9093,1@kafka1:9093,2@kafka2:9093,3@kafka3:9093,4@kafka4:9093,5@kafka5:9093" + KAFKA_CFG_NODE_ID: 0 + KAFKA_CFG_BROKER_RACK: "rack1" + ALLOW_PLAINTEXT_LISTENER: "yes" + volumes: &volumes + - type: tmpfs + target: /bitnami/kafka + kafka1: + image: *image + networks: + cluster_subnet: + ipv4_address: 172.16.1.3 + environment: + <<: *environment + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.3:9092" + KAFKA_CFG_NODE_ID: 1 + KAFKA_CFG_BROKER_RACK: "rack1" + volumes: *volumes + kafka2: + image: *image + networks: + cluster_subnet: + ipv4_address: 172.16.1.4 + environment: + <<: *environment + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.4:9092" + KAFKA_CFG_NODE_ID: 2 + KAFKA_CFG_BROKER_RACK: "rack1" + volumes: *volumes + kafka3: + image: *image + networks: + cluster_subnet: + ipv4_address: 172.16.1.5 + environment: + <<: *environment + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.5:9092" + KAFKA_CFG_NODE_ID: 3 + KAFKA_CFG_BROKER_RACK: "rack2" + volumes: *volumes + kafka4: + image: *image + networks: + cluster_subnet: + ipv4_address: 172.16.1.6 + environment: + <<: *environment + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.6:9092" + KAFKA_CFG_NODE_ID: 4 + KAFKA_CFG_BROKER_RACK: "rack2" + volumes: *volumes + kafka5: + image: *image + networks: + cluster_subnet: + ipv4_address: 172.16.1.7 + environment: + <<: *environment + KAFKA_CFG_ADVERTISED_LISTENERS: "BROKER://172.16.1.7:9092" + KAFKA_CFG_NODE_ID: 5 + KAFKA_CFG_BROKER_RACK: "rack2" + volumes: *volumes diff --git a/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack1.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack1.yaml new file mode 100644 index 000000000..440ba2f13 --- /dev/null +++ b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack1.yaml @@ -0,0 +1,12 @@ +--- +sources: + - Kafka: + name: "kafka" + listen_addr: "127.0.0.1:9191" + chain: + - KafkaSinkCluster: + shotover_nodes: + - "127.0.0.1:9191" + - "127.0.0.1:9192" + first_contact_points: ["172.16.1.2:9092"] + connect_timeout_ms: 3000 diff --git a/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack2.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack2.yaml new file mode 100644 index 000000000..ef4234294 --- /dev/null +++ b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-rack2.yaml @@ -0,0 +1,12 @@ +--- +sources: + - Kafka: + name: "kafka" + listen_addr: "127.0.0.1:9192" + chain: + - KafkaSinkCluster: + shotover_nodes: + - "127.0.0.1:9191" + - "127.0.0.1:9192" + first_contact_points: ["172.16.1.5:9092"] + connect_timeout_ms: 3000 diff --git a/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-single.yaml b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-single.yaml new file mode 100644 index 000000000..d38206e7f --- /dev/null +++ b/shotover-proxy/tests/test-configs/kafka/cluster-2-racks/topology-single.yaml @@ -0,0 +1,10 @@ +--- +sources: + - Kafka: + name: "kafka" + listen_addr: "127.0.0.1:9192" + chain: + - KafkaSinkCluster: + shotover_nodes: ["127.0.0.1:9192"] + first_contact_points: ["172.16.1.2:9092"] + connect_timeout_ms: 3000