WIP:refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code
authorKai Moritz <kai@juplo.de>
Sun, 3 Sep 2023 19:31:15 +0000 (21:31 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 3 Sep 2023 19:31:15 +0000 (21:31 +0200)
22 files changed:
src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java
src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java
src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java
src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHome.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/ChatRoomTo.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/nostorage/NoStorageStorageConfiguration.java
src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeTest.java
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTest.java
src/test/java/de/juplo/kafka/chat/backend/domain/ChatRoomDataTest.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java

index 8e1ff9e..cc924d7 100644 (file)
@@ -33,7 +33,7 @@ public class ChatBackendApplication implements WebFluxConfigurer
        public void onExit()
        {
                for (int shard = 0; shard < chatHomes.length; shard++)
-                       storageStrategy.write(chatHomes[shard].getChatRooms());
+                       storageStrategy.writeChatRoomData(chatHomes[shard].getChatRoomData());
        }
 
        public static void main(String[] args)
index a400119..ac77deb 100644 (file)
@@ -33,49 +33,49 @@ public class ChatBackendController
   public Flux<ChatRoomInfoTo> list()
   {
     return chatHome
-        .getChatRooms()
-        .map(chatroom -> ChatRoomInfoTo.from(chatroom));
+        .getChatRoomInfo()
+        .map(chatroomInfo -> ChatRoomInfoTo.from(chatroomInfo));
   }
 
-  @GetMapping("{chatroomId}/list")
-  public Flux<MessageTo> list(@PathVariable UUID chatroomId)
+  @GetMapping("{chatRoomId}/list")
+  public Flux<MessageTo> list(@PathVariable UUID chatRoomId)
   {
     return chatHome
-        .getChatRoom(chatroomId)
-        .flatMapMany(chatroom -> chatroom
+        .getChatRoomData(chatRoomId)
+        .flatMapMany(chatRoomData -> chatRoomData
             .getMessages()
             .map(MessageTo::from));
   }
 
-  @GetMapping("{chatroomId}")
-  public Mono<ChatRoomInfoTo> get(@PathVariable UUID chatroomId)
+  @GetMapping("{chatRoomId}")
+  public Mono<ChatRoomInfoTo> get(@PathVariable UUID chatRoomId)
   {
     return chatHome
-        .getChatRoom(chatroomId)
-        .map(chatroom -> ChatRoomInfoTo.from(chatroom));
+        .getChatRoomInfo(chatRoomId)
+        .map(chatRoomInfo -> ChatRoomInfoTo.from(chatRoomInfo));
   }
 
-  @PutMapping("{chatroomId}/{username}/{messageId}")
+  @PutMapping("{chatRoomId}/{username}/{messageId}")
   public Mono<MessageTo> put(
-      @PathVariable UUID chatroomId,
+      @PathVariable UUID chatRoomId,
       @PathVariable String username,
       @PathVariable Long messageId,
       @RequestBody String text)
   {
     return
         chatHome
-            .getChatRoom(chatroomId)
-            .flatMap(chatroom -> put(chatroom, username, messageId, text));
+            .getChatRoomData(chatRoomId)
+            .flatMap(chatRoomData -> put(chatRoomData, username, messageId, text));
   }
 
   private Mono<MessageTo> put(
-      ChatRoomData chatroom,
+      ChatRoomData chatRoomData,
       String username,
       Long messageId,
       String text)
   {
     return
-        chatroom
+        chatRoomData
             .addMessage(
                 messageId,
                 username,
@@ -83,40 +83,40 @@ public class ChatBackendController
             .map(message -> MessageTo.from(message));
   }
 
-  @GetMapping("{chatroomId}/{username}/{messageId}")
+  @GetMapping("{chatRoomId}/{username}/{messageId}")
   public Mono<MessageTo> get(
-      @PathVariable UUID chatroomId,
+      @PathVariable UUID chatRoomId,
       @PathVariable String username,
       @PathVariable Long messageId)
   {
     return
         chatHome
-            .getChatRoom(chatroomId)
-            .flatMap(chatroom -> get(chatroom, username, messageId));
+            .getChatRoomData(chatRoomId)
+            .flatMap(chatRoomData -> get(chatRoomData, username, messageId));
   }
 
   private Mono<MessageTo> get(
-      ChatRoomData chatroom,
+      ChatRoomData chatRoomData,
       String username,
       Long messageId)
   {
     return
-        chatroom
+        chatRoomData
             .getMessage(username, messageId)
             .map(message -> MessageTo.from(message));
   }
 
-  @GetMapping(path = "{chatroomId}/listen")
-  public Flux<ServerSentEvent<MessageTo>> listen(@PathVariable UUID chatroomId)
+  @GetMapping(path = "{chatRoomId}/listen")
+  public Flux<ServerSentEvent<MessageTo>> listen(@PathVariable UUID chatRoomId)
   {
     return chatHome
-        .getChatRoom(chatroomId)
-        .flatMapMany(chatroom -> listen(chatroom));
+        .getChatRoomData(chatRoomId)
+        .flatMapMany(chatRoomData -> listen(chatRoomData));
   }
 
-  private Flux<ServerSentEvent<MessageTo>> listen(ChatRoomData chatroom)
+  private Flux<ServerSentEvent<MessageTo>> listen(ChatRoomData chatRoomData)
   {
-    return chatroom
+    return chatRoomData
         .listen()
         .log()
         .map(message -> MessageTo.from(message))
@@ -131,6 +131,7 @@ public class ChatBackendController
   @PostMapping("/store")
   public void store()
   {
-    storageStrategy.write(chatHome.getChatRooms());
+    storageStrategy.writeChatRoomInfo(chatHome.getChatRoomInfo());
+    storageStrategy.writeChatRoomData(chatHome.getChatRoomData());
   }
 }
index 7b97d55..a3442ae 100644 (file)
@@ -10,7 +10,11 @@ public interface ChatHome
 {
   Mono<ChatRoomInfo> createChatRoom(UUID id, String name);
 
-  Mono<ChatRoomData> getChatRoom(UUID id);
+  Mono<ChatRoomInfo> getChatRoomInfo(UUID id);
 
-  Flux<ChatRoomData> getChatRooms();
+  Flux<ChatRoomInfo> getChatRoomInfo();
+
+  Mono<ChatRoomData> getChatRoomData(UUID id);
+
+  Flux<ChatRoomData> getChatRoomData();
 }
index a5667c1..cf44802 100644 (file)
@@ -17,20 +17,20 @@ public class ChatRoomData
 {
   public final static Pattern VALID_USER = Pattern.compile("^[a-z0-9-]{2,}$");
 
-  private final Clock clock;
   private final ChatRoomService service;
+  private final Clock clock;
   private final int bufferSize;
   private Sinks.Many<Message> sink;
 
 
   public ChatRoomData(
-      Clock clock,
       ChatRoomService service,
+      Clock clock,
       int bufferSize)
   {
     log.info("Created ChatRoom with buffer-size {}", bufferSize);
-    this.clock = clock;
     this.service = service;
+    this.clock = clock;
     this.bufferSize = bufferSize;
     // @RequiredArgsConstructor unfortunately not possible, because
     // the `bufferSize` is not set, if `createSink()` is called
index 96d1eb7..9997b94 100644 (file)
@@ -1,11 +1,14 @@
 package de.juplo.kafka.chat.backend.persistence;
 
 import de.juplo.kafka.chat.backend.domain.ChatRoomData;
+import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
 import reactor.core.publisher.Flux;
 
 
 public interface StorageStrategy
 {
-  void write(Flux<ChatRoomData> chatroomFlux);
-  Flux<ChatRoomData> read();
+  void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);
+  Flux<ChatRoomInfo> readChatRoomInfo();
+  void writeChatRoomData(Flux<ChatRoomData> chatRoomDataFlux);
+  Flux<ChatRoomData> readChatRoomData();
 }
index 106c736..dd8f7d2 100644 (file)
@@ -31,7 +31,7 @@ public class InMemoryServicesConfiguration
       Clock clock)
   {
     return new SimpleChatHome(
-        storageStrategy.read(),
+        storageStrategy.readChatRoomData(),
         clock,
         properties.getChatroomBufferSize());
   }
@@ -52,7 +52,7 @@ public class InMemoryServicesConfiguration
         .of(properties.getInmemory().getOwnedShards())
         .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
             shard,
-            storageStrategy.read(),
+            storageStrategy.readChatRoomData(),
             clock,
             properties.getChatroomBufferSize()));
     ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
index 653c64a..2c9e166 100644 (file)
@@ -48,13 +48,13 @@ public class ShardedChatHome implements ChatHome
   }
 
   @Override
