refactor: Renamed `ChatRoomService` into `ChatMessageService` -- ALIGNE
authorKai Moritz <kai@juplo.de>
Mon, 11 Sep 2023 14:19:22 +0000 (16:19 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 27 Jan 2024 14:16:22 +0000 (15:16 +0100)
src/main/java/de/juplo/kafka/chat/backend/domain/ChatMessageService.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryChatMessageService.java
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChatRoomChannel.java
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatMessageService.java
src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java
src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java

index 374a442..640dc9e 100644 (file)
@@ -6,7 +6,7 @@ import reactor.core.publisher.Mono;
 import java.time.LocalDateTime;
 
 
-public interface ChatRoomService
+public interface ChatMessageService
 {
   Mono<Message> persistMessage(
       Message.MessageKey key,
index 18ca0bf..d783eb4 100644 (file)
@@ -19,7 +19,7 @@ public class ChatRoomData
 {
   public final static Pattern VALID_USER = Pattern.compile("^[a-z0-9-]{2,}$");
 
-  private final ChatRoomService service;
+  private final ChatMessageService service;
   private final Clock clock;
   private final int bufferSize;
   private Sinks.Many<Message> sink;
@@ -27,7 +27,7 @@ public class ChatRoomData
 
   public ChatRoomData(
       Clock clock,
-      ChatRoomService service,
+      ChatMessageService service,
       int bufferSize)
   {
     log.info("Created ChatRoom with buffer-size {}", bufferSize);
@@ -78,7 +78,7 @@ public class ChatRoomData
   }
 
 
-  public ChatRoomService getChatRoomService()
+  public ChatMessageService getChatRoomService()
   {
     return service;
   }
index a4fcec8..8d89aeb 100644 (file)
@@ -1,7 +1,7 @@
 package de.juplo.kafka.chat.backend.implementation.inmemory;
 
+import de.juplo.kafka.chat.backend.domain.ChatMessageService;
 import de.juplo.kafka.chat.backend.domain.Message;
-import de.juplo.kafka.chat.backend.domain.ChatRoomService;
 import lombok.extern.slf4j.Slf4j;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -11,12 +11,12 @@ import java.util.LinkedHashMap;
 
 
 @Slf4j
-public class InMemoryChatRoomService implements ChatRoomService
+public class InMemoryChatMessageService implements ChatMessageService
 {
   private final LinkedHashMap<Message.MessageKey, Message> messages;
 
 
-  public InMemoryChatRoomService(Flux<Message> messageFlux)
+  public InMemoryChatMessageService(Flux<Message> messageFlux)
   {
     log.debug("Creating InMemoryChatRoomService");
     messages = new LinkedHashMap<>();
index da01a54..30a181e 100644 (file)
@@ -73,7 +73,7 @@ public class SimpleChatHomeService implements ChatHomeService
               info.getId(),
               new ChatRoomData(
                   clock,
-                  new InMemoryChatRoomService(messageFlux),
+                  new InMemoryChatMessageService(messageFlux),
                   bufferSize));
         });
     this.clock = clock;
@@ -85,7 +85,7 @@ public class SimpleChatHomeService implements ChatHomeService
   public Mono<ChatRoomInfo> createChatRoom(UUID id, String name)
   {
     log.info("Creating ChatRoom with buffer-size {}", bufferSize);
-    ChatRoomService service = new InMemoryChatRoomService(Flux.empty());
+    ChatMessageService service = new InMemoryChatMessageService(Flux.empty());
     ChatRoomInfo chatRoomInfo = new ChatRoomInfo(id, name, shard);
     this.chatRoomInfo.put(id, chatRoomInfo);
     ChatRoomData chatRoomData = new ChatRoomData(clock, service, bufferSize);
index 4143616..d94bc65 100644 (file)
@@ -292,7 +292,7 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener
         chatRoomId,
         partition,
         bufferSize);
-    KafkaChatRoomService service = new KafkaChatRoomService(this, chatRoomId);
+    KafkaChatMessageService service = new KafkaChatMessageService(this, chatRoomId);
     ChatRoomData chatRoomData = new ChatRoomData(
         clock,
         service,
@@ -309,7 +309,7 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener
   {
     UUID id = chatRoomInfo.getId();
     log.info("Creating ChatRoom {} with buffer-size {}", id, bufferSize);
-    KafkaChatRoomService service = new KafkaChatRoomService(this, id);
+    KafkaChatMessageService service = new KafkaChatMessageService(this, id);
     ChatRoomData chatRoomData = new ChatRoomData(clock, service, bufferSize);
     putChatRoom(
         chatRoomInfo.getId(),
@@ -329,8 +329,8 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener
     Message message = new Message(key, offset, timestamp, chatMessageTo.getText());
 
     ChatRoomData chatRoomData = this.chatRoomData[partition].get(chatRoomId);
-    KafkaChatRoomService kafkaChatRoomService =
-        (KafkaChatRoomService) chatRoomData.getChatRoomService();
+    KafkaChatMessageService kafkaChatRoomService =
+        (KafkaChatMessageService) chatRoomData.getChatRoomService();
 
     kafkaChatRoomService.persistMessage(message);
   }
index 084798c..df9ee73 100644 (file)
@@ -1,6 +1,6 @@
 package de.juplo.kafka.chat.backend.implementation.kafka;
 
-import de.juplo.kafka.chat.backend.domain.ChatRoomService;
+import de.juplo.kafka.chat.backend.domain.ChatMessageService;
 import de.juplo.kafka.chat.backend.domain.Message;import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import reactor.core.publisher.Flux;
@@ -13,7 +13,7 @@ import java.util.UUID;
 
 @RequiredArgsConstructor
 @Slf4j
-public class KafkaChatRoomService implements ChatRoomService
+public class KafkaChatMessageService implements ChatMessageService
 {
   private final ChatRoomChannel chatRoomChannel;
   private final UUID chatRoomId;
index 946498a..1478e7c 100644 (file)
@@ -36,7 +36,7 @@ public class ChatBackendControllerTest
   @MockBean
   ChatHomeService chatHomeService;
   @MockBean
-  ChatRoomService chatRoomService;
+  ChatMessageService chatMessageService;
 
   @Test
   @DisplayName("Assert expected problem-details for unknown chatroom on GET /list/{chatroomId}")
@@ -174,7 +174,7 @@ public class ChatBackendControllerTest
     String textMutatedMessage = "Mutated!";
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     when(chatHomeService.getChatRoomData(eq(chatroomId))).thenReturn(Mono.just(chatRoomData));
     Message existingMessage = new Message(
@@ -182,10 +182,10 @@ public class ChatBackendControllerTest
         serialNumberExistingMessage,
         timeExistingMessage,
         textExistingMessage);
-    when(chatRoomService.getMessage(any(Message.MessageKey.class)))
+    when(chatMessageService.getMessage(any(Message.MessageKey.class)))
         .thenReturn(Mono.just(existingMessage));
     // Needed for readable error-reports, in case of a bug that leads to according unwanted call
-    when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
+    when(chatMessageService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
         .thenReturn(Mono.just(mock(Message.class)));
 
     // When
@@ -209,7 +209,7 @@ public class ChatBackendControllerTest
         .jsonPath("$.existingMessage.user").isEqualTo(user)
         .jsonPath("$.existingMessage.text").isEqualTo(textExistingMessage)
         .jsonPath("$.mutatedText").isEqualTo(textMutatedMessage);
-    verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
+    verify(chatMessageService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
   }
 
   @Test
@@ -224,14 +224,14 @@ public class ChatBackendControllerTest
     String textMessage = "Hallo Welt";
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     when(chatHomeService.getChatRoomData(any(UUID.class)))
         .thenReturn(Mono.just(chatRoomData));
-    when(chatRoomService.getMessage(any(Message.MessageKey.class)))
+    when(chatMessageService.getMessage(any(Message.MessageKey.class)))
         .thenReturn(Mono.empty());
     // Needed for readable error-reports, in case of a bug that leads to according unwanted call
-    when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
+    when(chatMessageService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
         .thenReturn(Mono.just(mock(Message.class)));
 
     // When
@@ -250,7 +250,7 @@ public class ChatBackendControllerTest
         .expectBody()
         .jsonPath("$.type").isEqualTo("/problem/invalid-username")
         .jsonPath("$.username").isEqualTo(user);
-    verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
+    verify(chatMessageService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
   }
 
   @Test
index 790482f..3c7d1dd 100644 (file)
@@ -22,15 +22,15 @@ public class ChatRoomDataTest
     // Given
     String user = "foo";
     Long messageId = 1l;
-    ChatRoomService chatRoomService = mock(ChatRoomService.class);
+    ChatMessageService chatMessageService = mock(ChatMessageService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     Message.MessageKey key = Message.MessageKey.of(user, messageId);
     LocalDateTime timestamp = LocalDateTime.now();
     Message message = new Message(key, 0l, timestamp, "Bar");
-    when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
 
     // When
     Mono<Message> mono = chatRoomData.getMessage(user, messageId);
@@ -46,12 +46,12 @@ public class ChatRoomDataTest
     // Given
     String user = "foo";
     Long messageId = 1l;
-    ChatRoomService chatRoomService = mock(ChatRoomService.class);
+    ChatMessageService chatMessageService = mock(ChatMessageService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
-    when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty());
+    when(chatMessageService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty());
 
     // When
     Mono<Message> mono = chatRoomData.getMessage(user, messageId);
@@ -67,18 +67,18 @@ public class ChatRoomDataTest
     // Given
     String user = "foo";
     Long messageId = 1l;
-    ChatRoomService chatRoomService = mock(ChatRoomService.class);
+    ChatMessageService chatMessageService = mock(ChatMessageService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     Message.MessageKey key = Message.MessageKey.of(user, messageId);
     Clock now = Clock.fixed(Instant.now(), ZoneId.systemDefault());
     LocalDateTime timestamp = LocalDateTime.now(now);
     String messageText = "Bar";
     Message message = new Message(key, 0l, timestamp, messageText);
-    when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty());
-    when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty());
+    when(chatMessageService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
 
     // When
     Mono<Message> mono = chatRoomData.addMessage(messageId, user, messageText);
@@ -94,18 +94,18 @@ public class ChatRoomDataTest
     // Given
     String user = "foo";
     Long messageId = 1l;
-    ChatRoomService chatRoomService = mock(ChatRoomService.class);
+    ChatMessageService chatMessageService = mock(ChatMessageService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     Message.MessageKey key = Message.MessageKey.of(user, messageId);
     Clock now = Clock.fixed(Instant.now(), ZoneId.systemDefault());
     LocalDateTime timestamp = LocalDateTime.now(now);
     String messageText = "Bar";
     Message message = new Message(key, 0l, timestamp, messageText);
-    when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
-    when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
 
     // When
     Mono<Message> mono = chatRoomData.addMessage(messageId, user, messageText);
@@ -121,10 +121,10 @@ public class ChatRoomDataTest
     // Given
     String user = "foo";
     Long messageId = 1l;
-    ChatRoomService chatRoomService = mock(ChatRoomService.class);
+    ChatMessageService chatMessageService = mock(ChatMessageService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
         Clock.systemDefaultZone(),
-        chatRoomService,
+        chatMessageService,
         8);
     Message.MessageKey key = Message.MessageKey.of(user, messageId);
     Clock now = Clock.fixed(Instant.now(), ZoneId.systemDefault());
@@ -132,8 +132,8 @@ public class ChatRoomDataTest
     String messageText = "Bar";
     String mutatedText = "Boom!";
     Message message = new Message(key, 0l, timestamp, messageText);
-    when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
-    when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message));
+    when(chatMessageService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message));
 
     // When
     Mono<Message> mono = chatRoomData.addMessage(messageId, user, mutatedText);