+
+ final Network network = Network.newNetwork();
+ final GenericContainer haproxy, backend1, backend2, backend3;
+
+
+ AbstractContainerTemplates()
+ {
+ haproxy = createHaproxyContainer();
+ backend1 = createBackendContainer("1");
+ backend2 = createBackendContainer("2");
+ backend3 = createBackendContainer("3");
+ }
+
+
+ void setUpExtra() throws Exception
+ {
+ log.info("This setup does not need any extra containers");
+ }
+
+ void setUp() throws Exception
+ {
+ setUpExtra();
+ haproxy.start();
+ backend1.start();
+ // backend2.start();
+ // backend3.start();
+
+ Awaitility
+ .await()
+ .atMost(Duration.ofMinutes(10))
+ .until(() -> WebClient
+ .create("http://localhost:" + backend1.getMappedPort(8080))
+ .get()
+ .uri("/actuator/health")
+ .exchangeToMono(response ->
+ {
+ if (response.statusCode().equals(HttpStatus.OK))
+ {
+ return response
+ .bodyToMono(StatusTO.class)
+ .map(StatusTO::getStatus)
+ .map(status -> status.equalsIgnoreCase("UP"));
+ }
+ else
+ {
+ return Mono.just(false);
+ }
+ })
+ .block());
+
+ haproxy
+ .getDockerClient()
+ .killContainerCmd(haproxy.getContainerId())
+ .withSignal("HUP")
+ .exec();
+
+
+ Awaitility
+ .await()
+ .atMost(Duration.ofMinutes(10))
+ .until(() -> WebClient
+ .create("http://localhost:" + haproxy.getMappedPort(8400))
+ .get()
+ .uri("/actuator/health")
+ .exchangeToMono(response ->
+ {
+ if (response.statusCode().equals(HttpStatus.OK))
+ {
+ return response
+ .bodyToMono(StatusTO.class)
+ .map(StatusTO::getStatus)
+ .map(status -> status.equalsIgnoreCase("UP"));
+ }
+ else
+ {
+ return Mono.just(false);
+ }
+ })
+ .block());
+ }
+
+ abstract String[] getBackendCommand();
+
+ final GenericContainer createHaproxyContainer()