1 package de.juplo.kafka.chat.backend.persistence.inmemory;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTestBase;
5 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
6 import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
7 import org.springframework.boot.test.context.TestConfiguration;
8 import org.springframework.context.annotation.Bean;
10 import java.nio.file.Paths;
11 import java.time.Clock;
12 import java.util.stream.IntStream;
15 public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
18 static class Configuration
21 ShardedChatHome chatHome(
24 InMemoryChatHomeService chatHomeService)
26 SimpleChatHome[] chatHomes = new SimpleChatHome[numShards];
30 .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
32 ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
34 return new ShardedChatHome(chatHomes, strategy);
38 InMemoryChatHomeService chatHomeService(
41 StorageStrategy storageStrategy)
43 return new InMemoryChatHomeService(
46 storageStrategy.read());
50 public FilesStorageStrategy storageStrategy(Integer numShards)
52 return new FilesStorageStrategy(
53 Paths.get("target", "test-classes", "data", "files"),
54 Clock.systemDefaultZone(),
56 new KafkaLikeShardingStrategy(numShards),
57 messageFlux -> new InMemoryChatRoomService(messageFlux),
70 return new int[] { 2 };