From b518aa4da4a320f9a72db28f6242765df2e6ddab Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 5 Sep 2023 23:31:40 +0200 Subject: [PATCH] refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code --- .../storage/mongodb/MessageTo.java | 8 +- .../mongodb/MongoDbStorageConfiguration.java | 6 +- .../mongodb/MongoDbStorageStrategy.java | 1 - .../InMemoryWithMongoDbStorageIT.java | 3 +- src/test/resources/data/mongodb/0001.sh | 1 + .../resources/data/mongodb/chatRoomTo.json | 29 +---- .../resources/data/mongodb/messageTo.json | 114 ++++++++++++++---- 7 files changed, 101 insertions(+), 61 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java index 90e4e9cd..f6c6b85d 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java @@ -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 diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageConfiguration.java index c2b014e0..3c36dab1 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageConfiguration.java @@ -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); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java index e64acf29..f7fb685e 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java @@ -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 diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java index 068dd6ba..c8eaa666 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageIT.java @@ -68,8 +68,7 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT messageRepository, clock, 8, - chatRoomId -> 0, - messageFlux -> new InMemoryChatRoomService(messageFlux)); + chatRoomId -> 0); } @Bean diff --git a/src/test/resources/data/mongodb/0001.sh b/src/test/resources/data/mongodb/0001.sh index 014a8be7..76199dcb 100644 --- a/src/test/resources/data/mongodb/0001.sh +++ b/src/test/resources/data/mongodb/0001.sh @@ -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 diff --git a/src/test/resources/data/mongodb/chatRoomTo.json b/src/test/resources/data/mongodb/chatRoomTo.json index ae150343..072d1264 100644 --- a/src/test/resources/data/mongodb/chatRoomTo.json +++ b/src/test/resources/data/mongodb/chatRoomTo.json @@ -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" } diff --git a/src/test/resources/data/mongodb/messageTo.json b/src/test/resources/data/mongodb/messageTo.json index ae150343..2021e0ae 100644 --- a/src/test/resources/data/mongodb/messageTo.json +++ b/src/test/resources/data/mongodb/messageTo.json @@ -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" } -- 2.20.1