From: Kai Moritz Date: Fri, 17 Feb 2023 22:34:55 +0000 (+0100) Subject: refactor: Refined the configuration of `AbstractStorageStrategyIT' X-Git-Tag: wip-sharding~16 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=676f6042961eeb89d10a6f82eb870760b66260ef;p=demos%2Fkafka%2Fchat refactor: Refined the configuration of `AbstractStorageStrategyIT' --- 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 5d22d12e..d5e02b83 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 @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; import java.util.List; import java.util.UUID; -import java.util.function.Supplier; import static pl.rzrz.assertj.reactor.Assertions.*; @@ -19,13 +18,13 @@ public abstract class AbstractStorageStrategyIT protected abstract StorageStrategy getStorageStrategy(); - protected abstract Supplier getChatHomeServiceSupplier(); - protected abstract ChatRoomFactory getChatRoomFactory(); + protected abstract StorageStrategyITConfig getConfig(); protected void start() { - chathome = new SimpleChatHome(getChatHomeServiceSupplier().get()); - chatRoomFactory = getChatRoomFactory(); + StorageStrategyITConfig config = getConfig(); + chathome = new SimpleChatHome(config.getChatHomeService()); + chatRoomFactory = config.getChatRoomFactory(); } protected void stop() @@ -110,4 +109,11 @@ public abstract class AbstractStorageStrategyIT .getChatRoom(chatroomB.getId()) .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4); } + + + interface StorageStrategyITConfig + { + ChatHomeService getChatHomeService(); + ChatRoomFactory getChatRoomFactory(); + } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java index fe7ecac1..8ca7d472 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java @@ -3,7 +3,6 @@ package de.juplo.kafka.chat.backend.persistence; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import de.juplo.kafka.chat.backend.domain.ShardingStrategy; import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomFactory; import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory; @@ -18,7 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Clock; -import java.util.function.Supplier; @Slf4j @@ -54,19 +52,32 @@ public class InMemoryWithFilesStorageIT extends AbstractStorageStrategyIT } @Override - protected Supplier getChatHomeServiceSupplier() + protected StorageStrategyITConfig getConfig() { - return () -> new InMemoryChatHomeService( - 1, - new int[] { 0 }, - getStorageStrategy().read()); - } + return new StorageStrategyITConfig() + { + InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService( + 1, + new int[] { 0 }, + getStorageStrategy().read()); - @Override - protected ChatRoomFactory getChatRoomFactory() - { - ShardingStrategy strategy = chatRoomId -> 0; - return new InMemoryChatRoomFactory(strategy, clock, 8); + InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory( + chatRoomId -> 0, + clock, + 8); + + @Override + public ChatHomeService getChatHomeService() + { + return chatHomeService; + } + + @Override + public ChatRoomFactory getChatRoomFactory() + { + return chatRoomFactory; + } + }; } @BeforeEach diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java index e56aff77..f86c9d3f 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java @@ -1,6 +1,5 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.domain.ShardingStrategy; import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomFactory; import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService; @@ -28,7 +27,6 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Clock; -import java.util.function.Supplier; @Testcontainers @@ -54,19 +52,32 @@ public class InMemoryWithMongoDbStorageIT extends AbstractStorageStrategyIT } @Override - protected Supplier getChatHomeServiceSupplier() + protected StorageStrategyITConfig getConfig() { - return () -> new InMemoryChatHomeService( - 1, - new int[] { 0 }, - getStorageStrategy().read()); - } + return new StorageStrategyITConfig() + { + InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService( + 1, + new int[] { 0 }, + getStorageStrategy().read()); - @Override - protected ChatRoomFactory getChatRoomFactory() - { - ShardingStrategy strategy = chatRoomId -> 0; - return new InMemoryChatRoomFactory(strategy, clock, 8); + InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory( + chatRoomId -> 0, + clock, + 8); + + @Override + public ChatHomeService getChatHomeService() + { + return chatHomeService; + } + + @Override + public ChatRoomFactory getChatRoomFactory() + { + return chatRoomFactory; + } + }; } @TestConfiguration