import de.juplo.kafka.chat.backend.domain.*;
import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
+import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration;
+import de.juplo.kafka.chat.backend.storage.files.FilesStorageConfiguration;
+import de.juplo.kafka.chat.backend.storage.mongodb.MongoDbStorageConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+import java.time.Clock;
import java.util.List;
import java.util.UUID;
import static pl.rzrz.assertj.reactor.Assertions.*;
+@SpringJUnitConfig(classes = {
+ InMemoryServicesConfiguration.class,
+ FilesStorageConfiguration.class,
+ MongoDbStorageConfiguration.class,
+ AbstractStorageStrategyIT.TestConfig.class })
+@EnableConfigurationProperties(ChatBackendProperties.class)
@Slf4j
public abstract class AbstractStorageStrategyIT
{
- protected ChatHomeService chathome;
+ @Autowired
+ ChatHomeService chathome;
+ @Autowired
+ StorageStrategy storageStrategy;
- protected abstract StorageStrategy getStorageStrategy();
- protected abstract StorageStrategyITConfig getConfig();
+ abstract void restore();
- protected void start()
+ void store()
{
- StorageStrategyITConfig config = getConfig();
- chathome = config.getChatHome();
- }
-
- protected void stop()
- {
- getStorageStrategy()
+ storageStrategy
.write(chathome)
- .subscribe();
+ .block();
}
@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);
}
- interface StorageStrategyITConfig
+ static class TestConfig
{
- ChatHomeService getChatHome();
+ @Bean
+ Clock clock()
+ {
+ return Clock.systemDefaultZone();
+ }
}
}