X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2FHandoverIT.java;h=97cf7676cdb650dbfaeaef2284dccadf72d7b94d;hb=cacfb02c73cfd86f76fc3abf192fbebcf5c27b44;hp=f384f7e8afdf641aa20f2ae1def14db5a177d015;hpb=45b6cc67b3b7997f64f8fb74ca15525642ef4f8d;p=demos%2Fkafka%2Fchat diff --git a/src/test/java/de/juplo/kafka/chat/backend/HandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/HandoverIT.java index f384f7e8..97cf7676 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/HandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/HandoverIT.java @@ -36,10 +36,6 @@ import java.util.stream.IntStream; @Slf4j public abstract class AbstractHandoverIT { - static final ImagePullPolicy NEVER_PULL = imageName -> false; - static final ParameterizedTypeReference> SSE_TYPE = new ParameterizedTypeReference<>() {}; - - @Test void test() throws InterruptedException { @@ -61,70 +57,6 @@ public abstract class AbstractHandoverIT .block(); } - Mono createChatRoom(String name) - { - return webClient - .post() - .uri("/create") - .contentType(MediaType.TEXT_PLAIN) - .bodyValue(name) - .accept(MediaType.APPLICATION_JSON) - .exchangeToMono(response -> - { - if (response.statusCode().equals(HttpStatus.OK)) - { - return response.bodyToMono(ChatRoomInfoTo.class); - } - else - { - return response.createError(); - } - }); - } - - Mono sendMessage( - ChatRoomInfoTo chatRoom, - User user, - String message) - { - return webClient - .put() - .uri( - "/{chatRoomId}/{username}/{serial}", - chatRoom.getId(), - user.getName(), - user.nextSerial()) - .contentType(MediaType.TEXT_PLAIN) - .accept(MediaType.APPLICATION_JSON) - .bodyValue(message) - .exchangeToMono(response -> - { - if (response.statusCode().equals(HttpStatus.OK)) - { - return response.bodyToMono(MessageTo.class); - } - else - { - return response.createError(); - } - }); - } - - Flux> receiveMessages(ChatRoomInfoTo chatRoom) - { - return webClient - .get() - .uri( - "/{chatRoomId}/listen", - chatRoom.getId()) - .accept(MediaType.TEXT_EVENT_STREAM) - .retrieve() - .bodyToFlux(SSE_TYPE); - } - - - WebClient webClient; - abstract void setUpExtra() throws IOException, InterruptedException; @@ -137,9 +69,6 @@ public abstract class AbstractHandoverIT // backend2.start(); // backend3.start(); - Integer port = haproxy.getMappedPort(8400); - webClient = WebClient.create("http://localhost:" + port); - Awaitility .await() .atMost(Duration.ofMinutes(10)) @@ -173,7 +102,8 @@ public abstract class AbstractHandoverIT Awaitility .await() .atMost(Duration.ofMinutes(10)) - .until(() -> webClient + .until(() -> WebClient + .create("http://localhost:" + haproxy.getMappedPort(8400)) .get() .uri("/actuator/health") .exchangeToMono(response -> @@ -193,44 +123,12 @@ public abstract class AbstractHandoverIT .block()); } - Network network = Network.newNetwork(); - - 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) - .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("HAPROXY")); + GenericContainer haproxy; abstract String[] getCommandBackend1(); - GenericContainer backend1 = - new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")) - .withImagePullPolicy(NEVER_PULL) - .withNetwork(network) - .withNetworkAliases("backend-1") - .withCommand(getCommandBackend1()) - .withExposedPorts(8080) - .waitingFor(Wait.forLogMessage(".*Started\\ ChatBackendApplication.*\\n", 1)) - .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-1")); - + GenericContainer backend1; abstract String[] getCommandBackend2(); - GenericContainer backend2 = - new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")) - .withImagePullPolicy(NEVER_PULL) - .withNetwork(network) - .withNetworkAliases("backend-2") - .withCommand(getCommandBackend2()) - .withExposedPorts(8080) - .waitingFor(Wait.forLogMessage(".*Started\\ ChatBackendApplication.*\\n", 1)) - .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-2")); + GenericContainer backend2; abstract String[] getCommandBackend3(); GenericContainer backend3 =