-  public Mono<ChatRoomData> getChatRoom(UUID id)
+  public Mono<ChatRoomInfo> getChatRoomInfo(UUID id)
   {
     int shard = selectShard(id);
     return chatHomes[shard] == null
         ? Mono.error(new ShardNotOwnedException(shard))
         : chatHomes[shard]
-            .getChatRoom(id)
+            .getChatRoomInfo(id)
             .onErrorMap(throwable -> throwable instanceof UnknownChatroomException
             ? new UnknownChatroomException(
                 id,
@@ -64,13 +64,38 @@ public class ShardedChatHome implements ChatHome
   }
 
   @Override
-  public Flux<ChatRoomData> getChatRooms()
+  public Flux<ChatRoomInfo> getChatRoomInfo()
   {
     return Flux
         .fromIterable(ownedShards)
-        .flatMap(shard -> chatHomes[shard].getChatRooms());
+        .flatMap(shard -> chatHomes[shard].getChatRoomInfo());
   }
 
+  @Override
+  public Mono<ChatRoomData> getChatRoomData(UUID id)
+  {
+    int shard = selectShard(id);
+    return chatHomes[shard] == null
+        ? Mono.error(new ShardNotOwnedException(shard))
+        : chatHomes[shard]
+            .getChatRoomData(id)
+            .onErrorMap(throwable -> throwable instanceof UnknownChatroomException
+                ? new UnknownChatroomException(
+                id,
+                shard,
+                ownedShards.stream().mapToInt(i -> i.intValue()).toArray())
+                : throwable);
+  }
+
+  @Override
+  public Flux<ChatRoomData> getChatRoomData()
+  {
+    return Flux
+        .fromIterable(ownedShards)
+        .flatMap(shard -> chatHomes[shard].getChatRoomData());
+  }
+
+
 
   private int selectShard(UUID chatroomId)
   {
index 9112fb9..f0067fa 100644 (file)
@@ -13,34 +13,43 @@ import java.util.*;
 public class SimpleChatHome implements ChatHome
 {
   private final Integer shard;
-  private final Map<UUID, ChatRoomData> chatRooms;
+  private final Map<UUID, ChatRoomInfo> chatRoomInfo;
+  private final Map<UUID, ChatRoomData> chatRoomData;
   private final Clock clock;
   private final int bufferSize;
 
 
 
   public SimpleChatHome(
-      Flux<ChatRoomData> chatroomFlux,
+      Flux<ChatRoomInfo> chatRoomInfoFlux,
+      ChatRoomService chatRoomService,
       Clock clock,
       int bufferSize)
   {
-    this(null, chatroomFlux, clock, bufferSize);
+    this(
+        null,
+        chatRoomInfoFlux,
+        chatRoomService,
+        clock,
+        bufferSize);
   }
 
   public SimpleChatHome(
       Integer shard,
-      Flux<ChatRoomData> chatroomFlux,
+      Flux<ChatRoomInfo> chatRoomInfoFlux,
+      ChatRoomService chatRoomService,
       Clock clock,
       int bufferSize)
   {
     log.info("Created SimpleChatHome for shard {}", shard);
 ;
     this.shard = shard;
-    this.chatRooms = new HashMap<>();
-    chatroomFlux
-        .filter(chatRoom ->
+    this.chatRoomInfo = new HashMap<>();
+    this.chatRoomData = new HashMap<>();
+    chatRoomInfoFlux
+        .filter(info ->
         {
-          if (shard == null || chatRoom.getShard() == shard)
+          if (shard == null || info.getShard() == shard)
           {
             return true;
           }
@@ -49,12 +58,18 @@ public class SimpleChatHome implements ChatHome
             log.info(
                 "SimpleChatHome for shard {} ignores not owned chat-room {}",
                 shard,
-                chatRoom);
+                info);
             return false;
           }
         })
         .toStream()
-        .forEach(chatroom -> chatRooms.put(chatroom.getId(), chatroom));
+        .forEach(info ->
+        {
+          chatRoomInfo.put(info.getId(), info);
+          chatRoomData.put(
+              info.getId(),
+              new ChatRoomData(chatRoomService, clock, bufferSize));
+        });
     this.clock = clock;
     this.bufferSize = bufferSize;
   }
@@ -65,22 +80,37 @@ public class SimpleChatHome implements ChatHome
   {
     log.info("Creating ChatRoom with buffer-size {}", bufferSize);
     ChatRoomService service = new InMemoryChatRoomService(Flux.empty());
-    ChatRoomData chatRoomData = new ChatRoomData(id, name, shard, clock, service, bufferSize);
-    chatRooms.put(id, chatRoomData);
-    return Mono.just(chatRoomData);
+    ChatRoomInfo chatRoomInfo = new ChatRoomInfo(id, name, shard);
+    ChatRoomData chatRoomData = new ChatRoomData(service, clock, bufferSize);
+    this.chatRoomData.put(id, chatRoomData);
+    return Mono.just(chatRoomInfo);
+  }
+
+  @Override
+  public Mono<ChatRoomInfo> getChatRoomInfo(UUID id)
+  {
+    return Mono
+        .justOrEmpty(chatRoomInfo.get(id))
+        .switchIfEmpty(Mono.error(() -> new UnknownChatroomException(id)));
+  }
+
+  @Override
+  public Flux<ChatRoomInfo> getChatRoomInfo()
+  {
+    return Flux.fromIterable(chatRoomInfo.values());
   }
 
   @Override
-  public Mono<ChatRoomData> getChatRoom(UUID id)
+  public Mono<ChatRoomData> getChatRoomData(UUID id)
   {
     return Mono
-        .justOrEmpty(chatRooms.get(id))
+        .justOrEmpty(chatRoomData.get(id))
         .switchIfEmpty(Mono.error(() -> new UnknownChatroomException(id)));
   }
 
   @Override
-  public Flux<ChatRoomData> getChatRooms()
+  public Flux<ChatRoomData> getChatRoomData()
   {
-    return Flux.fromIterable(chatRooms.values());
+    return Flux.fromIterable(chatRoomData.values());
   }
 }
index 6ce85d1..b631ed5 100644 (file)
@@ -282,9 +282,6 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener
     log.info("Loading ChatRoom {} with buffer-size {}", chatRoomId, bufferSize);
     KafkaChatRoomService service = new KafkaChatRoomService(this, chatRoomId);
     ChatRoomData chatRoomData = new ChatRoomData(
-        chatRoomId,
-        createChatRoomRequestTo.getName(),
-        partition,
         clock,
         service,
         bufferSize);
@@ -299,7 +296,7 @@ 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);
-    ChatRoomData chatRoomData = new ChatRoomData(id, name, shard, clock, service, bufferSize);
+    ChatRoomData chatRoomData = new ChatRoomData(clock, service, bufferSize);
     putChatRoom(chatRoomData);
   }
 
