refactor: Moved `ShardingStrategy` into package `persistence` -- ALIGNE
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / persistence / inmemory / ShardedChatHomeTest.java
index 2370cbe..8d9036f 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka.chat.backend.persistence.inmemory;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTest;
+import de.juplo.kafka.chat.backend.persistence.ShardingStrategy;
 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
 import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
 import org.springframework.boot.test.context.TestConfiguration;
@@ -18,13 +19,18 @@ public class ShardedChatHomeTest extends ChatHomeWithShardsTest
   {
     @Bean
     ShardedChatHome chatHome(
-        InMemoryChatHomeService chatHomeService)
+        StorageStrategy storageStrategy,
+        Clock clock)
     {
       SimpleChatHome[] chatHomes = new SimpleChatHome[NUM_SHARDS];
 
       IntStream
           .of(ownedShards())
-          .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
+          .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
+              shard,
+              storageStrategy,
+              clock,
+              bufferSize()));
 
       ShardingStrategy strategy = new KafkaLikeShardingStrategy(NUM_SHARDS);
 
@@ -32,30 +38,28 @@ public class ShardedChatHomeTest extends ChatHomeWithShardsTest
     }
 
     @Bean
-    InMemoryChatHomeService chatHomeService(
-        StorageStrategy storageStrategy)
-    {
-      return new InMemoryChatHomeService(
-          NUM_SHARDS,
-          ownedShards(),
-          storageStrategy.read());
-    }
-
-    @Bean
-    public FilesStorageStrategy storageStrategy()
+    public FilesStorageStrategy storageStrategy(Clock clock)
     {
       return new FilesStorageStrategy(
           Paths.get("target", "test-classes", "data", "files"),
-          Clock.systemDefaultZone(),
-          8,
           new KafkaLikeShardingStrategy(NUM_SHARDS),
-          messageFlux -> new InMemoryChatRoomService(messageFlux),
           new ObjectMapper());
     }
 
+    @Bean
+    Clock clock()
+    {
+      return Clock.systemDefaultZone();
+    }
+
     int[] ownedShards()
     {
       return new int[] { OWNED_SHARD };
     }
+
+    int bufferSize()
+    {
+      return 8;
+    }
   }
 }