From: Kai Moritz Date: Mon, 9 Jan 2023 21:23:35 +0000 (+0100) Subject: refactor: Moved classes in package `persistence` in sub-packages -- Rename X-Git-Tag: wip-sharding~48 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5970768c9609c7b2b0bd087cef2a88db2eb60752;p=demos%2Fkafka%2Fchat refactor: Moved classes in package `persistence` in sub-packages -- Rename --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java index 65708628..c4a36e32 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -3,8 +3,8 @@ package de.juplo.kafka.chat.backend; 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; @@ -42,7 +42,7 @@ public class ChatBackendConfiguration Clock clock, ObjectMapper mapper) { - return new LocalJsonFilesStorageStrategy( + return new FileStorageStrategy( Paths.get(properties.getStorageDirectory()), clock, properties.getChatroomBufferSize(), diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/FileStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/FileStorageStrategy.java index 7b490bf6..433e5f1f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/FileStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/FileStorageStrategy.java @@ -1,4 +1,4 @@ -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; @@ -7,6 +7,8 @@ import de.juplo.kafka.chat.backend.api.ChatRoomTo; 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; @@ -22,7 +24,7 @@ import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; @RequiredArgsConstructor @Slf4j -public class LocalJsonFilesStorageStrategy implements StorageStrategy +public class FileStorageStrategy implements StorageStrategy { public static final String CHATROOMS_FILENAME = "chatrooms.json"; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/JsonFilePublisher.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/JsonFilePublisher.java index e502539e..3824898f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/JsonFilePublisher.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/filestorage/JsonFilePublisher.java @@ -1,4 +1,4 @@ -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; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java index b2f94ec3..4eea6451 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java @@ -1,4 +1,4 @@ -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; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomService.java index f789d359..5a5f2b25 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomService.java @@ -1,4 +1,4 @@ -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; diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java index 524e6f10..b2cbde2b 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java @@ -16,24 +16,24 @@ import static pl.rzrz.assertj.reactor.Assertions.*; @Slf4j public abstract class AbstractStorageStrategyIT { - ChatHome chathome; + protected ChatHome chathome; - abstract StorageStrategy getStorageStrategy(); - abstract Supplier chatHomeServiceSupplier(); + protected abstract StorageStrategy getStorageStrategy(); + protected abstract Supplier 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(); diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFileStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFileStorageStrategyIT.java index 515942c9..7efa081a 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFileStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFileStorageStrategyIT.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; 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; @@ -16,34 +18,34 @@ import java.util.function.Supplier; @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 chatHomeServiceSupplier() + protected Supplier chatHomeServiceSupplier() { return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8); }