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(
22 InMemoryChatHomeService chatHomeService)
24 SimpleChatHome[] chatHomes = new SimpleChatHome[numShards()];
28 .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
30 ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards());
32 return new ShardedChatHome(chatHomes, strategy);
36 InMemoryChatHomeService chatHomeService(
37 StorageStrategy storageStrategy)
39 return new InMemoryChatHomeService(
42 storageStrategy.read());
46 public FilesStorageStrategy storageStrategy()
48 return new FilesStorageStrategy(
49 Paths.get("target", "test-classes", "data", "files"),
50 Clock.systemDefaultZone(),
52 new KafkaLikeShardingStrategy(numShards()),
53 messageFlux -> new InMemoryChatRoomService(messageFlux),
64 return new int[] { 2 };