1 package de.juplo.kafka.chat.backend.implementation.inmemory;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest;
5 import de.juplo.kafka.chat.backend.implementation.ShardingStrategy;
6 import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
7 import de.juplo.kafka.chat.backend.storage.files.FilesStorageStrategy;
8 import org.springframework.boot.test.context.TestConfiguration;
9 import org.springframework.context.annotation.Bean;
12 import java.nio.file.Paths;
13 import java.time.Clock;
14 import java.util.stream.IntStream;
16 public class ShardedChatHomeServiceTest extends ChatHomeServiceWithShardsTest
19 static class Configuration
22 ShardedChatHomeService chatHome(
23 StorageStrategy storageStrategy,
26 SimpleChatHomeService[] chatHomes = new SimpleChatHomeService[NUM_SHARDS];
30 .forEach(shard -> chatHomes[shard] = new SimpleChatHomeService(
36 ShardingStrategy strategy = new KafkaLikeShardingStrategy(NUM_SHARDS);
38 return new ShardedChatHomeService(
43 .mapToObj(shard -> "http://instance-0")
44 .map(uriString -> URI.create(uriString))
45 .toArray(size -> new URI[size]),
50 public FilesStorageStrategy storageStrategy(Clock clock)
52 return new FilesStorageStrategy(
53 Paths.get("target", "test-classes", "data", "files"),
54 new KafkaLikeShardingStrategy(NUM_SHARDS),
61 return Clock.systemDefaultZone();
66 return new int[] { OWNED_SHARD };