name = "sharding-strategy",
havingValue = "none",
matchIfMissing = true)
- ChatHomeService noneShardingChatHome(
+ SimpleChatHomeService noneShardingChatHome(
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
prefix = "chat.backend.inmemory",
name = "sharding-strategy",
havingValue = "kafkalike")
- ChatHomeService kafkalikeShardingChatHome(
+ ShardedChatHomeService kafkalikeShardingChatHome(
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
Mono<Void> restore(StorageStrategy storageStrategy)
{
+ chatRoomInfo.clear();
+ chatRoomData.clear();
+
return storageStrategy
.readChatRoomInfo()
.filter(info ->
}
@Bean
- ChatHomeService kafkaChatHome(
+ KafkaChatHomeService kafkaChatHome(
ChatBackendProperties properties,
InfoChannel infoChannel,
DataChannel dataChannel)
package de.juplo.kafka.chat.backend;
-import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
-import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration;
import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryTestUtils;
+import de.juplo.kafka.chat.backend.implementation.inmemory.SimpleChatHomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import java.time.Clock;
-
@ContextConfiguration(classes = InMemoryTestUtils.class)
@Slf4j
{
@Autowired
InMemoryTestUtils testUtils;
+ @Autowired
+ SimpleChatHomeService simpleChatHomeService;
@Override
- ChatHomeService getChatHome()
+ void restore()
{
- return testUtils.createNoneShardingChatHomeService();
+ testUtils.restore(simpleChatHomeService).block();
}
}
@Slf4j
public abstract class AbstractStorageStrategyIT
{
+ @Autowired
ChatHomeService chathome;
-
@Autowired
StorageStrategy storageStrategy;
- abstract ChatHomeService getChatHome();
- protected void start()
- {
- chathome = getChatHome();
- }
+ abstract void restore();
- protected void stop()
+ void store()
{
storageStrategy
.write(chathome)
}
@Test
- protected void testStoreAndRecreate()
+ void testStoreAndRecreate()
{
- start();
+ restore();
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
.getChatRoomData(chatRoomId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
- stop();
- start();
+ store();
+ restore();
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
}
@Test
- protected void testStoreAndRecreateParallelChatRooms()
+ void testStoreAndRecreateParallelChatRooms()
{
- start();
+ restore();
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
.getChatRoomData(chatRoomBId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
- stop();
- start();
+ store();
+ restore();
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
+import reactor.core.publisher.Mono;
import java.time.Clock;
public class InMemoryTestUtils
{
- private final InMemoryServicesConfiguration config =
- new InMemoryServicesConfiguration();
-
- @Autowired
- ChatBackendProperties properties;
@Autowired
StorageStrategy storageStrategy;
- @Autowired
- Clock clock;
- public ChatHomeService createNoneShardingChatHomeService()
+ public Mono<Void> restore(SimpleChatHomeService simpleChatHomeService)
{
- return config.noneShardingChatHome(
- properties,
- storageStrategy,
- clock);
+ return simpleChatHomeService.restore(storageStrategy);
}
}