From: Kai Moritz Date: Mon, 11 Mar 2024 17:15:32 +0000 (+0100) Subject: test: HandoverIT-POC - Refactored `TestListener` X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=b6c2b1b93250747d3c09b76d5dee0c09a726c7d8;p=demos%2Fkafka%2Fchat test: HandoverIT-POC - Refactored `TestListener` --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestListener.java b/src/test/java/de/juplo/kafka/chat/backend/TestListener.java index e58cb2b6..e5b25293 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestListener.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestListener.java @@ -28,28 +28,34 @@ public class TestListener .fromArray(chatRooms) .flatMap(chatRoom -> { - log.info("Requesting messages for chat-room {}", chatRoom); List list = new LinkedList<>(); receivedMessages.put(chatRoom.getId(), list); - return receiveMessages(chatRoom) - .flatMap(sse -> - { - try - { - return Mono.just(objectMapper.readValue(sse.data(), MessageTo.class)); - } - catch (Exception e) - { - return Mono.error(e); - } - }) - .doOnNext(message -> list.add(message)) - .doOnComplete(() -> log.info("{} was completed!", chatRoom)) - .doOnError(throwalbe -> log.error("{} failed: {}", chatRoom, throwalbe)); + return receiveMessages(chatRoom); }); } - Flux> receiveMessages(ChatRoomInfoTo chatRoom) + Flux receiveMessages(ChatRoomInfoTo chatRoom) + { + log.info("Requesting messages for chat-room {}", chatRoom); + List list = receivedMessages.get(chatRoom.getId()); + return receiveServerSentEvents(chatRoom) + .flatMap(sse -> + { + try + { + return Mono.just(objectMapper.readValue(sse.data(), MessageTo.class)); + } + catch (Exception e) + { + return Mono.error(e); + } + }) + .doOnNext(message -> list.add(message)) + .doOnComplete(() -> log.info("{} was completed!", chatRoom)) + .doOnError(throwalbe -> log.error("{} failed: {}", chatRoom, throwalbe)); + } + + Flux> receiveServerSentEvents(ChatRoomInfoTo chatRoom) { return webClient .get()