From: Kai Moritz Date: Mon, 21 Aug 2023 16:25:20 +0000 (+0200) Subject: refactor: Removed Interface `ChatHomeService` X-Git-Tag: rebase--2023-08-22~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=a6b73917ab03690cd264b82c6539fe2a88f786fa;p=demos%2Fkafka%2Fchat refactor: Removed Interface `ChatHomeService` --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java deleted file mode 100644 index f47e017d..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.juplo.kafka.chat.backend.persistence.inmemory; - -import de.juplo.kafka.chat.backend.domain.ChatRoom; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.util.UUID; - - -public interface ChatHomeService -{ - Mono getChatRoom(int shard, UUID id); - Flux getChatRooms(int shard); -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java index 381f5dbe..13341244 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java @@ -9,7 +9,7 @@ import java.util.*; @Slf4j -public class InMemoryChatHomeService implements ChatHomeService +public class InMemoryChatHomeService { private final Map[] chatrooms; @@ -55,13 +55,11 @@ public class InMemoryChatHomeService implements ChatHomeService chatrooms[chatRoom.getShard()].put(chatRoom.getId(), chatRoom); } - @Override public Mono getChatRoom(int shard, UUID id) { return Mono.justOrEmpty(chatrooms[shard].get(id)); } - @Override public Flux getChatRooms(int shard) { return Flux.fromStream(chatrooms[shard].values().stream()); diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java index bdca9b79..e35a6611 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java @@ -13,18 +13,18 @@ import java.util.*; @Slf4j public class SimpleChatHome implements ChatHome { - private final ChatHomeService service; + private final InMemoryChatHomeService service; private final int shard; - public SimpleChatHome(ChatHomeService service, int shard) + public SimpleChatHome(InMemoryChatHomeService service, int shard) { log.info("Created SimpleChatHome for shard {}", shard); this.service = service; this.shard = shard; } - public SimpleChatHome(ChatHomeService service) + public SimpleChatHome(InMemoryChatHomeService service) { this(service, 0); } diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java index a4defeb1..bff02a36 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java @@ -1,9 +1,10 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService; +import de.juplo.kafka.chat.backend.domain.ChatHome; import de.juplo.kafka.chat.backend.domain.ChatRoomFactory; import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService; import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory; +import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -21,21 +22,23 @@ public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyI { return new StorageStrategyITConfig() { - InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService( + InMemoryChatHomeService inMemoryChatHomeService = new InMemoryChatHomeService( 1, new int[] { 0 }, getStorageStrategy().read()); + SimpleChatHome simpleChatHome = new SimpleChatHome(inMemoryChatHomeService); + InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory( - chatHomeService, + inMemoryChatHomeService, chatRoomId -> 0, clock, 8); @Override - public ChatHomeService getChatHomeService() + public ChatHome getChatHome() { - return chatHomeService; + return simpleChatHome; } @Override diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java index 1373cf0b..58acb192 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java @@ -1,8 +1,6 @@ package de.juplo.kafka.chat.backend.persistence; import de.juplo.kafka.chat.backend.domain.*; -import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService; -import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; @@ -25,7 +23,7 @@ public abstract class AbstractStorageStrategyIT protected void start() { StorageStrategyITConfig config = getConfig(); - chathome = new SimpleChatHome(config.getChatHomeService()); + chathome = config.getChatHome(); chatRoomFactory = config.getChatRoomFactory(); } @@ -118,7 +116,7 @@ public abstract class AbstractStorageStrategyIT interface StorageStrategyITConfig { - ChatHomeService getChatHomeService(); + ChatHome getChatHome(); ChatRoomFactory getChatRoomFactory(); } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java index 418373a9..e45f1a5e 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java @@ -2,8 +2,6 @@ package de.juplo.kafka.chat.backend.persistence.inmemory; import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.domain.ChatRoomService; -import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService; -import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -25,7 +23,7 @@ public class SimpleChatHomeTest void testGetExistingChatroom() { // Given - ChatHomeService chatHomeService = mock(ChatHomeService.class); + InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class); ChatRoom chatRoom = new ChatRoom( UUID.randomUUID(), "Foo", @@ -48,7 +46,7 @@ public class SimpleChatHomeTest void testGetNonExistentChatroom() { // Given - ChatHomeService chatHomeService = mock(ChatHomeService.class); + InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class); when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty()); SimpleChatHome chatHome = new SimpleChatHome(chatHomeService);