WIP:neu
authorKai Moritz <kai@juplo.de>
Thu, 22 Feb 2024 21:59:00 +0000 (22:59 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 23 Feb 2024 15:40:03 +0000 (16:40 +0100)
src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java
src/test/resources/haproxy.cfg [new file with mode: 0644]

index 00b7a30..c1862be 100644 (file)
@@ -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 (file)
index 0000000..b19f71f
--- /dev/null
@@ -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
+