name = "sharding-strategy",
havingValue = "none",
matchIfMissing = true)
- ChatHome noneShardingChatHome(StorageStrategy storageStrategy)
+ ChatHome noneShardingChatHome(
+ ChatBackendProperties properties,
+ StorageStrategy storageStrategy,
+ Clock clock)
{
- return new SimpleChatHome(storageStrategy.read());
+ return new SimpleChatHome(
+ storageStrategy.read(),
+ clock,
+ properties.getChatroomBufferSize());
}
@Bean
havingValue = "kafkalike")
ChatHome kafkalikeShardingChatHome(
ChatBackendProperties properties,
- StorageStrategy storageStrategy)
+ StorageStrategy storageStrategy,
+ Clock clock)
{
int numShards = properties.getInmemory().getNumShards();
SimpleChatHome[] chatHomes = new SimpleChatHome[numShards];
IntStream
.of(properties.getInmemory().getOwnedShards())
- .forEach(shard -> chatHomes[shard] = new SimpleChatHome(shard, storageStrategy.read()));
+ .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
+ shard,
+ storageStrategy.read(),
+ clock,
+ properties.getChatroomBufferSize()));
ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
return new ShardedChatHome(chatHomes, strategy);
}
- @Bean
- InMemoryChatRoomFactory chatRoomFactory(
- ShardingStrategy strategy,
- Clock clock,
- ChatBackendProperties properties)
- {
- return new InMemoryChatRoomFactory(
- strategy,
- clock,
- properties.getChatroomBufferSize());
- }
-
@ConditionalOnProperty(
prefix = "chat.backend.inmemory",
name = "sharding-strategy",
public abstract class AbstractStorageStrategyIT
{
protected ChatHome chathome;
- protected ChatRoomFactory chatRoomFactory;
protected abstract StorageStrategy getStorageStrategy();
{
StorageStrategyITConfig config = getConfig();
chathome = config.getChatHome();
- chatRoomFactory = config.getChatRoomFactory();
}
protected void stop()
assertThat(chathome.getChatRooms().toStream()).hasSize(0);
UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
- ChatRoomInfo info = chatRoomFactory.createChatRoom(chatRoomId, "FOO").block();
+ ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block();
log.debug("Created chat-room {}", info);
ChatRoom chatroom = chathome.getChatRoom(chatRoomId).block();
Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
assertThat(chathome.getChatRooms().toStream()).hasSize(0);
UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
- ChatRoomInfo infoA = chatRoomFactory.createChatRoom(chatRoomAId, "FOO").block();
+ ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block();
log.debug("Created chat-room {}", infoA);
ChatRoom chatroomA = chathome.getChatRoom(chatRoomAId).block();
Message ma1 = chatroomA.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
Message ma4 = chatroomA.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
UUID chatRoomBId = UUID.fromString("8763dfdc-4dda-4a74-bea4-4b389177abea");
- ChatRoomInfo infoB = chatRoomFactory.createChatRoom(chatRoomBId, "BAR").block();
+ ChatRoomInfo infoB = chathome.createChatRoom(chatRoomBId, "BAR").block();
log.debug("Created chat-room {}", infoB);
ChatRoom chatroomB = chathome.getChatRoom(chatRoomBId).block();
Message mb1 = chatroomB.addMessage(1l,"peter", "Hallo, ich heiße Uwe!").block();
interface StorageStrategyITConfig
{
ChatHome getChatHome();
- ChatRoomFactory getChatRoomFactory();
}
}
{
@Bean
ShardedChatHome chatHome(
- InMemoryChatHomeService chatHomeService)
+ StorageStrategy storageStrategy,
+ Clock clock)
{
SimpleChatHome[] chatHomes = new SimpleChatHome[NUM_SHARDS];
IntStream
.of(ownedShards())
- .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard));
+ .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
+ shard,
+ storageStrategy.read(),
+ clock,
+ bufferSize()));
ShardingStrategy strategy = new KafkaLikeShardingStrategy(NUM_SHARDS);
}
@Bean
- InMemoryChatHomeService chatHomeService(
- StorageStrategy storageStrategy)
- {
- return new InMemoryChatHomeService(
- NUM_SHARDS,
- ownedShards(),
- storageStrategy.read());
- }
-
- @Bean
- public FilesStorageStrategy storageStrategy()
+ public FilesStorageStrategy storageStrategy(Clock clock)
{
return new FilesStorageStrategy(
Paths.get("target", "test-classes", "data", "files"),
- Clock.systemDefaultZone(),
- 8,
+ clock,
+ bufferSize(),
new KafkaLikeShardingStrategy(NUM_SHARDS),
messageFlux -> new InMemoryChatRoomService(messageFlux),
new ObjectMapper());
}
+ @Bean
+ Clock clock()
+ {
+ return Clock.systemDefaultZone();
+ }
+
int[] ownedShards()
{
return new int[] { OWNED_SHARD };
}
+
+ int bufferSize()
+ {
+ return 8;
+ }
}
}
static class Configuration
{
@Bean
- SimpleChatHome chatHome(InMemoryChatHomeService chatHomeService)
+ SimpleChatHome chatHome(
+ StorageStrategy storageStrategy,
+ Clock clock)
{
- return new SimpleChatHome(chatHomeService);
+ return new SimpleChatHome(
+ storageStrategy.read(),
+ clock,
+ bufferSize());
}
@Bean
- InMemoryChatHomeService chatHomeService(StorageStrategy storageStrategy)
- {
- return new InMemoryChatHomeService(
- 1,
- new int[] { 0 },
- storageStrategy.read());
- }
-
- @Bean
- public FilesStorageStrategy storageStrategy()
+ public FilesStorageStrategy storageStrategy(Clock clock)
{
return new FilesStorageStrategy(
Paths.get("target", "test-classes", "data", "files"),
- Clock.systemDefaultZone(),
- 8,
+ clock,
+ bufferSize(),
chatRoomId -> 0,
messageFlux -> new InMemoryChatRoomService(messageFlux),
new ObjectMapper());
}
+
+ @Bean
+ Clock clock()
+ {
+ return Clock.systemDefaultZone();
+ }
+
+ int bufferSize()
+ {
+ return 8;
+ }
}
}