index 68cad73..cea178b 100644 (file)
@@ -30,7 +30,7 @@ public class KafkaChatHome implements ChatHome
   }
 
   @Override
-  public Mono<ChatRoomData> getChatRoom(UUID id)
+  public Mono<ChatRoomInfo> getChatRoomInfo(UUID id)
   {
     int shard = selectShard(id);
     return chatRoomChannel
@@ -41,15 +41,33 @@ public class KafkaChatHome implements ChatHome
             chatRoomChannel.getOwnedShards())));
   }
 
-  int selectShard(UUID chatRoomId)
+  @Override
+  public Flux<ChatRoomInfo> getChatRoomInfo()
   {
-    byte[] serializedKey = chatRoomId.toString().getBytes();
-    return Utils.toPositive(Utils.murmur2(serializedKey)) % numPartitions;
+    return chatRoomChannel.getChatRooms();
   }
 
   @Override
-  public Flux<ChatRoomData> getChatRooms()
+  public Mono<ChatRoomData> getChatRoomData(UUID id)
+  {
+    int shard = selectShard(id);
+    return chatRoomChannel
+        .getChatRoom(shard, id)
+        .switchIfEmpty(Mono.error(() -> new UnknownChatroomException(
+            id,
+            shard,
+            chatRoomChannel.getOwnedShards())));
+  }
+
+  @Override
+  public Flux<ChatRoomData> getChatRoomData()
   {
       return chatRoomChannel.getChatRooms();
   }
