import de.juplo.kafka.chat.backend.domain.ChatHome;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.InMemoryChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.LocalJsonFilesStorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
+import de.juplo.kafka.chat.backend.persistence.filestorage.FileStorageStrategy;
import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Clock clock,
ObjectMapper mapper)
{
- return new LocalJsonFilesStorageStrategy(
+ return new FileStorageStrategy(
Paths.get(properties.getStorageDirectory()),
clock,
properties.getChatroomBufferSize(),
-package de.juplo.kafka.chat.backend.persistence;
+package de.juplo.kafka.chat.backend.persistence.filestorage;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import de.juplo.kafka.chat.backend.api.MessageTo;
import de.juplo.kafka.chat.backend.domain.ChatRoom;
import de.juplo.kafka.chat.backend.domain.Message;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
@RequiredArgsConstructor
@Slf4j
-public class LocalJsonFilesStorageStrategy implements StorageStrategy
+public class FileStorageStrategy implements StorageStrategy
{
public static final String CHATROOMS_FILENAME = "chatrooms.json";
-package de.juplo.kafka.chat.backend.persistence;
+package de.juplo.kafka.chat.backend.persistence.filestorage;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
-package de.juplo.kafka.chat.backend.persistence;
+package de.juplo.kafka.chat.backend.persistence.inmemory;
import de.juplo.kafka.chat.backend.domain.ChatRoom;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-package de.juplo.kafka.chat.backend.persistence;
+package de.juplo.kafka.chat.backend.persistence.inmemory;
import de.juplo.kafka.chat.backend.domain.Message;
import de.juplo.kafka.chat.backend.domain.ChatRoomService;
@Slf4j
public abstract class AbstractStorageStrategyIT
{
- ChatHome chathome;
+ protected ChatHome chathome;
- abstract StorageStrategy getStorageStrategy();
- abstract Supplier<ChatHomeService> chatHomeServiceSupplier();
+ protected abstract StorageStrategy getStorageStrategy();
+ protected abstract Supplier<ChatHomeService> chatHomeServiceSupplier();
- void start()
+ protected void start()
{
chathome = new ChatHome(chatHomeServiceSupplier().get());
}
- void stop()
+ protected void stop()
{
getStorageStrategy().writeChatrooms(chathome.getChatRooms());
}
@Test
- void testStoreAndRecreate()
+ protected void testStoreAndRecreate()
{
start();
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
+import de.juplo.kafka.chat.backend.persistence.filestorage.FileStorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
@Slf4j
-public class LocalJsonFilesStorageStrategyIT extends AbstractStorageStrategyIT
+public class InMemoryWithFileStorageStrategyIT extends AbstractStorageStrategyIT
{
final static Path path = Paths.get("target","local-json-files");
final Clock clock;
final ObjectMapper mapper;
- final LocalJsonFilesStorageStrategy storageStrategy;
+ final FileStorageStrategy storageStrategy;
- public LocalJsonFilesStorageStrategyIT()
+ public InMemoryWithFileStorageStrategyIT()
{
clock = Clock.systemDefaultZone();
mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- storageStrategy = new LocalJsonFilesStorageStrategy(path, clock, 8, mapper);
+ storageStrategy = new FileStorageStrategy(path, clock, 8, mapper);
}
@Override
- StorageStrategy getStorageStrategy()
+ protected StorageStrategy getStorageStrategy()
{
return storageStrategy;
}
@Override
- Supplier<ChatHomeService> chatHomeServiceSupplier()
+ protected Supplier<ChatHomeService> chatHomeServiceSupplier()
{
return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
}