From: Kai Moritz Date: Wed, 20 Mar 2024 22:02:22 +0000 (+0100) Subject: test: RED - Updated keys must survive, if HAProxy reloads X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2e1e20c94f7119d5fd4d60c7e902affc7698a257;p=demos%2Fkafka%2Fchat test: RED - Updated keys must survive, if HAProxy reloads * The Handover-IT hast to signal HAProxy to reload, after a new backend was started for the first time. * Otherwise, HAProxy is not able to detect newly started backend-instances, because with docker, the name of a backend cannot be resolved, before it is started. * This test formulates the expectation, that dynamically added changes, that were applyed with the help of the Data Plane API, persist a reload. * *The test fails*, because HAProxy restores all maps from disk, if it reloads, but the dynamically made changes are never synced back to disk. --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyDataPlaneApiShardingPublisherStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyDataPlaneApiShardingPublisherStrategyIT.java index 9235a062..41ed2dea 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyDataPlaneApiShardingPublisherStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyDataPlaneApiShardingPublisherStrategyIT.java @@ -9,11 +9,13 @@ import org.springframework.web.reactive.function.client.WebClient; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.MountableFile; import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; import java.time.Duration; @@ -27,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class HaproxyDataPlaneApiShardingPublisherStrategyIT { @Test - void test() + void test() throws InterruptedException { Mono result = shardingPublisherStrategy.publishOwnership(SHARD); @@ -35,6 +37,17 @@ public class HaproxyDataPlaneApiShardingPublisherStrategyIT .isEqualTo(INSTANCE_ID); assertThat(getMapEntryValueForKey(SHARD).block(Duration.ofSeconds(5))) .isEqualTo(INSTANCE_ID); + + HAPROXY + .getDockerClient() + .killContainerCmd(HAPROXY.getContainerId()) + .withSignal("HUP") + .exec(); + + Thread.sleep(1000); // << No clue, how to detect that the reload is complete + + assertThat(getMapEntryValueForKey(SHARD).block(Duration.ofSeconds(5))) + .isEqualTo(INSTANCE_ID); } @@ -58,6 +71,7 @@ public class HaproxyDataPlaneApiShardingPublisherStrategyIT return response.createError(); } }) + .retryWhen(Retry.fixedDelay(15, Duration.ofSeconds(1))) .map(entry -> entry.value()); }