refactor: DRY für shard-selection
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / persistence / InMemoryWithFilesStorageStrategyIT.java
index e10aae0..6fc9aac 100644 (file)
@@ -3,8 +3,11 @@ 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.api.ShardingStrategy;
 import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.filestorage.FileStorageStrategy;
+import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
+import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
 import lombok.extern.slf4j.Slf4j;
@@ -19,22 +22,22 @@ import java.util.function.Supplier;
 
 
 @Slf4j
-public class InMemoryWithFileStorageStrategyIT extends AbstractStorageStrategyIT
+public class InMemoryWithFilesStorageStrategyIT extends AbstractStorageStrategyIT
 {
   final static Path path = Paths.get("target","local-json-files");
 
   final Clock clock;
   final ObjectMapper mapper;
-  final FileStorageStrategy storageStrategy;
+  final FilesStorageStrategy storageStrategy;
 
 
-  public InMemoryWithFileStorageStrategyIT()
+  public InMemoryWithFilesStorageStrategyIT()
   {
     clock = Clock.systemDefaultZone();
     mapper = new ObjectMapper();
     mapper.registerModule(new JavaTimeModule());
     mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
-    storageStrategy = new FileStorageStrategy(
+    storageStrategy = new FilesStorageStrategy(
         path,
         clock,
         8,
@@ -50,9 +53,16 @@ public class InMemoryWithFileStorageStrategyIT extends AbstractStorageStrategyIT
   }
 
   @Override
-  protected Supplier<ChatHomeService> chatHomeServiceSupplier()
+  protected Supplier<ChatHomeService> getChatHomeServiceSupplier()
   {
-    return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
+    return () -> new InMemoryChatHomeService(1, getStorageStrategy().read());
+  }
+
+  @Override
+  protected ChatRoomFactory getChatRoomFactory()
+  {
+    ShardingStrategy strategy = chatRoomId -> 0;
+    return new InMemoryChatRoomFactory(strategy, clock, 8);
   }
 
   @BeforeEach