From 3d02d758eef3adf433adff579302ab8e14f52ce4 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 6 Sep 2023 23:41:37 +0200 Subject: [PATCH] refactor: `ChatHome` is a service - Aligned code --- .../chat/backend/ChatBackendApplication.java | 6 ++--- .../backend/api/ChatBackendController.java | 20 +++++++------- .../chat/backend/domain/ChatHomeService.java | 2 +- .../backend/persistence/StorageStrategy.java | 8 +++--- .../InMemoryServicesConfiguration.java | 14 +++++----- .../inmemory/ShardedChatHomeService.java | 8 +++--- .../inmemory/SimpleChatHomeService.java | 6 ++--- .../kafka/KafkaChatHomeService.java | 4 +-- .../kafka/KafkaServicesConfiguration.java | 6 ++--- .../api/ChatBackendControllerTest.java | 26 +++++++++---------- .../backend/domain/ChatHomeServiceTest.java | 8 +++--- .../domain/ChatHomeServiceWithShardsTest.java | 4 +-- .../AbstractInMemoryStorageIT.java | 8 +++--- .../AbstractStorageStrategyIT.java | 4 +-- .../inmemory/ShardedChatHomeServiceTest.java | 12 ++++----- .../inmemory/SimpleChatHomeServiceTest.java | 8 +++--- .../kafka/KafkaChatHomeServiceTest.java | 10 +++---- 17 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java index 15f8ae15..e2c35628 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import jakarta.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +16,7 @@ public class ChatBackendApplication implements WebFluxConfigurer @Autowired ChatBackendProperties properties; @Autowired - ChatHome chatHome; + ChatHomeService chatHomeService; @Autowired StorageStrategy storageStrategy; @@ -32,7 +32,7 @@ public class ChatBackendApplication implements WebFluxConfigurer @PreDestroy public void onExit() { - storageStrategy.write(chatHome); + storageStrategy.write(chatHomeService); } public static void main(String[] args) 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 e2fe714b..7f29b16c 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,6 +1,6 @@ package de.juplo.kafka.chat.backend.api; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import lombok.RequiredArgsConstructor; @@ -16,7 +16,7 @@ import java.util.UUID; @RequiredArgsConstructor public class ChatBackendController { - private final ChatHome chatHome; + private final ChatHomeService chatHomeService; private final StorageStrategy storageStrategy; @@ -24,7 +24,7 @@ public class ChatBackendController public Mono create(@RequestBody String name) { UUID chatRoomId = UUID.randomUUID(); - return chatHome + return chatHomeService .createChatRoom(chatRoomId, name) .map(ChatRoomInfoTo::from); } @@ -32,7 +32,7 @@ public class ChatBackendController @GetMapping("list") public Flux list() { - return chatHome + return chatHomeService .getChatRoomInfo() .map(chatroomInfo -> ChatRoomInfoTo.from(chatroomInfo)); } @@ -40,7 +40,7 @@ public class ChatBackendController @GetMapping("{chatRoomId}/list") public Flux list(@PathVariable UUID chatRoomId) { - return chatHome + return chatHomeService .getChatRoomData(chatRoomId) .flatMapMany(chatRoomData -> chatRoomData .getMessages() @@ -50,7 +50,7 @@ public class ChatBackendController @GetMapping("{chatRoomId}") public Mono get(@PathVariable UUID chatRoomId) { - return chatHome + return chatHomeService .getChatRoomInfo(chatRoomId) .map(chatRoomInfo -> ChatRoomInfoTo.from(chatRoomInfo)); } @@ -63,7 +63,7 @@ public class ChatBackendController @RequestBody String text) { return - chatHome + chatHomeService .getChatRoomData(chatRoomId) .flatMap(chatRoomData -> put(chatRoomData, username, messageId, text)); } @@ -90,7 +90,7 @@ public class ChatBackendController @PathVariable Long messageId) { return - chatHome + chatHomeService .getChatRoomData(chatRoomId) .flatMap(chatRoomData -> get(chatRoomData, username, messageId)); } @@ -109,7 +109,7 @@ public class ChatBackendController @GetMapping(path = "{chatRoomId}/listen") public Flux> listen(@PathVariable UUID chatRoomId) { - return chatHome + return chatHomeService .getChatRoomData(chatRoomId) .flatMapMany(chatRoomData -> listen(chatRoomData)); } @@ -131,6 +131,6 @@ public class ChatBackendController @PostMapping("/store") public void store() { - storageStrategy.write(chatHome); + storageStrategy.write(chatHomeService); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java index 2ff59cb3..388a20ad 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java @@ -6,7 +6,7 @@ import reactor.core.publisher.Mono; import java.util.UUID; -public interface ChatHome +public interface ChatHomeService { Mono createChatRoom(UUID id, String name); 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 7d0f66d4..cbf55a4c 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,6 +1,6 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomInfo; import de.juplo.kafka.chat.backend.domain.Message; import reactor.core.publisher.Flux; @@ -10,15 +10,15 @@ import java.util.UUID; public interface StorageStrategy { - default void write(ChatHome chatHome) + default void write(ChatHomeService chatHomeService) { writeChatRoomInfo( - chatHome + chatHomeService .getChatRoomInfo() .doOnNext(chatRoomInfo -> writeChatRoomData( chatRoomInfo.getId(), - chatHome + chatHomeService .getChatRoomData(chatRoomInfo.getId()) .flatMapMany(chatRoomData -> chatRoomData.getMessages())))); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java index d2fd731e..263a2d5f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.inmemory; import de.juplo.kafka.chat.backend.ChatBackendProperties; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.persistence.ShardingStrategy; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -26,12 +26,12 @@ public class InMemoryServicesConfiguration name = "sharding-strategy", havingValue = "none", matchIfMissing = true) - ChatHome noneShardingChatHome( + ChatHomeService noneShardingChatHome( ChatBackendProperties properties, StorageStrategy storageStrategy, Clock clock) { - return new SimpleChatHome( + return new SimpleChatHomeService( storageStrategy, clock, properties.getChatroomBufferSize()); @@ -42,22 +42,22 @@ public class InMemoryServicesConfiguration prefix = "chat.backend.inmemory", name = "sharding-strategy", havingValue = "kafkalike") - ChatHome kafkalikeShardingChatHome( + ChatHomeService kafkalikeShardingChatHome( ChatBackendProperties properties, StorageStrategy storageStrategy, Clock clock) { int numShards = properties.getInmemory().getNumShards(); - SimpleChatHome[] chatHomes = new SimpleChatHome[numShards]; + SimpleChatHomeService[] chatHomes = new SimpleChatHomeService[numShards]; IntStream .of(properties.getInmemory().getOwnedShards()) - .forEach(shard -> chatHomes[shard] = new SimpleChatHome( + .forEach(shard -> chatHomes[shard] = new SimpleChatHomeService( shard, storageStrategy, clock, properties.getChatroomBufferSize())); ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards); - return new ShardedChatHome(chatHomes, strategy); + return new ShardedChatHomeService(chatHomes, strategy); } @ConditionalOnProperty( diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeService.java index 4c8b2faa..09e4684d 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeService.java @@ -15,15 +15,15 @@ import java.util.stream.Collectors; @Slf4j -public class ShardedChatHome implements ChatHome +public class ShardedChatHomeService implements ChatHomeService { - private final SimpleChatHome[] chatHomes; + private final SimpleChatHomeService[] chatHomes; private final Set ownedShards; private final ShardingStrategy shardingStrategy; - public ShardedChatHome( - SimpleChatHome[] chatHomes, + public ShardedChatHomeService( + SimpleChatHomeService[] chatHomes, ShardingStrategy shardingStrategy) { this.chatHomes = chatHomes; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeService.java index 868c01e8..d9c31546 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeService.java @@ -12,7 +12,7 @@ import java.util.*; @Slf4j -public class SimpleChatHome implements ChatHome +public class SimpleChatHomeService implements ChatHomeService { private final Integer shard; private final Map chatRoomInfo; @@ -22,7 +22,7 @@ public class SimpleChatHome implements ChatHome - public SimpleChatHome( + public SimpleChatHomeService( StorageStrategy storageStrategy, Clock clock, int bufferSize) @@ -34,7 +34,7 @@ public class SimpleChatHome implements ChatHome bufferSize); } - public SimpleChatHome( + public SimpleChatHomeService( Integer shard, StorageStrategy storageStrategy, Clock clock, diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeService.java index 86b32707..d3321d71 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeService.java @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend.persistence.kafka; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.domain.ChatRoomInfo; import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException; @@ -15,7 +15,7 @@ import java.util.*; @RequiredArgsConstructor @Slf4j -public class KafkaChatHome implements ChatHome +public class KafkaChatHomeService implements ChatHomeService { private final int numPartitions; private final ChatRoomChannel chatRoomChannel; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java index df4faed8..c4479ce5 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.kafka; import de.juplo.kafka.chat.backend.ChatBackendProperties; -import de.juplo.kafka.chat.backend.domain.ChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.persistence.kafka.messages.AbstractMessageTo; import de.juplo.kafka.chat.backend.persistence.kafka.messages.CommandCreateChatRoomTo; import de.juplo.kafka.chat.backend.persistence.kafka.messages.EventChatMessageReceivedTo; @@ -34,11 +34,11 @@ import java.util.Properties; public class KafkaServicesConfiguration { @Bean - ChatHome kafkaChatHome( + ChatHomeService kafkaChatHome( ChatBackendProperties properties, ChatRoomChannel chatRoomChannel) { - return new KafkaChatHome( + return new KafkaChatHomeService( properties.getKafka().getNumPartitions(), chatRoomChannel); } 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 f831dbaf..946498ab 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 @@ -34,7 +34,7 @@ public class ChatBackendControllerTest ChatBackendProperties properties; @MockBean - ChatHome chatHome; + ChatHomeService chatHomeService; @MockBean ChatRoomService chatRoomService; @@ -44,7 +44,7 @@ public class ChatBackendControllerTest { // Given UUID chatroomId = UUID.randomUUID(); - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); // When WebTestClient.ResponseSpec responseSpec = client @@ -64,7 +64,7 @@ public class ChatBackendControllerTest { // Given UUID chatroomId = UUID.randomUUID(); - when(chatHome.getChatRoomInfo(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); + when(chatHomeService.getChatRoomInfo(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); // When WebTestClient.ResponseSpec responseSpec = client @@ -85,7 +85,7 @@ public class ChatBackendControllerTest UUID chatroomId = UUID.randomUUID(); String username = "foo"; Long messageId = 66l; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); // When WebTestClient.ResponseSpec responseSpec = client @@ -111,7 +111,7 @@ public class ChatBackendControllerTest UUID chatroomId = UUID.randomUUID(); String username = "foo"; Long messageId = 66l; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); // When WebTestClient.ResponseSpec responseSpec = client @@ -134,7 +134,7 @@ public class ChatBackendControllerTest { // Given UUID chatroomId = UUID.randomUUID(); - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new UnknownChatroomException(chatroomId)); // When WebTestClient.ResponseSpec responseSpec = client @@ -176,7 +176,7 @@ public class ChatBackendControllerTest Clock.systemDefaultZone(), chatRoomService, 8); - when(chatHome.getChatRoomData(eq(chatroomId))).thenReturn(Mono.just(chatRoomData)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenReturn(Mono.just(chatRoomData)); Message existingMessage = new Message( key, serialNumberExistingMessage, @@ -226,7 +226,7 @@ public class ChatBackendControllerTest Clock.systemDefaultZone(), chatRoomService, 8); - when(chatHome.getChatRoomData(any(UUID.class))) + when(chatHomeService.getChatRoomData(any(UUID.class))) .thenReturn(Mono.just(chatRoomData)); when(chatRoomService.getMessage(any(Message.MessageKey.class))) .thenReturn(Mono.empty()); @@ -260,7 +260,7 @@ public class ChatBackendControllerTest // Given UUID chatroomId = UUID.randomUUID(); int shard = 666; - when(chatHome.getChatRoomInfo(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); + when(chatHomeService.getChatRoomInfo(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); // When WebTestClient.ResponseSpec responseSpec = client @@ -280,7 +280,7 @@ public class ChatBackendControllerTest // Given UUID chatroomId = UUID.randomUUID(); int shard = 666; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); // When WebTestClient.ResponseSpec responseSpec = client @@ -302,7 +302,7 @@ public class ChatBackendControllerTest String username = "foo"; Long messageId = 66l; int shard = 666; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); // When WebTestClient.ResponseSpec responseSpec = client @@ -329,7 +329,7 @@ public class ChatBackendControllerTest String username = "foo"; Long messageId = 66l; int shard = 666; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); // When WebTestClient.ResponseSpec responseSpec = client @@ -353,7 +353,7 @@ public class ChatBackendControllerTest // Given UUID chatroomId = UUID.randomUUID(); int shard = 666; - when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); + when(chatHomeService.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard)); // When WebTestClient.ResponseSpec responseSpec = client diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java index 62826432..984da1de 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java @@ -17,10 +17,10 @@ import static pl.rzrz.assertj.reactor.Assertions.assertThat; @ExtendWith(SpringExtension.class) -public abstract class ChatHomeTest +public abstract class ChatHomeServiceTest { @Autowired - ChatHome chatHome; + ChatHomeService chatHomeService; @Test @@ -32,7 +32,7 @@ public abstract class ChatHomeTest // When Mono mono = Mono - .defer(() -> chatHome.getChatRoomData(chatRoomId)) + .defer(() -> chatHomeService.getChatRoomData(chatRoomId)) .log("testGetExistingChatroom") .retryWhen(Retry .backoff(5, Duration.ofSeconds(1)) @@ -51,7 +51,7 @@ public abstract class ChatHomeTest // When Mono mono = Mono - .defer(() -> chatHome.getChatRoomData(chatRoomId)) + .defer(() -> chatHomeService.getChatRoomData(chatRoomId)) .log("testGetNonExistentChatroom") .retryWhen(Retry .backoff(5, Duration.ofSeconds(1)) diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceWithShardsTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceWithShardsTest.java index 65a67b99..5eeac471 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceWithShardsTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceWithShardsTest.java @@ -13,7 +13,7 @@ import java.util.UUID; import static pl.rzrz.assertj.reactor.Assertions.assertThat; -public abstract class ChatHomeWithShardsTest extends ChatHomeTest +public abstract class ChatHomeServiceWithShardsTest extends ChatHomeServiceTest { public static final int NUM_SHARDS = 10; public static final int OWNED_SHARD = 2; @@ -29,7 +29,7 @@ public abstract class ChatHomeWithShardsTest extends ChatHomeTest // When Mono mono = Mono - .defer(() -> chatHome.getChatRoomData(chatRoomId)) + .defer(() -> chatHomeService.getChatRoomData(chatRoomId)) .log("testGetChatroomForNotOwnedShard") .retryWhen(Retry .backoff(5, Duration.ofSeconds(1)) diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java index 142f7099..3d311a4e 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.domain.ChatHome; -import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; +import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHomeService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -21,13 +21,13 @@ public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyI { int bufferSize = 8; - SimpleChatHome simpleChatHome = new SimpleChatHome( + SimpleChatHomeService simpleChatHome = new SimpleChatHomeService( getStorageStrategy(), clock, bufferSize); @Override - public ChatHome getChatHome() + public ChatHomeService getChatHome() { return simpleChatHome; } 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 e619649a..c2149bba 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 @@ -13,7 +13,7 @@ import static pl.rzrz.assertj.reactor.Assertions.*; @Slf4j public abstract class AbstractStorageStrategyIT { - protected ChatHome chathome; + protected ChatHomeService chathome; protected abstract StorageStrategy getStorageStrategy(); @@ -114,6 +114,6 @@ public abstract class AbstractStorageStrategyIT interface StorageStrategyITConfig { - ChatHome getChatHome(); + ChatHomeService getChatHome(); } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeServiceTest.java index 8d9036f0..0363f5dc 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeServiceTest.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.inmemory; import com.fasterxml.jackson.databind.ObjectMapper; -import de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTest; +import de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest; import de.juplo.kafka.chat.backend.persistence.ShardingStrategy; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy; @@ -12,21 +12,21 @@ import java.nio.file.Paths; import java.time.Clock; import java.util.stream.IntStream; -public class ShardedChatHomeTest extends ChatHomeWithShardsTest +public class ShardedChatHomeServiceTest extends ChatHomeServiceWithShardsTest { @TestConfiguration static class Configuration { @Bean - ShardedChatHome chatHome( + ShardedChatHomeService chatHome( StorageStrategy storageStrategy, Clock clock) { - SimpleChatHome[] chatHomes = new SimpleChatHome[NUM_SHARDS]; + SimpleChatHomeService[] chatHomes = new SimpleChatHomeService[NUM_SHARDS]; IntStream .of(ownedShards()) - .forEach(shard -> chatHomes[shard] = new SimpleChatHome( + .forEach(shard -> chatHomes[shard] = new SimpleChatHomeService( shard, storageStrategy, clock, @@ -34,7 +34,7 @@ public class ShardedChatHomeTest extends ChatHomeWithShardsTest ShardingStrategy strategy = new KafkaLikeShardingStrategy(NUM_SHARDS); - return new ShardedChatHome(chatHomes, strategy); + return new ShardedChatHomeService(chatHomes, strategy); } @Bean diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeServiceTest.java index 8be31731..3e3311c6 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeServiceTest.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.inmemory; import com.fasterxml.jackson.databind.ObjectMapper; -import de.juplo.kafka.chat.backend.domain.ChatHomeTest; +import de.juplo.kafka.chat.backend.domain.ChatHomeServiceTest; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy; import org.springframework.boot.test.context.TestConfiguration; @@ -11,17 +11,17 @@ import java.nio.file.Paths; import java.time.Clock; -public class SimpleChatHomeTest extends ChatHomeTest +public class SimpleChatHomeServiceTest extends ChatHomeServiceTest { @TestConfiguration static class Configuration { @Bean - SimpleChatHome chatHome( + SimpleChatHomeService chatHome( StorageStrategy storageStrategy, Clock clock) { - return new SimpleChatHome( + return new SimpleChatHomeService( storageStrategy, clock, bufferSize()); diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeServiceTest.java index d758a22d..3633aa5f 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeServiceTest.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence.kafka; import de.juplo.kafka.chat.backend.ChatBackendProperties; -import de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTest; +import de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.producer.ProducerRecord; @@ -24,13 +24,13 @@ import java.time.Clock; import java.util.List; import java.util.concurrent.CompletableFuture; -import static de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTest.NUM_SHARDS; -import static de.juplo.kafka.chat.backend.persistence.kafka.KafkaChatHomeTest.TOPIC; +import static de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest.NUM_SHARDS; +import static de.juplo.kafka.chat.backend.persistence.kafka.KafkaChatHomeServiceTest.TOPIC; @SpringBootTest( classes = { - KafkaChatHomeTest.KafkaChatHomeTestConfiguration.class, + KafkaChatHomeServiceTest.KafkaChatHomeTestConfiguration.class, KafkaServicesConfiguration.class, KafkaAutoConfiguration.class, TaskExecutionAutoConfiguration.class, @@ -45,7 +45,7 @@ import static de.juplo.kafka.chat.backend.persistence.kafka.KafkaChatHomeTest.TO }) @EmbeddedKafka(topics = { TOPIC }, partitions = 10) @Slf4j -public class KafkaChatHomeTest extends ChatHomeWithShardsTest +public class KafkaChatHomeServiceTest extends ChatHomeServiceWithShardsTest { final static String TOPIC = "KAFKA_CHAT_HOME_TEST"; -- 2.20.1