c65908c4465cd51a9c98e22f8269bd86861b05d1
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / domain / ChatHomeWithShardsTest.java
1 package de.juplo.kafka.chat.backend.domain;
2
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import reactor.core.publisher.Mono;
6 import reactor.util.retry.Retry;
7
8 import java.time.Duration;
9 import java.util.UUID;
10
11 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
12
13
14 public abstract class ChatHomeWithShardsTest extends ChatHomeTest
15 {
16   public static final int NUM_SHARDS = 10;
17   public static final int OWNED_SHARD = 2;
18   public static final int NOT_OWNED_SHARD = 0;
19
20
21   @Test
22   @DisplayName("Assert ShardNotOwnedException is thrown, if the shard for the chatroom is not owned")
23   void testGetChatroomForNotOwnedShard()
24   {
25     // Given
26     UUID chatRoomId = UUID.fromString("4e7246a6-29ae-43ea-b56f-669c3481ac19");
27
28     // When
29     Mono<ChatRoomData> mono = Mono
30         .defer(() -> chatHome.getChatRoomData(chatRoomId))
31         .log("testGetChatroomForNotOwnedShard")
32         .retryWhen(Retry
33             .backoff(5, Duration.ofSeconds(1))
34             .filter(throwable -> throwable instanceof LoadInProgressException));
35
36     // Then
37     assertThat(mono).sendsError(e ->
38     {
39       assertThat(e).isInstanceOf(ShardNotOwnedException.class);
40       ShardNotOwnedException shardNotOwnedException = (ShardNotOwnedException) e;
41       assertThat(shardNotOwnedException.getShard()).isEqualTo(NOT_OWNED_SHARD);
42     });
43   }
44 }