refactor: Refined (simplified) `StorageStrategy`
authorKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 21:46:42 +0000 (22:46 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 21:46:42 +0000 (22:46 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java
src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageStrategyIT.java

index 80a46c0..c61f848 100644 (file)
@@ -32,7 +32,7 @@ public class ChatBackendApplication implements WebFluxConfigurer
        @PreDestroy
        public void onExit()
        {
-               storageStrategy.writeChatrooms(chatHome.getChatRooms());
+               storageStrategy.write(chatHome.getChatRooms());
        }
 
        public static void main(String[] args)
index dcf2d9f..87965ab 100644 (file)
@@ -32,7 +32,7 @@ public class ChatBackendConfiguration
       ChatBackendProperties properties)
   {
     return new InMemoryChatHomeService(
-        storageStrategy.readChatrooms(),
+        storageStrategy.read(),
         clock,
         properties.getChatroomBufferSize());
   }
index e7a6f1a..3b8fc84 100644 (file)
@@ -124,6 +124,6 @@ public class ChatBackendController
   @PostMapping("/store")
   public void store()
   {
-    storageStrategy.writeChatrooms(chatHome.getChatRooms());
+    storageStrategy.write(chatHome.getChatRooms());
   }
 }
index 4355f9f..bedd0aa 100644 (file)
@@ -1,15 +1,11 @@
 package de.juplo.kafka.chat.backend.persistence;
 
-import de.juplo.kafka.chat.backend.api.ChatRoomTo;
 import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import de.juplo.kafka.chat.backend.domain.Message;
 import reactor.core.publisher.Flux;
 
 
 public interface StorageStrategy
 {
-  void writeChatrooms(Flux<ChatRoom> chatroomFlux);
-  Flux<ChatRoom> readChatrooms();
-  void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux);
-  Flux<Message> readMessages(ChatRoomTo chatroomTo);
+  void write(Flux<ChatRoom> chatroomFlux);
+  Flux<ChatRoom> read();
 }
index e670970..1fd307f 100644 (file)
@@ -36,7 +36,7 @@ public class FilesStorageStrategy implements StorageStrategy
 
 
   @Override
-  public void writeChatrooms(Flux<ChatRoom> chatroomFlux)
+  public void write(Flux<ChatRoom> chatroomFlux)
   {
     Path path = chatroomsPath();
     log.info("Writing chatrooms to {}", path);
@@ -96,7 +96,7 @@ public class FilesStorageStrategy implements StorageStrategy
   }
 
   @Override
-  public Flux<ChatRoom> readChatrooms()
+  public Flux<ChatRoom> read()
   {
     JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class);
     return Flux
@@ -110,7 +110,6 @@ public class FilesStorageStrategy implements StorageStrategy
             bufferSize));
   }
 
-  @Override
   public void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux)
   {
     Path path = chatroomPath(chatroomTo);
@@ -169,7 +168,6 @@ public class FilesStorageStrategy implements StorageStrategy
     }
   }
 
-  @Override
   public Flux<Message> readMessages(ChatRoomTo chatroomTo)
   {
     JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
index b2cbde2..549faad 100644 (file)
@@ -29,7 +29,7 @@ public abstract class AbstractStorageStrategyIT
 
   protected void stop()
   {
-    getStorageStrategy().writeChatrooms(chathome.getChatRooms());
+    getStorageStrategy().write(chathome.getChatRooms());
   }
 
   @Test
index 4df5944..218b186 100644 (file)
@@ -53,7 +53,7 @@ public class InMemoryWithFilesStorageStrategyIT extends AbstractStorageStrategyI
   @Override
   protected Supplier<ChatHomeService> chatHomeServiceSupplier()
   {
-    return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
+    return () -> new InMemoryChatHomeService(getStorageStrategy().read(), clock, 8);
   }
 
   @BeforeEach