refactor: Cleaned up code
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 12:05:21 +0000 (13:05 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 16:27:11 +0000 (17:27 +0100)
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/storage/mongodb/MongoDbStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java

index 8d89aeb..8f3e495 100644 (file)
@@ -18,7 +18,7 @@ public class InMemoryChatMessageService implements ChatMessageService
 
   public InMemoryChatMessageService(Flux<Message> messageFlux)
   {
-    log.debug("Creating InMemoryChatRoomService");
+    log.debug("Creating InMemoryChatMessageService");
     messages = new LinkedHashMap<>();
     messageFlux.subscribe(message -> messages.put(message.getKey(), message));
   }
index 5ed039e..93593d8 100644 (file)
@@ -40,7 +40,6 @@ public class SimpleChatHomeService implements ChatHomeService
       Clock clock,
       int bufferSize)
   {
-;
     this.shard = shard;
     log.info("Created {}", this);
 
index ad57da5..1b5803a 100644 (file)
@@ -17,12 +17,8 @@ public class MongoDbStorageConfiguration
   @Bean
   public StorageStrategy storageStrategy(
       ChatRoomRepository chatRoomRepository,
-      MessageRepository messageRepository,
-      ShardingStrategy shardingStrategy)
+      MessageRepository messageRepository)
   {
-    return new MongoDbStorageStrategy(
-        chatRoomRepository,
-        messageRepository,
-        shardingStrategy);
+    return new MongoDbStorageStrategy(chatRoomRepository, messageRepository);
   }
 }
index 1428119..fb04039 100644 (file)
@@ -2,7 +2,6 @@ package de.juplo.kafka.chat.backend.storage.mongodb;
 
 import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
 import de.juplo.kafka.chat.backend.domain.Message;
-import de.juplo.kafka.chat.backend.implementation.ShardingStrategy;
 import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -17,7 +16,6 @@ public class MongoDbStorageStrategy implements StorageStrategy
 {
   private final ChatRoomRepository chatRoomRepository;
   private final MessageRepository messageRepository;
-  private final ShardingStrategy shardingStrategy;
 
 
   @Override
@@ -25,7 +23,7 @@ public class MongoDbStorageStrategy implements StorageStrategy
   {
     return chatRoomInfoFlux
         .map(ChatRoomTo::from)
-        .map(chatroomTo -> chatRoomRepository.save(chatroomTo))
+        .map(chatRoomRepository::save)
         .map(ChatRoomTo::toChatRoomInfo);
   }
 
@@ -34,11 +32,7 @@ public class MongoDbStorageStrategy implements StorageStrategy
   {
     return Flux
         .fromIterable(chatRoomRepository.findAll())
-        .map(chatRoomTo ->
-        {
-          UUID chatRoomId = UUID.fromString(chatRoomTo.getId());
-          return new ChatRoomInfo(chatRoomId, chatRoomTo.getName(), null);
-        });
+        .map(ChatRoomTo::toChatRoomInfo);
   }
 
   @Override
@@ -46,7 +40,7 @@ public class MongoDbStorageStrategy implements StorageStrategy
   {
     return messageFlux
         .map(message -> MessageTo.from(chatRoomId, message))
-        .map(messageTo -> messageRepository.save(messageTo))
+        .map(messageRepository::save)
         .map(MessageTo::toMessage);
   }
 
@@ -55,6 +49,6 @@ public class MongoDbStorageStrategy implements StorageStrategy
   {
     return Flux
         .fromIterable(messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()))
-        .map(messageTo -> messageTo.toMessage());
+        .map(MessageTo::toMessage);
   }
 }
index 6937736..c7ede36 100644 (file)
@@ -37,7 +37,7 @@ class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationIT
        @DynamicPropertySource
        static void addMongoPortProperty(DynamicPropertyRegistry registry)
        {
-               registry.add("spring.data.mongodb.port", () -> CONTAINER.getMappedPort(27017));
+               registry.add("spring.data.mongodb.port", () -> CONTAINER.getMappedPort(MONGODB_PORT));
        }
 
        @BeforeEach
index 43a0900..7566f52 100644 (file)
@@ -60,13 +60,9 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
     @Bean
     MongoDbStorageStrategy storageStrategy(
         ChatRoomRepository chatRoomRepository,
-        MessageRepository messageRepository,
-        Clock clock)
+        MessageRepository messageRepository)
     {
-      return new MongoDbStorageStrategy(
-          chatRoomRepository,
-          messageRepository,
-          chatRoomId -> 0);
+      return new MongoDbStorageStrategy(chatRoomRepository, messageRepository);
     }
 
     @Bean
@@ -80,8 +76,7 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
 
   @Container
   private static final GenericContainer CONTAINER =
-      new GenericContainer("mongo:6")
-          .withExposedPorts(MONGODB_PORT);
+      new GenericContainer("mongo:6").withExposedPorts(MONGODB_PORT);
 
   public static class DataSourceInitializer
       implements ApplicationContextInitializer<ConfigurableApplicationContext>