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:
4052e4f
)
WIP:test: Simp...
author
Kai Moritz
<kai@juplo.de>
Fri, 25 Aug 2023 10:18:48 +0000
(12:18 +0200)
committer
Kai Moritz
<kai@juplo.de>
Fri, 25 Aug 2023 10:18:48 +0000
(12:18 +0200)
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTestBase.java
patch
|
blob
|
history
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
patch
|
blob
|
history
diff --git
a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTestBase.java
b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTestBase.java
index
587c754
..
c7f8c11
100644
(file)
--- a/
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTestBase.java
+++ b/
src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeWithShardsTestBase.java
@@
-11,6
+11,11
@@
import static pl.rzrz.assertj.reactor.Assertions.assertThat;
public class ChatHomeWithShardsTestBase extends ChatHomeTestBase
{
public class ChatHomeWithShardsTestBase extends ChatHomeTestBase
{
+ public static final int NUM_SHARDS = 10;
+ public static final int OWNED_SHARD = 2;
+ public static final int NOT_OWNED_SHARD = 0;
+
+
@Test
@DisplayName("Assert ShardNotOwnedException is thrown, if the shard for the chatroom is not owned")
void testGetChatroomForNotOwnedShard()
@Test
@DisplayName("Assert ShardNotOwnedException is thrown, if the shard for the chatroom is not owned")
void testGetChatroomForNotOwnedShard()
@@
-26,7
+31,7
@@
public class ChatHomeWithShardsTestBase extends ChatHomeTestBase
{
assertThat(e).isInstanceOf(ShardNotOwnedException.class);
ShardNotOwnedException shardNotOwnedException = (ShardNotOwnedException) e;
{
assertThat(e).isInstanceOf(ShardNotOwnedException.class);
ShardNotOwnedException shardNotOwnedException = (ShardNotOwnedException) e;
- assertThat(shardNotOwnedException.getShard()).isEqualTo(
0
);
+ assertThat(shardNotOwnedException.getShard()).isEqualTo(
NOT_OWNED_SHARD
);
});
}
}
});
}
}
diff --git
a/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
b/src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
index
d36bf22
..
9b4bde7
100644
(file)
--- a/
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
+++ b/
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHomeTest.java
@@
-11,7
+11,6
@@
import java.nio.file.Paths;
import java.time.Clock;
import java.util.stream.IntStream;
import java.time.Clock;
import java.util.stream.IntStream;
-
public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
{
@TestConfiguration
public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
{
@TestConfiguration
@@
-21,13
+20,13
@@
public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
ShardedChatHome chatHome(
InMemoryChatHomeService chatHomeService)
{
ShardedChatHome chatHome(
InMemoryChatHomeService chatHomeService)
{
- SimpleChatHome[] chatHomes = new SimpleChatHome[
numShards()
];
+ SimpleChatHome[] chatHomes = new SimpleChatHome[
NUM_SHARDS
];
IntStream
.of(ownedShards())
.forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
IntStream
.of(ownedShards())
.forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
- ShardingStrategy strategy = new KafkaLikeShardingStrategy(
numShards()
);
+ ShardingStrategy strategy = new KafkaLikeShardingStrategy(
NUM_SHARDS
);
return new ShardedChatHome(chatHomes, strategy);
}
return new ShardedChatHome(chatHomes, strategy);
}
@@
-37,7
+36,7
@@
public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
StorageStrategy storageStrategy)
{
return new InMemoryChatHomeService(
StorageStrategy storageStrategy)
{
return new InMemoryChatHomeService(
-
numShards()
,
+
NUM_SHARDS
,
ownedShards(),
storageStrategy.read());
}
ownedShards(),
storageStrategy.read());
}
@@
-49,19
+48,14
@@
public class ShardedChatHomeTest extends ChatHomeWithShardsTestBase
Paths.get("target", "test-classes", "data", "files"),
Clock.systemDefaultZone(),
8,
Paths.get("target", "test-classes", "data", "files"),
Clock.systemDefaultZone(),
8,
- new KafkaLikeShardingStrategy(
numShards()
),
+ new KafkaLikeShardingStrategy(
NUM_SHARDS
),
messageFlux -> new InMemoryChatRoomService(messageFlux),
new ObjectMapper());
}
messageFlux -> new InMemoryChatRoomService(messageFlux),
new ObjectMapper());
}
- Integer numShards()
- {
- return 10;
- }
-
int[] ownedShards()
{
int[] ownedShards()
{
- return new int[] {
2
};
+ return new int[] {
OWNED_SHARD
};
}
}
}
}
}
}