From 0a8b2d30befef01b62d1e29b8af0121ff487ad01 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 3 Sep 2023 19:54:46 +0200 Subject: [PATCH] refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code --- .../backend/api/ChatBackendController.java | 8 ++--- .../kafka/chat/backend/domain/ChatHome.java | 4 +-- .../chat/backend/domain/ChatRoomData.java | 4 +-- .../backend/persistence/StorageStrategy.java | 6 ++-- .../persistence/inmemory/ShardedChatHome.java | 4 +-- .../persistence/inmemory/SimpleChatHome.java | 16 +++++----- .../persistence/kafka/ChatRoomChannel.java | 30 +++++++++---------- .../persistence/kafka/KafkaChatHome.java | 6 ++-- .../storage/files/FilesStorageStrategy.java | 8 ++--- .../storage/mongodb/ChatRoomTo.java | 6 ++-- .../mongodb/MongoDbStorageStrategy.java | 8 ++--- .../NoStorageStorageConfiguration.java | 6 ++-- .../api/ChatBackendControllerTest.java | 8 ++--- .../chat/backend/domain/ChatHomeTest.java | 4 +-- .../domain/ChatHomeWithShardsTest.java | 2 +- .../chat/backend/domain/ChatRoomDataTest.java | 22 +++++++------- .../AbstractStorageStrategyIT.java | 6 ++-- 17 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java index f41f45f6..a400119f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.api; import de.juplo.kafka.chat.backend.domain.ChatHome; -import de.juplo.kafka.chat.backend.domain.ChatRoom; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import lombok.RequiredArgsConstructor; import org.springframework.http.codec.ServerSentEvent; @@ -69,7 +69,7 @@ public class ChatBackendController } private Mono put( - ChatRoom chatroom, + ChatRoomData chatroom, String username, Long messageId, String text) @@ -96,7 +96,7 @@ public class ChatBackendController } private Mono get( - ChatRoom chatroom, + ChatRoomData chatroom, String username, Long messageId) { @@ -114,7 +114,7 @@ public class ChatBackendController .flatMapMany(chatroom -> listen(chatroom)); } - private Flux> listen(ChatRoom chatroom) + private Flux> listen(ChatRoomData chatroom) { return chatroom .listen() diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java index e4d92dbb..7b97d553 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java @@ -10,7 +10,7 @@ public interface ChatHome { Mono createChatRoom(UUID id, String name); - Mono getChatRoom(UUID id); + Mono getChatRoom(UUID id); - Flux getChatRooms(); + Flux getChatRooms(); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java index 873e58e7..a5667c18 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java @@ -13,7 +13,7 @@ import java.util.regex.Pattern; @Slf4j -public class ChatRoom +public class ChatRoomData { public final static Pattern VALID_USER = Pattern.compile("^[a-z0-9-]{2,}$"); @@ -23,7 +23,7 @@ public class ChatRoom private Sinks.Many sink; - public ChatRoom( + public ChatRoomData( Clock clock, ChatRoomService service, int bufferSize) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java index bedd0aac..96d1eb7b 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java @@ -1,11 +1,11 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.domain.ChatRoom; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import reactor.core.publisher.Flux; public interface StorageStrategy { - void write(Flux chatroomFlux); - Flux read(); + void write(Flux chatroomFlux); + Flux read(); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java index c6aff1e3..653c64aa 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java @@ -48,7 +48,7 @@ public class ShardedChatHome implements ChatHome } @Override - public Mono getChatRoom(UUID id) + public Mono getChatRoom(UUID id) { int shard = selectShard(id); return chatHomes[shard] == null @@ -64,7 +64,7 @@ public class ShardedChatHome implements ChatHome } @Override - public Flux getChatRooms() + public Flux getChatRooms() { return Flux .fromIterable(ownedShards) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java index c2d25b20..9112fb92 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java @@ -13,14 +13,14 @@ import java.util.*; public class SimpleChatHome implements ChatHome { private final Integer shard; - private final Map chatRooms; + private final Map chatRooms; private final Clock clock; private final int bufferSize; public SimpleChatHome( - Flux chatroomFlux, + Flux chatroomFlux, Clock clock, int bufferSize) { @@ -29,7 +29,7 @@ public class SimpleChatHome implements ChatHome public SimpleChatHome( Integer shard, - Flux chatroomFlux, + Flux chatroomFlux, Clock clock, int bufferSize) { @@ -65,13 +65,13 @@ public class SimpleChatHome implements ChatHome { log.info("Creating ChatRoom with buffer-size {}", bufferSize); ChatRoomService service = new InMemoryChatRoomService(Flux.empty()); - ChatRoom chatRoom = new ChatRoom(id, name, shard, clock, service, bufferSize); - chatRooms.put(id, chatRoom); - return Mono.just(chatRoom); + ChatRoomData chatRoomData = new ChatRoomData(id, name, shard, clock, service, bufferSize); + chatRooms.put(id, chatRoomData); + return Mono.just(chatRoomData); } @Override - public Mono getChatRoom(UUID id) + public Mono getChatRoom(UUID id) { return Mono .justOrEmpty(chatRooms.get(id)) @@ -79,7 +79,7 @@ public class SimpleChatHome implements ChatHome } @Override - public Flux getChatRooms() + public Flux getChatRooms() { return Flux.fromIterable(chatRooms.values()); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java index 234554eb..6ce85d1b 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java @@ -35,7 +35,7 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener private final boolean[] isShardOwned; private final long[] currentOffset; private final long[] nextOffset; - private final Map[] chatrooms; + private final Map[] chatrooms; private boolean running; @Getter @@ -281,14 +281,14 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener { log.info("Loading ChatRoom {} with buffer-size {}", chatRoomId, bufferSize); KafkaChatRoomService service = new KafkaChatRoomService(this, chatRoomId); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( chatRoomId, createChatRoomRequestTo.getName(), partition, clock, service, bufferSize); - putChatRoom(chatRoom); + putChatRoom(chatRoomData); } @@ -299,8 +299,8 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener int shard = chatRoomInfo.getShard(); log.info("Creating ChatRoom {} with buffer-size {}", id, bufferSize); KafkaChatRoomService service = new KafkaChatRoomService(this, id); - ChatRoom chatRoom = new ChatRoom(id, name, shard, clock, service, bufferSize); - putChatRoom(chatRoom); + ChatRoomData chatRoomData = new ChatRoomData(id, name, shard, clock, service, bufferSize); + putChatRoom(chatRoomData); } private void loadChatMessage( @@ -313,9 +313,9 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener Message.MessageKey key = Message.MessageKey.of(chatMessageTo.getUser(), chatMessageTo.getId()); Message message = new Message(key, offset, timestamp, chatMessageTo.getText()); - ChatRoom chatRoom = chatrooms[partition].get(chatRoomId); + ChatRoomData chatRoomData = chatrooms[partition].get(chatRoomId); KafkaChatRoomService kafkaChatRoomService = - (KafkaChatRoomService) chatRoom.getChatRoomService(); + (KafkaChatRoomService) chatRoomData.getChatRoomService(); kafkaChatRoomService.persistMessage(message); } @@ -338,22 +338,22 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener } - private void putChatRoom(ChatRoom chatRoom) + private void putChatRoom(ChatRoomData chatRoomData) { - Integer partition = chatRoom.getShard(); - UUID chatRoomId = chatRoom.getId(); + Integer partition = chatRoomData.getShard(); + UUID chatRoomId = chatRoomData.getId(); if (chatrooms[partition].containsKey(chatRoomId)) { - log.warn("Ignoring existing chat-room: " + chatRoom); + log.warn("Ignoring existing chat-room: " + chatRoomData); } else { log.info( "Adding new chat-room to partition {}: {}", partition, - chatRoom); + chatRoomData); - chatrooms[partition].put(chatRoomId, chatRoom); + chatrooms[partition].put(chatRoomId, chatRoomData); } } @@ -365,7 +365,7 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener .toArray(); } - Mono getChatRoom(int shard, UUID id) + Mono getChatRoom(int shard, UUID id) { if (loadInProgress) { @@ -380,7 +380,7 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener return Mono.justOrEmpty(chatrooms[shard].get(id)); } - Flux getChatRooms() + Flux getChatRooms() { return Flux .fromStream(IntStream.range(0, numShards).mapToObj(i -> Integer.valueOf(i))) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHome.java index 06228396..68cad73e 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHome.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.kafka; import de.juplo.kafka.chat.backend.domain.ChatHome; -import de.juplo.kafka.chat.backend.domain.ChatRoom; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.domain.ChatRoomInfo; import de.juplo.kafka.chat.backend.domain.UnknownChatroomException; import lombok.RequiredArgsConstructor; @@ -30,7 +30,7 @@ public class KafkaChatHome implements ChatHome } @Override - public Mono getChatRoom(UUID id) + public Mono getChatRoom(UUID id) { int shard = selectShard(id); return chatRoomChannel @@ -48,7 +48,7 @@ public class KafkaChatHome implements ChatHome } @Override - public Flux getChatRooms() + public Flux getChatRooms() { return chatRoomChannel.getChatRooms(); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java index 025e3aef..fb6e3446 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java @@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo; import de.juplo.kafka.chat.backend.api.MessageTo; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.persistence.inmemory.ShardingStrategy; -import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.domain.Message; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import lombok.RequiredArgsConstructor; @@ -39,7 +39,7 @@ public class FilesStorageStrategy implements StorageStrategy @Override - public void write(Flux chatroomFlux) + public void write(Flux chatroomFlux) { Path path = chatroomsPath(); log.info("Writing chatrooms to {}", path); @@ -99,7 +99,7 @@ public class FilesStorageStrategy implements StorageStrategy } @Override - public Flux read() + public Flux read() { JavaType type = mapper.getTypeFactory().constructType(ChatRoomInfoTo.class); return Flux @@ -109,7 +109,7 @@ public class FilesStorageStrategy implements StorageStrategy { UUID chatRoomId = infoTo.getId(); int shard = shardingStrategy.selectShard(chatRoomId); - return new ChatRoom( + return new ChatRoomData( infoTo.getId(), infoTo.getName(), shard, diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/ChatRoomTo.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/ChatRoomTo.java index 1ad8d178..6b5ea878 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/ChatRoomTo.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/ChatRoomTo.java @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend.persistence.storage.mongodb; -import de.juplo.kafka.chat.backend.domain.ChatRoom; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import lombok.*; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -22,7 +22,9 @@ public class ChatRoomTo private String name; private List messages; - public static ChatRoomTo from(ChatRoom chatroom) + public static ChatRoomTo from( + ChatRoomInfo chatRoomInfo, + ChatRoomData chatroom) { return new ChatRoomTo( chatroom.getId().toString(), 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 d3a18bc2..b9c7fb23 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 @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.storage.mongodb; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.persistence.inmemory.ShardingStrategy; -import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import de.juplo.kafka.chat.backend.persistence.storage.files.ChatRoomServiceFactory; import lombok.RequiredArgsConstructor; @@ -24,7 +24,7 @@ public class MongoDbStorageStrategy implements StorageStrategy @Override - public void write(Flux chatroomFlux) + public void write(Flux chatroomFlux) { chatroomFlux .map(ChatRoomTo::from) @@ -32,7 +32,7 @@ public class MongoDbStorageStrategy implements StorageStrategy } @Override - public Flux read() + public Flux read() { return Flux .fromIterable(repository.findAll()) @@ -40,7 +40,7 @@ public class MongoDbStorageStrategy implements StorageStrategy { UUID chatRoomId = UUID.fromString(chatRoomTo.getId()); int shard = shardingStrategy.selectShard(chatRoomId); - return new ChatRoom( + return new ChatRoomData( chatRoomId, chatRoomTo.getName(), shard, diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/nostorage/NoStorageStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/nostorage/NoStorageStorageConfiguration.java index ffed2992..dd2223ca 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/nostorage/NoStorageStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/nostorage/NoStorageStorageConfiguration.java @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend.persistence.storage.nostorage; -import de.juplo.kafka.chat.backend.domain.ChatRoom; +import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -29,10 +29,10 @@ public class NoStorageStorageConfiguration return new StorageStrategy() { @Override - public void write(Flux chatroomFlux) {} + public void write(Flux chatroomFlux) {} @Override - public Flux read() + public Flux read() { return Flux.empty(); } diff --git a/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java b/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java index 9b8b09f8..63ab7d6f 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java @@ -170,13 +170,13 @@ public class ChatBackendControllerTest LocalDateTime timeExistingMessage = LocalDateTime.parse(timeExistingMessageAsString); String textExistingMessage = "Existing"; String textMutatedMessage = "Mutated!"; - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( chatroomId, "Test-ChatRoom", 0, Clock.systemDefaultZone(), chatRoomService, 8); - when(chatHome.getChatRoom(eq(chatroomId))).thenReturn(Mono.just(chatRoom)); + when(chatHome.getChatRoom(eq(chatroomId))).thenReturn(Mono.just(chatRoomData)); Message existingMessage = new Message( key, serialNumberExistingMessage, @@ -222,14 +222,14 @@ public class ChatBackendControllerTest Long messageId = 66l; Message.MessageKey key = Message.MessageKey.of(user, messageId); String textMessage = "Hallo Welt"; - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( chatroomId, "Test-ChatRoom", 0, Clock.systemDefaultZone(), chatRoomService, 8); when(chatHome.getChatRoom(any(UUID.class))) - .thenReturn(Mono.just(chatRoom)); + .thenReturn(Mono.just(chatRoomData)); when(chatRoomService.getMessage(any(Message.MessageKey.class))) .thenReturn(Mono.empty()); // Needed for readable error-reports, in case of a bug that leads to according unwanted call diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeTest.java index 2a995ef4..ad7fe95d 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeTest.java @@ -29,7 +29,7 @@ public abstract class ChatHomeTest UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7"); // When - Mono mono = Mono + Mono mono = Mono .defer(() -> chatHome.getChatRoom(chatRoomId)) .log("testGetExistingChatroom") .retryWhen(Retry @@ -48,7 +48,7 @@ public abstract class ChatHomeTest UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17"); // When - Mono mono = Mono + Mono mono = Mono .defer(() -> chatHome.getChatRoom(chatRoomId)) .log("testGetNonExistentChatroom") .retryWhen(Retry diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTest.java index eebeea1e..67754566 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTest.java @@ -26,7 +26,7 @@ public abstract class ChatHomeWithShardsTest extends ChatHomeTest UUID chatRoomId = UUID.fromString("4e7246a6-29ae-43ea-b56f-669c3481ac19"); // When - Mono mono = Mono + Mono mono = Mono .defer(() -> chatHome.getChatRoom(chatRoomId)) .log("testGetChatroomForNotOwnedShard") .retryWhen(Retry diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java index 822ffe77..171a9da5 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java @@ -14,7 +14,7 @@ import static org.mockito.Mockito.*; import static pl.rzrz.assertj.reactor.Assertions.assertThat; -public class ChatRoomTest +public class ChatRoomDataTest { @Test @DisplayName("Assert, that Mono emits expected message, if it exists") @@ -24,7 +24,7 @@ public class ChatRoomTest String user = "foo"; Long messageId = 1l; ChatRoomService chatRoomService = mock(ChatRoomService.class); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( UUID.randomUUID(), "Foo", 0, @@ -37,7 +37,7 @@ public class ChatRoomTest when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.just(message)); // When - Mono mono = chatRoom.getMessage(user, messageId); + Mono mono = chatRoomData.getMessage(user, messageId); // Then assertThat(mono).emitsExactly(message); @@ -51,7 +51,7 @@ public class ChatRoomTest String user = "foo"; Long messageId = 1l; ChatRoomService chatRoomService = mock(ChatRoomService.class); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( UUID.randomUUID(), "Foo", 0, @@ -61,7 +61,7 @@ public class ChatRoomTest when(chatRoomService.getMessage(any(Message.MessageKey.class))).thenReturn(Mono.empty()); // When - Mono mono = chatRoom.getMessage(user, messageId); + Mono mono = chatRoomData.getMessage(user, messageId); // Then assertThat(mono).emitsCount(0); @@ -75,7 +75,7 @@ public class ChatRoomTest String user = "foo"; Long messageId = 1l; ChatRoomService chatRoomService = mock(ChatRoomService.class); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( UUID.randomUUID(), "Foo", 0, @@ -91,7 +91,7 @@ public class ChatRoomTest when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message)); // When - Mono mono = chatRoom.addMessage(messageId, user, messageText); + Mono mono = chatRoomData.addMessage(messageId, user, messageText); // Then assertThat(mono).emitsExactly(message); @@ -105,7 +105,7 @@ public class ChatRoomTest String user = "foo"; Long messageId = 1l; ChatRoomService chatRoomService = mock(ChatRoomService.class); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( UUID.randomUUID(), "Foo", 0, @@ -121,7 +121,7 @@ public class ChatRoomTest when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message)); // When - Mono mono = chatRoom.addMessage(messageId, user, messageText); + Mono mono = chatRoomData.addMessage(messageId, user, messageText); // Then assertThat(mono).emitsExactly(message); @@ -135,7 +135,7 @@ public class ChatRoomTest String user = "foo"; Long messageId = 1l; ChatRoomService chatRoomService = mock(ChatRoomService.class); - ChatRoom chatRoom = new ChatRoom( + ChatRoomData chatRoomData = new ChatRoomData( UUID.randomUUID(), "Foo", 0, @@ -152,7 +152,7 @@ public class ChatRoomTest when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class))).thenReturn(Mono.just(message)); // When - Mono mono = chatRoom.addMessage(messageId, user, mutatedText); + Mono mono = chatRoomData.addMessage(messageId, user, mutatedText); // Then assertThat(mono).sendsError(); diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java index 2a42a128..7de58620 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java @@ -40,7 +40,7 @@ public abstract class AbstractStorageStrategyIT UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7"); ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block(); log.debug("Created chat-room {}", info); - ChatRoom chatroom = chathome.getChatRoom(chatRoomId).block(); + ChatRoomData chatroom = chathome.getChatRoom(chatRoomId).block(); Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block(); Message m2 = chatroom.addMessage(1l, "ute", "Ich bin Ute...").block(); Message m3 = chatroom.addMessage(2l, "peter", "Willst du mit mir gehen?").block(); @@ -72,7 +72,7 @@ public abstract class AbstractStorageStrategyIT UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7"); ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block(); log.debug("Created chat-room {}", infoA); - ChatRoom chatroomA = chathome.getChatRoom(chatRoomAId).block(); + ChatRoomData chatroomA = chathome.getChatRoom(chatRoomAId).block(); Message ma1 = chatroomA.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block(); Message ma2 = chatroomA.addMessage(1l, "ute", "Ich bin Ute...").block(); Message ma3 = chatroomA.addMessage(2l, "peter", "Willst du mit mir gehen?").block(); @@ -81,7 +81,7 @@ public abstract class AbstractStorageStrategyIT UUID chatRoomBId = UUID.fromString("8763dfdc-4dda-4a74-bea4-4b389177abea"); ChatRoomInfo infoB = chathome.createChatRoom(chatRoomBId, "BAR").block(); log.debug("Created chat-room {}", infoB); - ChatRoom chatroomB = chathome.getChatRoom(chatRoomBId).block(); + ChatRoomData chatroomB = chathome.getChatRoom(chatRoomBId).block(); Message mb1 = chatroomB.addMessage(1l,"peter", "Hallo, ich heiße Uwe!").block(); Message mb2 = chatroomB.addMessage(1l, "ute", "Ich bin Ute...").block(); Message mb3 = chatroomB.addMessage(1l, "klaus", "Willst du mit mir gehen?").block(); -- 2.20.1