+
+  int selectShard(UUID chatRoomId)
+  {
+    byte[] serializedKey = chatRoomId.toString().getBytes();
+    return Utils.toPositive(Utils.murmur2(serializedKey)) % numPartitions;
+  }
 }
index fb6e344..860d9ff 100644 (file)
@@ -39,7 +39,7 @@ public class FilesStorageStrategy implements StorageStrategy
 
 
   @Override
-  public void write(Flux<ChatRoomData> chatroomFlux)
+  public void writeChatRoomData(Flux<ChatRoomData> chatRoomDataFlux)
   {
     Path path = chatroomsPath();
     log.info("Writing chatrooms to {}", path);
@@ -52,7 +52,7 @@ public class FilesStorageStrategy implements StorageStrategy
               .getFactory()
               .createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
 
-      chatroomFlux
+      chatRoomDataFlux
           .log()
           .doFirst(() ->
           {
@@ -99,7 +99,7 @@ public class FilesStorageStrategy implements StorageStrategy
   }
 
   @Override
-  public Flux<ChatRoomData> read()
+  public Flux<ChatRoomData> readChatRoomData()
   {
     JavaType type = mapper.getTypeFactory().constructType(ChatRoomInfoTo.class);
     return Flux
@@ -110,9 +110,6 @@ public class FilesStorageStrategy implements StorageStrategy
           UUID chatRoomId = infoTo.getId();
           int shard = shardingStrategy.selectShard(chatRoomId);
           return new ChatRoomData(
-              infoTo.getId(),
-              infoTo.getName(),
-              shard,
               clock,
               factory.create(readMessages(infoTo)),
               bufferSize);
index 6b5ea87..f3fae32 100644 (file)
@@ -1,6 +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.domain.ChatRoomInfo;
 import lombok.*;
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
@@ -24,12 +25,12 @@ public class ChatRoomTo
 
   public static ChatRoomTo from(
       ChatRoomInfo chatRoomInfo,
-      ChatRoomData chatroom)
+      ChatRoomData chatRoomData)
   {
     return new ChatRoomTo(
-        chatroom.getId().toString(),
-        chatroom.getName(),
-        chatroom
+        chatRoomInfo.getId().toString(),
+        chatRoomInfo.getName(),
+        chatRoomData
             .getMessages()
             .map(MessageTo::from)
             .collectList()
index b9c7fb2..7952a2b 100644 (file)
@@ -24,15 +24,15 @@ public class MongoDbStorageStrategy implements StorageStrategy
 
 
   @Override
-  public void write(Flux<ChatRoomData> chatroomFlux)
+  public void writeChatRoomData(Flux<ChatRoomData> chatRoomDataFlux)
   {
-    chatroomFlux
+    chatRoomDataFlux
         .map(ChatRoomTo::from)
         .subscribe(chatroomTo -> repository.save(chatroomTo));
   }
 
   @Override
-  public Flux<ChatRoomData> read()
+  public Flux<ChatRoomData> readChatRoomData()
   {
     return Flux
         .fromIterable(repository.findAll())
@@ -41,9 +41,6 @@ public class MongoDbStorageStrategy implements StorageStrategy
           UUID chatRoomId = UUID.fromString(chatRoomTo.getId());
           int shard = shardingStrategy.selectShard(chatRoomId);
           return new ChatRoomData(
-              chatRoomId,
-              chatRoomTo.getName(),
-              shard,
               clock,
               factory.create(
                   Flux
index dd2223c..84ac8de 100644 (file)
@@ -1,6 +1,7 @@
 package de.juplo.kafka.chat.backend.persistence.storage.nostorage;
 
 import de.juplo.kafka.chat.backend.domain.ChatRoomData;
+import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -29,10 +30,19 @@ public class NoStorageStorageConfiguration
     return new StorageStrategy()
     {
       @Override
-      public void write(Flux<ChatRoomData> chatroomFlux) {}
+      public void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux) {}
 
       @Override
-      public Flux<ChatRoomData> read()
+      public Flux<ChatRoomInfo> readChatRoomInfo()
+      {
+        return Flux.empty();
+      }
+
+      @Override
+      public void writeChatRoomData(Flux<ChatRoomData> chatRoomDataFlux) {}
+
+      @Override
+      public Flux<ChatRoomData> readChatRoomData()
       {
         return Flux.empty();
       }
index 63ab7d6..8736b82 100644 (file)
@@ -42,7 +42,7 @@ public class ChatBackendControllerTest
   {
     // Given
     UUID chatroomId = UUID.randomUUID();
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -62,7 +62,7 @@ public class ChatBackendControllerTest
   {
     // Given
     UUID chatroomId = UUID.randomUUID();
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -83,7 +83,7 @@ public class ChatBackendControllerTest
     UUID chatroomId = UUID.randomUUID();
     String username = "foo";
     Long messageId = 66l;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -109,7 +109,7 @@ public class ChatBackendControllerTest
     UUID chatroomId = UUID.randomUUID();
     String username = "foo";
     Long messageId = 66l;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -132,7 +132,7 @@ public class ChatBackendControllerTest
   {
     // Given
     UUID chatroomId = UUID.randomUUID();
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -171,12 +171,10 @@ public class ChatBackendControllerTest
     String textExistingMessage = "Existing";
     String textMutatedMessage = "Mutated!";
     ChatRoomData chatRoomData = new ChatRoomData(
-        chatroomId,
-        "Test-ChatRoom",
-        0,
         Clock.systemDefaultZone(),
-        chatRoomService, 8);
-    when(chatHome.getChatRoom(eq(chatroomId))).thenReturn(Mono.just(chatRoomData));
+        chatRoomService,
+        8);
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenReturn(Mono.just(chatRoomData));
     Message existingMessage = new Message(
         key,
         serialNumberExistingMessage,
@@ -223,12 +221,10 @@ public class ChatBackendControllerTest
     Message.MessageKey key = Message.MessageKey.of(user, messageId);
     String textMessage = "Hallo Welt";
     ChatRoomData chatRoomData = new ChatRoomData(
-        chatroomId,
-        "Test-ChatRoom",
-        0,
         Clock.systemDefaultZone(),
-        chatRoomService, 8);
-    when(chatHome.getChatRoom(any(UUID.class)))
+        chatRoomService,
+        8);
+    when(chatHome.getChatRoomData(any(UUID.class)))
         .thenReturn(Mono.just(chatRoomData));
     when(chatRoomService.getMessage(any(Message.MessageKey.class)))
         .thenReturn(Mono.empty());
@@ -262,7 +258,7 @@ public class ChatBackendControllerTest
     // Given
     UUID chatroomId = UUID.randomUUID();
     int shard = 666;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -282,7 +278,7 @@ public class ChatBackendControllerTest
     // Given
     UUID chatroomId = UUID.randomUUID();
     int shard = 666;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -304,7 +300,7 @@ public class ChatBackendControllerTest
     String username = "foo";
     Long messageId = 66l;
     int shard = 666;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -331,7 +327,7 @@ public class ChatBackendControllerTest
     String username = "foo";
     Long messageId = 66l;
     int shard = 666;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
@@ -355,7 +351,7 @@ public class ChatBackendControllerTest
     // Given
     UUID chatroomId = UUID.randomUUID();
     int shard = 666;
-    when(chatHome.getChatRoom(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+    when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
 
     // When
     WebTestClient.ResponseSpec responseSpec = client
index ad7fe95..5b50314 100644 (file)
@@ -30,7 +30,7 @@ public abstract class ChatHomeTest
 
     // When
     Mono<ChatRoomData> mono = Mono
-        .defer(() -> chatHome.getChatRoom(chatRoomId))
+        .defer(() -> chatHome.getChatRoomData(chatRoomId))
         .log("testGetExistingChatroom")
         .retryWhen(Retry
             .backoff(5, Duration.ofSeconds(1))
@@ -49,7 +49,7 @@ public abstract class ChatHomeTest
 
     // When
     Mono<ChatRoomData> mono = Mono
-        .defer(() -> chatHome.getChatRoom(chatRoomId))
+        .defer(() -> chatHome.getChatRoomData(chatRoomId))
         .log("testGetNonExistentChatroom")
         .retryWhen(Retry
             .backoff(5, Duration.ofSeconds(1))
index 6775456..c65908c 100644 (file)
@@ -27,7 +27,7 @@ public abstract class ChatHomeWithShardsTest extends ChatHomeTest
 
     // When
     Mono<ChatRoomData> mono = Mono
-        .defer(() -> chatHome.getChatRoom(chatRoomId))
+        .defer(() -> chatHome.getChatRoomData(chatRoomId))
         .log("testGetChatroomForNotOwnedShard")
         .retryWhen(Retry
             .backoff(5, Duration.ofSeconds(1))
index 171a9da..790482f 100644 (file)
@@ -8,7 +8,6 @@ import java.time.Clock;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
-import java.util.UUID;
 
 import static org.mockito.Mockito.*;
 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
@@ -25,9 +24,6 @@ public class ChatRoomDataTest
     Long messageId = 1l;
     ChatRoomService chatRoomService = mock(ChatRoomService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
-        UUID.randomUUID(),
-        "Foo",
-        0,
         Clock.systemDefaultZone(),
         chatRoomService,
         8);
@@ -52,9 +48,6 @@ public class ChatRoomDataTest
     Long messageId = 1l;
     ChatRoomService chatRoomService = mock(ChatRoomService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
-        UUID.randomUUID(),
-        "Foo",
-        0,
         Clock.systemDefaultZone(),
         chatRoomService,
         8);
@@ -76,9 +69,6 @@ public class ChatRoomDataTest
     Long messageId = 1l;
     ChatRoomService chatRoomService = mock(ChatRoomService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
-        UUID.randomUUID(),
-        "Foo",
-        0,
         Clock.systemDefaultZone(),
         chatRoomService,
         8);
@@ -106,9 +96,6 @@ public class ChatRoomDataTest
     Long messageId = 1l;
     ChatRoomService chatRoomService = mock(ChatRoomService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
-        UUID.randomUUID(),
-        "Foo",
-        0,
         Clock.systemDefaultZone(),
         chatRoomService,
         8);
@@ -136,9 +123,6 @@ public class ChatRoomDataTest
     Long messageId = 1l;
     ChatRoomService chatRoomService = mock(ChatRoomService.class);
     ChatRoomData chatRoomData = new ChatRoomData(
-        UUID.randomUUID(),
-        "Foo",
-        0,
         Clock.systemDefaultZone(),
         chatRoomService,
         8);
index 62dc08a..b5d0cd4 100644 (file)
@@ -22,7 +22,7 @@ public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyI
       int bufferSize = 8;
 
       SimpleChatHome simpleChatHome = new SimpleChatHome(
-          getStorageStrategy().read(),
+          getStorageStrategy().readChatRoomData(),
           clock,
           bufferSize);
 
index 7de5862..d9e6c04 100644 (file)
@@ -27,7 +27,7 @@ public abstract class AbstractStorageStrategyIT
 
   protected void stop()
   {
-    getStorageStrategy().write(chathome.getChatRooms());
+    getStorageStrategy().writeChatRoomData(chathome.getChatRoomData());
   }
 
   @Test
@@ -35,30 +35,30 @@ public abstract class AbstractStorageStrategyIT
   {
     start();
 
-    assertThat(chathome.getChatRooms().toStream()).hasSize(0);
+    assertThat(chathome.getChatRoomData().toStream()).hasSize(0);
 
     UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
     ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block();
     log.debug("Created chat-room {}", info);
-    ChatRoomData chatroom = chathome.getChatRoom(chatRoomId).block();
+    ChatRoomData chatroom = chathome.getChatRoomData(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();
     Message m4 = chatroom.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
 
-    assertThat(chathome.getChatRooms().toStream()).containsExactlyElementsOf(List.of(chatroom));
-    assertThat(chathome.getChatRoom(chatroom.getId())).emitsExactly(chatroom);
+    assertThat(chathome.getChatRoomData().toStream()).containsExactlyElementsOf(List.of(chatroom));
+    assertThat(chathome.getChatRoomData(chatroom.getId())).emitsExactly(chatroom);
     assertThat(chathome
-        .getChatRoom(chatroom.getId())
+        .getChatRoomData(chatroom.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
 
     stop();
     start();
 
-    assertThat(chathome.getChatRooms().toStream()).containsExactlyElementsOf(List.of(chatroom));
-    assertThat(chathome.getChatRoom(chatroom.getId())).emitsExactly(chatroom);
+    assertThat(chathome.getChatRoomData().toStream()).containsExactlyElementsOf(List.of(chatroom));
+    assertThat(chathome.getChatRoomData(chatroom.getId())).emitsExactly(chatroom);
     assertThat(chathome
-        .getChatRoom(chatroom.getId())
+        .getChatRoomData(chatroom.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
   }
 
@@ -67,12 +67,12 @@ public abstract class AbstractStorageStrategyIT
   {
     start();
 
-    assertThat(chathome.getChatRooms().toStream()).hasSize(0);
+    assertThat(chathome.getChatRoomData().toStream()).hasSize(0);
 
     UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
     ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block();
     log.debug("Created chat-room {}", infoA);
-    ChatRoomData chatroomA = chathome.getChatRoom(chatRoomAId).block();
+    ChatRoomData chatroomA = chathome.getChatRoomData(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,33 +81,33 @@ 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);
-    ChatRoomData chatroomB = chathome.getChatRoom(chatRoomBId).block();
+    ChatRoomData chatroomB = chathome.getChatRoomData(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();
     Message mb4 = chatroomB.addMessage(2l, "peter", "Hä? Was jetzt?!? Isch glohb isch höb ühn däjah vüh...").block();
 
-    assertThat(chathome.getChatRooms().toStream()).containsExactlyInAnyOrderElementsOf(List.of(chatroomA, chatroomB));
-    assertThat(chathome.getChatRoom(chatroomA.getId())).emitsExactly(chatroomA);
+    assertThat(chathome.getChatRoomData().toStream()).containsExactlyInAnyOrderElementsOf(List.of(chatroomA, chatroomB));
+    assertThat(chathome.getChatRoomData(chatroomA.getId())).emitsExactly(chatroomA);
     assertThat(chathome
-        .getChatRoom(chatroomA.getId())
+        .getChatRoomData(chatroomA.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
-    assertThat(chathome.getChatRoom(chatroomB.getId())).emitsExactly(chatroomB);
+    assertThat(chathome.getChatRoomData(chatroomB.getId())).emitsExactly(chatroomB);
     assertThat(chathome
-        .getChatRoom(chatroomB.getId())
+        .getChatRoomData(chatroomB.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
 
     stop();
     start();
 
-    assertThat(chathome.getChatRooms().toStream()).containsExactlyInAnyOrderElementsOf(List.of(chatroomA, chatroomB));
-    assertThat(chathome.getChatRoom(chatroomA.getId())).emitsExactly(chatroomA);
+    assertThat(chathome.getChatRoomData().toStream()).containsExactlyInAnyOrderElementsOf(List.of(chatroomA, chatroomB));
+    assertThat(chathome.getChatRoomData(chatroomA.getId())).emitsExactly(chatroomA);
     assertThat(chathome
-        .getChatRoom(chatroomA.getId())
+        .getChatRoomData(chatroomA.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
-    assertThat(chathome.getChatRoom(chatroomB.getId())).emitsExactly(chatroomB);
+    assertThat(chathome.getChatRoomData(chatroomB.getId())).emitsExactly(chatroomB);
     assertThat(chathome
-        .getChatRoom(chatroomB.getId())
+        .getChatRoomData(chatroomB.getId())
         .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
   }
 
index e2ffd3a..22c37d1 100644 (file)
@@ -27,7 +27,7 @@ public class ShardedChatHomeTest extends ChatHomeWithShardsTest
           .of(ownedShards())
           .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
               shard,
-              storageStrategy.read(),
+              storageStrategy.readChatRoomData(),
               clock,
               bufferSize()));
 
index 190d0f2..1140f69 100644 (file)
@@ -22,7 +22,7 @@ public class SimpleChatHomeTest extends ChatHomeTest
         Clock clock)
     {
       return new SimpleChatHome(
-          storageStrategy.read(),
+          storageStrategy.readChatRoomData(),
           clock,
           bufferSize());
     }