From a132e02981a3875e3c890347a2c498ef6a760e6e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 22 Feb 2024 22:59:00 +0100 Subject: [PATCH] WIP:neu --- .../kafka/chat/backend/KafkaHandoverIT.java | 40 ++++++++++++++-- src/test/resources/haproxy.cfg | 46 +++++++++++++++++++ 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/haproxy.cfg diff --git a/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java index 00b7a30d..c1862be4 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.test.context.EmbeddedKafka; +import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.KafkaContainer; import org.testcontainers.containers.Network; @@ -33,6 +34,22 @@ class KafkaHandoverIT extends AbstractHandoverIT Network network = Network.newNetwork(); + @Container + GenericContainer HAPROXY = + new GenericContainer(DockerImageName.parse("haproxytech/haproxy-debian:2.8")) + .withNetwork(network) + .withNetworkAliases("haproxy") + .withClasspathResourceMapping( + "haproxy.cfg", + "/usr/local/etc/haproxy/haproxy.cfg", + BindMode.READ_ONLY) + .withClasspathResourceMapping( + "sharding.map", + "/usr/local/etc/haproxy/sharding.map", + BindMode.READ_WRITE) + .withExposedPorts(8400, 8401, 8404, 5555) + .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("HAPROXY")); + @Container KafkaContainer KAFKA = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")) @@ -51,7 +68,12 @@ class KafkaHandoverIT extends AbstractHandoverIT .withCommand( "--chat.backend.instance-id=backend-1", "--chat.backend.services=kafka", - "--chat.backend.kafka.bootstrap-servers=kafka:9999" + "--chat.backend.kafka.bootstrap-servers=kafka:9999", + "--chat.backend.kafka.instance-uri=http://backend-1:8080", + "--chat.backend.kafka.num-partitions=10", + "--chat.backend.kafka.client-id-prefix=B1", + "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401", + "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map" ) .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-1")); @@ -64,7 +86,12 @@ class KafkaHandoverIT extends AbstractHandoverIT .withCommand( "--chat.backend.instance-id=backend-2", "--chat.backend.services=kafka", - "--chat.backend.kafka.bootstrap-servers=kafka:9999" + "--chat.backend.kafka.bootstrap-servers=kafka:9999", + "--chat.backend.kafka.instance-uri=http://backend-2:8080", + "--chat.backend.kafka.num-partitions=10", + "--chat.backend.kafka.client-id-prefix=B2", + "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401", + "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map" ) .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-2")); @@ -77,7 +104,12 @@ class KafkaHandoverIT extends AbstractHandoverIT .withCommand( "--chat.backend.instance-id=backend-3", "--chat.backend.services=kafka", - "--chat.backend.kafka.bootstrap-servers=kafka:9999" + "--chat.backend.kafka.bootstrap-servers=kafka:9999", + "--chat.backend.kafka.instance-uri=http://backend-3:8080", + "--chat.backend.kafka.num-partitions=10", + "--chat.backend.kafka.client-id-prefix=B3", + "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401", + "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map" ) .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-3")); @@ -90,6 +122,6 @@ class KafkaHandoverIT extends AbstractHandoverIT @Test void test() throws InterruptedException { - Thread.sleep(15000); + Thread.sleep(150000); } } diff --git a/src/test/resources/haproxy.cfg b/src/test/resources/haproxy.cfg new file mode 100644 index 00000000..b19f71f1 --- /dev/null +++ b/src/test/resources/haproxy.cfg @@ -0,0 +1,46 @@ +# Config from Blog-article "How to Run HAProxy with Docker" +defaults + mode http + timeout client 10s + timeout connect 5s + timeout server 10m + timeout http-request 10s + log global + +global + stats socket ipv4@:8401 level admin + stats socket /var/run/haproxy.sock mode 666 level admin + stats timeout 2m + +frontend stats + bind *:8404 + stats enable + stats uri / + stats refresh 10s + +frontend frontend + bind :8400 + default_backend random + use_backend %[req.hdr(X-Shard),map(/usr/local/etc/haproxy/sharding.map)] + +backend random + server b1 backend-1:8080 check + server b2 backend-2:8080 check + server b3 backend-3:8080 check + +backend backend_1 + server b1 backend-1:8080 check + +backend backend_2 + server b2 backend-2:8080 check + +backend backend_3 + server b3 backend-3:8080 check + +userlist haproxy-dataplaneapi + user juplo insecure-password juplo + +program api + command /usr/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --restart-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist haproxy-dataplaneapi + no option start-on-reload + -- 2.20.1