WIP:refactor: Refined channel-states, introduced `ChannelState` -- ALIGN
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / implementation / inmemory / ShardedChatHomeServiceTest.java
index b830f30..95501ad 100644 (file)
@@ -1,74 +1,18 @@
 package de.juplo.kafka.chat.backend.implementation.inmemory;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest;
-import de.juplo.kafka.chat.backend.implementation.ShardingStrategy;
-import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
-import de.juplo.kafka.chat.backend.storage.files.FilesStorageStrategy;
-import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.TestPropertySource;
 
-import java.net.URI;
-import java.nio.file.Paths;
-import java.time.Clock;
-import java.util.stream.IntStream;
+import static de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest.NUM_SHARDS;
+import static de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest.OWNED_SHARD;
 
+
+@TestPropertySource(properties = {
+    "chat.backend.inmemory.sharding-strategy=kafkalike",
+    "chat.backend.inmemory.num-shards=" + NUM_SHARDS,
+    "chat.backend.inmemory.owned-shards=" + OWNED_SHARD,
+    "chat.backend.inmemory.storage-strategy=files",
+    "chat.backend.inmemory.storage-directory=target/test-classes/data/files" })
 public class ShardedChatHomeServiceTest extends ChatHomeServiceWithShardsTest
 {
-  @TestConfiguration
-  static class Configuration
-  {
-    @Bean
-    ShardedChatHomeService chatHome(
-        StorageStrategy storageStrategy,
-        Clock clock)
-    {
-      SimpleChatHomeService[] chatHomes = new SimpleChatHomeService[NUM_SHARDS];
-
-      IntStream
-          .of(ownedShards())
-          .forEach(shard -> chatHomes[shard] = new SimpleChatHomeService(
-              shard,
-              storageStrategy,
-              clock,
-              bufferSize()));
-
-      ShardingStrategy strategy = new KafkaLikeShardingStrategy(NUM_SHARDS);
-
-      return new ShardedChatHomeService(
-          "http://instance-0",
-          chatHomes,
-          IntStream
-              .range(0, NUM_SHARDS)
-              .mapToObj(shard -> "http://instance-0")
-              .map(uriString -> URI.create(uriString))
-              .toArray(size -> new URI[size]),
-          strategy);
-    }
-
-    @Bean
-    public FilesStorageStrategy storageStrategy(Clock clock)
-    {
-      return new FilesStorageStrategy(
-          Paths.get("target", "test-classes", "data", "files"),
-          new KafkaLikeShardingStrategy(NUM_SHARDS),
-          new ObjectMapper());
-    }
-
-    @Bean
-    Clock clock()
-    {
-      return Clock.systemDefaultZone();
-    }
-
-    int[] ownedShards()
-    {
-      return new int[] { OWNED_SHARD };
-    }
-
-    int bufferSize()
-    {
-      return 8;
-    }
-  }
 }