refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code
authorKai Moritz <kai@juplo.de>
Tue, 5 Sep 2023 21:31:40 +0000 (23:31 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 5 Sep 2023 21:31:40 +0000 (23:31 +0200)
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java
src/test/resources/data/mongodb/0001.sh
src/test/resources/data/mongodb/chatRoomTo.json
src/test/resources/data/mongodb/messageTo.json

index 90e4e9c..f6c6b85 100644 (file)
@@ -2,21 +2,20 @@ package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
 
 import de.juplo.kafka.chat.backend.domain.Message;
 import lombok.*;
-import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.index.Indexed;
 import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.Field;
 
 import java.time.LocalDateTime;
 import java.util.UUID;
-import java.util.regex.Matcher;
 
 
 @AllArgsConstructor
 @NoArgsConstructor
 @Getter(AccessLevel.PACKAGE)
 @Setter(AccessLevel.PACKAGE)
-@EqualsAndHashCode(of = { "user", "id" })
-@ToString(of = { "user", "id" })
+@EqualsAndHashCode(of = { "chatRoomId", "user", "id" })
+@ToString(of = { "chatRoomId", "user", "id" })
 @Document
 class MessageTo
 {
@@ -24,6 +23,7 @@ class MessageTo
   private String chatRoomId;
   @Indexed
   private String user;
+  @Field("id")
   @Indexed
   private Long id;
   @Indexed
index c2b014e..3c36dab 100644 (file)
@@ -25,15 +25,13 @@ public class MongoDbStorageConfiguration
       MessageRepository messageRepository,
       ChatBackendProperties properties,
       Clock clock,
-      ShardingStrategy shardingStrategy,
-      ChatRoomServiceFactory chatRoomServiceFactory)
+      ShardingStrategy shardingStrategy)
   {
     return new MongoDbStorageStrategy(
         chatRoomRepository,
         messageRepository,
         clock,
         properties.getChatroomBufferSize(),
-        shardingStrategy,
-        chatRoomServiceFactory);
+        shardingStrategy);
   }
 }
index e64acf2..f7fb685 100644 (file)
@@ -22,7 +22,6 @@ public class MongoDbStorageStrategy implements StorageStrategy
   private final Clock clock;
   private final int bufferSize;
   private final ShardingStrategy shardingStrategy;
-  private final ChatRoomServiceFactory factory;
 
 
   @Override
index 068dd6b..c8eaa66 100644 (file)
@@ -68,8 +68,7 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
           messageRepository,
           clock,
           8,
-          chatRoomId -> 0,
-          messageFlux -> new InMemoryChatRoomService(messageFlux));
+          chatRoomId -> 0);
     }
 
     @Bean
index 014a8be..76199dc 100644 (file)
@@ -1,2 +1,3 @@
 #!/bin/bash
 mongoimport --collection=chatRoomTo --db=test /docker-entrypoint-initdb.d/chatRoomTo.json
+mongoimport --collection=chatRoomTo --db=test /docker-entrypoint-initdb.d/messageTo.json
index ae15034..072d126 100644 (file)
@@ -1,31 +1,6 @@
 {
-  "_id": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "_id": "a9e30ed3-7fd1-4eb9-b174-eebbf6ecfea9",
+  "shard": 0,
   "name": "FOO",
-  "messages": [
-    {
-      "_id": "peter--1",
-      "serial": 0,
-      "time": "2023-01-13T20:43:16.803382151",
-      "text": "Hallo, ich heiße Peter!"
-    },
-    {
-      "_id": "ute--1",
-      "serial": 1,
-      "time": "2023-01-13T20:43:16.804049969",
-      "text": "Ich bin Ute..."
-    },
-    {
-      "_id": "peter--2",
-      "serial": 2,
-      "time": "2023-01-13T20:43:16.804092782",
-      "text": "Willst du mit mir gehen?"
-    },
-    {
-      "_id": "klaus--1",
-      "serial": 3,
-      "time": "2023-01-13T20:43:16.804122604",
-      "text": "Ja? Nein? Vielleicht??"
-    }
-  ],
   "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.ChatRoomTo"
 }
index ae15034..2021e0a 100644 (file)
@@ -1,31 +1,99 @@
 {
-  "_id": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
-  "name": "FOO",
-  "messages": [
-    {
-      "_id": "peter--1",
-      "serial": 0,
-      "time": "2023-01-13T20:43:16.803382151",
-      "text": "Hallo, ich heiße Peter!"
-    },
+  "_id": {
+    "$oid": "64f7952cecf06d750cad4b9c"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "peter",
+  "serial": {
+    "$numberLong": "0"
+  },
+  "time": "2023-01-13T20:43:16.803382151",
+  "text": "Hallo, ich heiße Peter!",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
+}
+{
     {
       "_id": "ute--1",
       "serial": 1,
       "time": "2023-01-13T20:43:16.804049969",
       "text": "Ich bin Ute..."
     },
-    {
-      "_id": "peter--2",
-      "serial": 2,
-      "time": "2023-01-13T20:43:16.804092782",
-      "text": "Willst du mit mir gehen?"
-    },
-    {
-      "_id": "klaus--1",
-      "serial": 3,
-      "time": "2023-01-13T20:43:16.804122604",
-      "text": "Ja? Nein? Vielleicht??"
-    }
-  ],
-  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.ChatRoomTo"
+  "_id": {
+    "$oid": "64f7952cecf06d750cad4b9d"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "ute",
+  "id": {
+    "$numberLong": "1"
+  },
+  "serial": {
+    "$numberLong": "1"
+  },
+  "time": "2023-01-13T20:43:16.804049969",
+  "text": "Ich bin Ute...",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
+}
+{
+  "_id": {
+    "$oid": "64f7952cecf06d750cad4b9e"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "peter",
+  "id": {
+    "$numberLong": "2"
+  },
+  "serial": {
+    "$numberLong": "2"
+  },
+  "time": "2023-01-13T20:43:16.804092782",
+  "text": "Willst du mit mir gehen?",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
+}
+{
+  "_id": {
+    "$oid": "64f7953ddf7a9063e0b1f7dc"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "klaus",
+  "id": {
+    "$numberLong": "1"
+  },
+  "serial": {
+    "$numberLong": "3"
+  },
+  "time": "2023-01-13T20:43:16.804122604",
+  "text": "Ja? Nein? Vielleicht??",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
+}
+{
+  "_id": {
+    "$oid": "64f7953ddf7a9063e0b1f7dd"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "peter",
+  "id": {
+    "$numberLong": "2"
+  },
+  "serial": {
+    "$numberLong": "1"
+  },
+  "time": "2023-09-05T22:52:39.274621568",
+  "text": "Hallo, ich heiße Peter!",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
+}
+{
+  "_id": {
+    "$oid": "64f7953ddf7a9063e0b1f7de"
+  },
+  "chatRoomId": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+  "user": "peter",
+  "id": {
+    "$numberLong": "3"
+  },
+  "serial": {
+    "$numberLong": "2"
+  },
+  "time": "2023-09-05T22:52:41.226211877",
+  "text": "Hallo, ich heiße Peter!",
+  "_class": "de.juplo.kafka.chat.backend.persistence.storage.mongodb.MessageTo"
 }