+++ /dev/null
-package de.juplo.kafka.chat.backend.persistence.inmemory;
-
-import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.util.UUID;
-
-
-public interface ChatHomeService
-{
- Mono<ChatRoom> getChatRoom(int shard, UUID id);
- Flux<ChatRoom> getChatRooms(int shard);
-}
@Slf4j
-public class InMemoryChatHomeService implements ChatHomeService
+public class InMemoryChatHomeService
{
private final Map<UUID, ChatRoom>[] chatrooms;
chatrooms[chatRoom.getShard()].put(chatRoom.getId(), chatRoom);
}
- @Override
public Mono<ChatRoom> getChatRoom(int shard, UUID id)
{
return Mono.justOrEmpty(chatrooms[shard].get(id));
}
- @Override
public Flux<ChatRoom> getChatRooms(int shard)
{
return Flux.fromStream(chatrooms[shard].values().stream());
@Slf4j
public class SimpleChatHome implements ChatHome
{
- private final ChatHomeService service;
+ private final InMemoryChatHomeService service;
private final int shard;
- public SimpleChatHome(ChatHomeService service, int shard)
+ public SimpleChatHome(InMemoryChatHomeService service, int shard)
{
log.info("Created SimpleChatHome for shard {}", shard);
this.service = service;
this.shard = shard;
}
- public SimpleChatHome(ChatHomeService service)
+ public SimpleChatHome(InMemoryChatHomeService service)
{
this(service, 0);
}
package de.juplo.kafka.chat.backend.persistence;
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
+import de.juplo.kafka.chat.backend.domain.ChatHome;
import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
+import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
{
return new StorageStrategyITConfig()
{
- InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService(
+ InMemoryChatHomeService inMemoryChatHomeService = new InMemoryChatHomeService(
1,
new int[] { 0 },
getStorageStrategy().read());
+ SimpleChatHome simpleChatHome = new SimpleChatHome(inMemoryChatHomeService);
+
InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory(
- chatHomeService,
+ inMemoryChatHomeService,
chatRoomId -> 0,
clock,
8);
@Override
- public ChatHomeService getChatHomeService()
+ public ChatHome getChatHome()
{
- return chatHomeService;
+ return simpleChatHome;
}
@Override
package de.juplo.kafka.chat.backend.persistence;
import de.juplo.kafka.chat.backend.domain.*;
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
protected void start()
{
StorageStrategyITConfig config = getConfig();
- chathome = new SimpleChatHome(config.getChatHomeService());
+ chathome = config.getChatHome();
chatRoomFactory = config.getChatRoomFactory();
}
interface StorageStrategyITConfig
{
- ChatHomeService getChatHomeService();
+ ChatHome getChatHome();
ChatRoomFactory getChatRoomFactory();
}
}
import de.juplo.kafka.chat.backend.domain.ChatRoom;
import de.juplo.kafka.chat.backend.domain.ChatRoomService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
void testGetExistingChatroom()
{
// Given
- ChatHomeService chatHomeService = mock(ChatHomeService.class);
+ InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class);
ChatRoom chatRoom = new ChatRoom(
UUID.randomUUID(),
"Foo",
void testGetNonExistentChatroom()
{
// Given
- ChatHomeService chatHomeService = mock(ChatHomeService.class);
+ InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class);
when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
SimpleChatHome chatHome = new SimpleChatHome(chatHomeService);