refactor: Refined the configuration of `AbstractStorageStrategyIT'
authorKai Moritz <kai@juplo.de>
Fri, 17 Feb 2023 22:34:55 +0000 (23:34 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 17 Feb 2023 22:59:50 +0000 (23:59 +0100)
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java

index 5d22d12..d5e02b8 100644 (file)
@@ -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<ChatHomeService> 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();
+  }
 }
index fe7ecac..8ca7d47 100644 (file)
@@ -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<ChatHomeService> 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
index e56aff7..f86c9d3 100644 (file)
@@ -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<ChatHomeService> 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