+++ /dev/null
-package de.juplo.kafka.chat.backend;
-
-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;
-
-
-@ContextConfiguration(classes = InMemoryTestUtils.class)
-@Slf4j
-public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyIT
-{
- @Autowired
- InMemoryTestUtils testUtils;
- @Autowired
- SimpleChatHomeService simpleChatHomeService;
-
- @Override
- void restore()
- {
- testUtils.restore(simpleChatHomeService).block();
- }
-}
+++ /dev/null
-package de.juplo.kafka.chat.backend;
-
-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
-{
- @Autowired
- ChatHomeService chathome;
- @Autowired
- StorageStrategy storageStrategy;
-
-
- abstract void restore();
-
- void store()
- {
- storageStrategy
- .write(chathome)
- .block();
- }
-
- @Test
- void testStoreAndRecreate()
- {
- restore();
-
- assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
-
- UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
- ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block();
- log.debug("Created chat-room {}", info);
- ChatRoomData chatroom = chathome.getChatRoomData(chatRoomId).block();
- Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
- Message m2 = chatroom.addMessage(1l, "ute", "Ich bin Ute...").block();
- Message m3 = chatroom.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
- Message m4 = chatroom.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
-
- assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
- assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
- assertThat(chathome
- .getChatRoomData(chatRoomId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
-
- store();
- restore();
-
- assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
- assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
- assertThat(chathome
- .getChatRoomData(chatRoomId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
- }
-
- @Test
- void testStoreAndRecreateParallelChatRooms()
- {
- restore();
-
- assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
-
- UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
- ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block();
- log.debug("Created chat-room {}", infoA);
- ChatRoomData chatroomA = chathome.getChatRoomData(chatRoomAId).block();
- Message ma1 = chatroomA.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
- Message ma2 = chatroomA.addMessage(1l, "ute", "Ich bin Ute...").block();
- Message ma3 = chatroomA.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
- Message ma4 = chatroomA.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
-
- UUID chatRoomBId = UUID.fromString("8763dfdc-4dda-4a74-bea4-4b389177abea");
- ChatRoomInfo infoB = chathome.createChatRoom(chatRoomBId, "BAR").block();
- log.debug("Created chat-room {}", infoB);
- ChatRoomData chatroomB = chathome.getChatRoomData(chatRoomBId).block();
- Message mb1 = chatroomB.addMessage(1l,"peter", "Hallo, ich heiße Uwe!").block();
- Message mb2 = chatroomB.addMessage(1l, "ute", "Ich bin Ute...").block();
- Message mb3 = chatroomB.addMessage(1l, "klaus", "Willst du mit mir gehen?").block();
- Message mb4 = chatroomB.addMessage(2l, "peter", "Hä? Was jetzt?!? Isch glohb isch höb ühn däjah vüh...").block();
-
- assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
- assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
- assertThat(chathome
- .getChatRoomData(chatRoomAId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
- assertThat(chathome.getChatRoomData(chatRoomBId)).emitsExactly(chatroomB);
- assertThat(chathome
- .getChatRoomData(chatRoomBId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
-
- store();
- restore();
-
- assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
- assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
- assertThat(chathome
- .getChatRoomData(chatRoomAId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
- assertThat(chathome.getChatRoomInfo(chatRoomBId)).emitsExactly(infoB);
- assertThat(chathome
- .getChatRoomData(chatRoomBId)
- .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
- }
-
-
- static class TestConfig
- {
- @Bean
- Clock clock()
- {
- return Clock.systemDefaultZone();
- }
- }
-}
+++ /dev/null
-package de.juplo.kafka.chat.backend;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.BeforeEach;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.TestPropertySource;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-
-@TestPropertySource(properties = {
- "chat.backend.inmemory.sharding-strategy=none",
- "chat.backend.inmemory.storage-strategy=files",
- "chat.backend.inmemory.storage-directory=target/files" })
-@ContextConfiguration(classes = InMemoryWithFilesStorageIT.TestConfig.class)
-@Slf4j
-public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
-{
- @BeforeEach
- void resetStorage(
- @Autowired ChatBackendProperties properties)
- throws Exception
- {
- Path path = Paths.get(properties.getInmemory().getStorageDirectory());
- if (Files.exists(path))
- {
- Files
- .walk(path)
- .forEach(file ->
- {
- try
- {
- if (!file.equals(path))
- {
- log.debug("Deleting file {}", file);
- Files.delete(file);
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- });
- log.debug("Deleting data-directory {}", path);
- Files.delete(path);
- }
- }
-
-
- static class TestConfig
- {
- @Bean
- ObjectMapper objectMapper()
- {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.registerModule(new JavaTimeModule());
- objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- return objectMapper;
- }
- }
-}
+++ /dev/null
-package de.juplo.kafka.chat.backend;
-
-import de.juplo.kafka.chat.backend.storage.mongodb.ChatRoomRepository;
-import de.juplo.kafka.chat.backend.storage.mongodb.MessageRepository;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.BeforeEach;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
-import org.springframework.test.context.TestPropertySource;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.MongoDBContainer;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
-import org.testcontainers.junit.jupiter.Container;
-import org.testcontainers.junit.jupiter.Testcontainers;
-
-
-@TestPropertySource(properties = {
- "chat.backend.inmemory.sharding-strategy=none",
- "chat.backend.inmemory.storage-strategy=mongodb" })
-@Testcontainers
-@EnableAutoConfiguration
-@Slf4j
-public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
-{
- @Container
- @ServiceConnection
- private static final GenericContainer MONGODB = new MongoDBContainer("mongo:6");
-
- @BeforeEach
- void resetStorage(
- @Autowired ChatRoomRepository chatRoomRepository,
- @Autowired MessageRepository messageRepository)
- {
- chatRoomRepository.deleteAll().block();
- messageRepository.deleteAll().block();
- }
-
- @BeforeEach
- void setUpLogging()
- {
- Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
- MONGODB.followOutput(logConsumer);
- }
-}
--- /dev/null
+package de.juplo.kafka.chat.backend;
+
+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;
+
+
+@ContextConfiguration(classes = InMemoryTestUtils.class)
+@Slf4j
+public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyIT
+{
+ @Autowired
+ InMemoryTestUtils testUtils;
+ @Autowired
+ SimpleChatHomeService simpleChatHomeService;
+
+ @Override
+ void restore()
+ {
+ testUtils.restore(simpleChatHomeService).block();
+ }
+}
--- /dev/null
+package de.juplo.kafka.chat.backend;
+
+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
+{
+ @Autowired
+ ChatHomeService chathome;
+ @Autowired
+ StorageStrategy storageStrategy;
+
+
+ abstract void restore();
+
+ void store()
+ {
+ storageStrategy
+ .write(chathome)
+ .block();
+ }
+
+ @Test
+ void testStoreAndRecreate()
+ {
+ restore();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
+
+ UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
+ ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block();
+ log.debug("Created chat-room {}", info);
+ ChatRoomData chatroom = chathome.getChatRoomData(chatRoomId).block();
+ Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
+ Message m2 = chatroom.addMessage(1l, "ute", "Ich bin Ute...").block();
+ Message m3 = chatroom.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
+ Message m4 = chatroom.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
+ assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
+ assertThat(chathome
+ .getChatRoomData(chatRoomId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
+
+ store();
+ restore();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
+ assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
+ assertThat(chathome
+ .getChatRoomData(chatRoomId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
+ }
+
+ @Test
+ void testStoreAndRecreateParallelChatRooms()
+ {
+ restore();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
+
+ UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
+ ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block();
+ log.debug("Created chat-room {}", infoA);
+ ChatRoomData chatroomA = chathome.getChatRoomData(chatRoomAId).block();
+ Message ma1 = chatroomA.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
+ Message ma2 = chatroomA.addMessage(1l, "ute", "Ich bin Ute...").block();
+ Message ma3 = chatroomA.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
+ Message ma4 = chatroomA.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
+
+ UUID chatRoomBId = UUID.fromString("8763dfdc-4dda-4a74-bea4-4b389177abea");
+ ChatRoomInfo infoB = chathome.createChatRoom(chatRoomBId, "BAR").block();
+ log.debug("Created chat-room {}", infoB);
+ ChatRoomData chatroomB = chathome.getChatRoomData(chatRoomBId).block();
+ Message mb1 = chatroomB.addMessage(1l,"peter", "Hallo, ich heiße Uwe!").block();
+ Message mb2 = chatroomB.addMessage(1l, "ute", "Ich bin Ute...").block();
+ Message mb3 = chatroomB.addMessage(1l, "klaus", "Willst du mit mir gehen?").block();
+ Message mb4 = chatroomB.addMessage(2l, "peter", "Hä? Was jetzt?!? Isch glohb isch höb ühn däjah vüh...").block();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
+ assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
+ assertThat(chathome
+ .getChatRoomData(chatRoomAId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
+ assertThat(chathome.getChatRoomData(chatRoomBId)).emitsExactly(chatroomB);
+ assertThat(chathome
+ .getChatRoomData(chatRoomBId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
+
+ store();
+ restore();
+
+ assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
+ assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
+ assertThat(chathome
+ .getChatRoomData(chatRoomAId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
+ assertThat(chathome.getChatRoomInfo(chatRoomBId)).emitsExactly(infoB);
+ assertThat(chathome
+ .getChatRoomData(chatRoomBId)
+ .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
+ }
+
+
+ static class TestConfig
+ {
+ @Bean
+ Clock clock()
+ {
+ return Clock.systemDefaultZone();
+ }
+ }
+}
--- /dev/null
+package de.juplo.kafka.chat.backend;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.BeforeEach;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+
+@TestPropertySource(properties = {
+ "chat.backend.inmemory.sharding-strategy=none",
+ "chat.backend.inmemory.storage-strategy=files",
+ "chat.backend.inmemory.storage-directory=target/files" })
+@ContextConfiguration(classes = InMemoryWithFilesStorageIT.TestConfig.class)
+@Slf4j
+public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
+{
+ @BeforeEach
+ void resetStorage(
+ @Autowired ChatBackendProperties properties)
+ throws Exception
+ {
+ Path path = Paths.get(properties.getInmemory().getStorageDirectory());
+ if (Files.exists(path))
+ {
+ Files
+ .walk(path)
+ .forEach(file ->
+ {
+ try
+ {
+ if (!file.equals(path))
+ {
+ log.debug("Deleting file {}", file);
+ Files.delete(file);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ });
+ log.debug("Deleting data-directory {}", path);
+ Files.delete(path);
+ }
+ }
+
+
+ static class TestConfig
+ {
+ @Bean
+ ObjectMapper objectMapper()
+ {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.registerModule(new JavaTimeModule());
+ objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ return objectMapper;
+ }
+ }
+}
--- /dev/null
+package de.juplo.kafka.chat.backend;
+
+import de.juplo.kafka.chat.backend.storage.mongodb.ChatRoomRepository;
+import de.juplo.kafka.chat.backend.storage.mongodb.MessageRepository;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.BeforeEach;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
+import org.springframework.test.context.TestPropertySource;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+
+@TestPropertySource(properties = {
+ "chat.backend.inmemory.sharding-strategy=none",
+ "chat.backend.inmemory.storage-strategy=mongodb" })
+@Testcontainers
+@EnableAutoConfiguration
+@Slf4j
+public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
+{
+ @Container
+ @ServiceConnection
+ private static final GenericContainer MONGODB = new MongoDBContainer("mongo:6");
+
+ @BeforeEach
+ void resetStorage(
+ @Autowired ChatRoomRepository chatRoomRepository,
+ @Autowired MessageRepository messageRepository)
+ {
+ chatRoomRepository.deleteAll().block();
+ messageRepository.deleteAll().block();
+ }
+
+ @BeforeEach
+ void setUpLogging()
+ {
+ Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
+ MONGODB.followOutput(logConsumer);
+ }
+}