projects
/
demos
/
kafka
/
chat
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
dc53848
)
test: `StorageStrategy`-IT are restoring instead of recreating
author
Kai Moritz
<kai@juplo.de>
Thu, 22 Feb 2024 15:46:27 +0000
(16:46 +0100)
committer
Kai Moritz
<kai@juplo.de>
Thu, 22 Feb 2024 15:52:41 +0000
(16:52 +0100)
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryServicesConfiguration.java
patch
|
blob
|
history
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
patch
|
blob
|
history
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java
patch
|
blob
|
history
src/test/java/de/juplo/kafka/chat/backend/AbstractInMemoryStorageIT.java
patch
|
blob
|
history
src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java
patch
|
blob
|
history
src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryTestUtils.java
patch
|
blob
|
history
diff --git
a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryServicesConfiguration.java
b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryServicesConfiguration.java
index
518cf41
..
3f3d888
100644
(file)
--- a/
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryServicesConfiguration.java
+++ b/
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryServicesConfiguration.java
@@
-26,7
+26,7
@@
public class InMemoryServicesConfiguration
name = "sharding-strategy",
havingValue = "none",
matchIfMissing = true)
name = "sharding-strategy",
havingValue = "none",
matchIfMissing = true)
- ChatHomeService noneShardingChatHome(
+
Simple
ChatHomeService noneShardingChatHome(
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
@@
-43,7
+43,7
@@
public class InMemoryServicesConfiguration
prefix = "chat.backend.inmemory",
name = "sharding-strategy",
havingValue = "kafkalike")
prefix = "chat.backend.inmemory",
name = "sharding-strategy",
havingValue = "kafkalike")
- ChatHomeService kafkalikeShardingChatHome(
+
Sharded
ChatHomeService kafkalikeShardingChatHome(
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
ChatBackendProperties properties,
StorageStrategy storageStrategy,
Clock clock)
diff --git
a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
index
5c3fe2e
..
371d4a8
100644
(file)
--- a/
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
+++ b/
src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeService.java
@@
-49,6
+49,9
@@
public class SimpleChatHomeService implements ChatHomeService
Mono<Void> restore(StorageStrategy storageStrategy)
{
Mono<Void> restore(StorageStrategy storageStrategy)
{
+ chatRoomInfo.clear();
+ chatRoomData.clear();
+
return storageStrategy
.readChatRoomInfo()
.filter(info ->
return storageStrategy
.readChatRoomInfo()
.filter(info ->
diff --git
a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java
b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java
index
f8bebd6
..
b5a442f
100644
(file)
--- a/
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java
+++ b/
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java
@@
-109,7
+109,7
@@
public class KafkaServicesConfiguration
}
@Bean
}
@Bean
-
ChatHomeService kafkaChatHome(
+
Kafka
ChatHomeService kafkaChatHome(
ChatBackendProperties properties,
InfoChannel infoChannel,
DataChannel dataChannel)
ChatBackendProperties properties,
InfoChannel infoChannel,
DataChannel dataChannel)
diff --git
a/src/test/java/de/juplo/kafka/chat/backend/AbstractInMemoryStorageIT.java
b/src/test/java/de/juplo/kafka/chat/backend/AbstractInMemoryStorageIT.java
index
0ec0bc1
..
843b949
100644
(file)
--- a/
src/test/java/de/juplo/kafka/chat/backend/AbstractInMemoryStorageIT.java
+++ b/
src/test/java/de/juplo/kafka/chat/backend/AbstractInMemoryStorageIT.java
@@
-1,15
+1,11
@@
package de.juplo.kafka.chat.backend;
package de.juplo.kafka.chat.backend;
-import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
-import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration;
import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryTestUtils;
import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryTestUtils;
+import de.juplo.kafka.chat.backend.implementation.inmemory.SimpleChatHomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import java.time.Clock;
-
@ContextConfiguration(classes = InMemoryTestUtils.class)
@Slf4j
@ContextConfiguration(classes = InMemoryTestUtils.class)
@Slf4j
@@
-17,10
+13,12
@@
public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyI
{
@Autowired
InMemoryTestUtils testUtils;
{
@Autowired
InMemoryTestUtils testUtils;
+ @Autowired
+ SimpleChatHomeService simpleChatHomeService;
@Override
@Override
-
ChatHomeService getChatHom
e()
+
void restor
e()
{
{
-
return testUtils.createNoneShardingChatHomeService
();
+
testUtils.restore(simpleChatHomeService).block
();
}
}
}
}
diff --git
a/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java
b/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java
index
9568545
..
7c9c07c
100644
(file)
--- a/
src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java
+++ b/
src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java
@@
-28,19
+28,15
@@
import static pl.rzrz.assertj.reactor.Assertions.*;
@Slf4j
public abstract class AbstractStorageStrategyIT
{
@Slf4j
public abstract class AbstractStorageStrategyIT
{
+ @Autowired
ChatHomeService chathome;
ChatHomeService chathome;
-
@Autowired
StorageStrategy storageStrategy;
@Autowired
StorageStrategy storageStrategy;
- abstract ChatHomeService getChatHome();
- protected void start()
- {
- chathome = getChatHome();
- }
+ abstract void restore();
-
protected void stop
()
+
void store
()
{
storageStrategy
.write(chathome)
{
storageStrategy
.write(chathome)
@@
-48,9
+44,9
@@
public abstract class AbstractStorageStrategyIT
}
@Test
}
@Test
-
protected
void testStoreAndRecreate()
+ void testStoreAndRecreate()
{
{
-
start
();
+
restore
();
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
@@
-69,8
+65,8
@@
public abstract class AbstractStorageStrategyIT
.getChatRoomData(chatRoomId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
.getChatRoomData(chatRoomId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
- sto
p
();
-
start
();
+ sto
re
();
+
restore
();
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
@@
-80,9
+76,9
@@
public abstract class AbstractStorageStrategyIT
}
@Test
}
@Test
-
protected
void testStoreAndRecreateParallelChatRooms()
+ void testStoreAndRecreateParallelChatRooms()
{
{
-
start
();
+
restore
();
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
@@
-114,8
+110,8
@@
public abstract class AbstractStorageStrategyIT
.getChatRoomData(chatRoomBId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
.getChatRoomData(chatRoomBId)
.flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
- sto
p
();
-
start
();
+ sto
re
();
+
restore
();
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
diff --git
a/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryTestUtils.java
b/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryTestUtils.java
index
3f6cf9c
..
cfc8e72
100644
(file)
--- a/
src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryTestUtils.java
+++ b/
src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/InMemoryTestUtils.java
@@
-4,28
+4,19
@@
import de.juplo.kafka.chat.backend.ChatBackendProperties;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
+import reactor.core.publisher.Mono;
import java.time.Clock;
public class InMemoryTestUtils
{
import java.time.Clock;
public class InMemoryTestUtils
{
- private final InMemoryServicesConfiguration config =
- new InMemoryServicesConfiguration();
-
- @Autowired
- ChatBackendProperties properties;
@Autowired
StorageStrategy storageStrategy;
@Autowired
StorageStrategy storageStrategy;
- @Autowired
- Clock clock;
- public
ChatHomeService createNoneShardingChatHomeService(
)
+ public
Mono<Void> restore(SimpleChatHomeService simpleChatHomeService
)
{
{
- return config.noneShardingChatHome(
- properties,
- storageStrategy,
- clock);
+ return simpleChatHomeService.restore(storageStrategy);
}
}
}
}