1 package de.juplo.kafka.chat.backend;
3 import de.juplo.kafka.chat.backend.domain.*;
4 import de.juplo.kafka.chat.backend.implementation.StorageStrategy;
5 import lombok.extern.slf4j.Slf4j;
6 import org.junit.jupiter.api.Test;
11 import static pl.rzrz.assertj.reactor.Assertions.*;
15 public abstract class AbstractStorageStrategyIT
17 protected ChatHomeService chathome;
20 protected abstract StorageStrategy getStorageStrategy();
21 protected abstract StorageStrategyITConfig getConfig();
23 protected void start()
25 StorageStrategyITConfig config = getConfig();
26 chathome = config.getChatHome();
37 protected void testStoreAndRecreate()
41 assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
43 UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
44 ChatRoomInfo info = chathome.createChatRoom(chatRoomId, "FOO").block();
45 log.debug("Created chat-room {}", info);
46 ChatRoomData chatroom = chathome.getChatRoomData(chatRoomId).block();
47 Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
48 Message m2 = chatroom.addMessage(1l, "ute", "Ich bin Ute...").block();
49 Message m3 = chatroom.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
50 Message m4 = chatroom.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
52 assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
53 assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
55 .getChatRoomData(chatRoomId)
56 .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
61 assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info));
62 assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info);
64 .getChatRoomData(chatRoomId)
65 .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
69 protected void testStoreAndRecreateParallelChatRooms()
73 assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0);
75 UUID chatRoomAId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
76 ChatRoomInfo infoA = chathome.createChatRoom(chatRoomAId, "FOO").block();
77 log.debug("Created chat-room {}", infoA);
78 ChatRoomData chatroomA = chathome.getChatRoomData(chatRoomAId).block();
79 Message ma1 = chatroomA.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
80 Message ma2 = chatroomA.addMessage(1l, "ute", "Ich bin Ute...").block();
81 Message ma3 = chatroomA.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
82 Message ma4 = chatroomA.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
84 UUID chatRoomBId = UUID.fromString("8763dfdc-4dda-4a74-bea4-4b389177abea");
85 ChatRoomInfo infoB = chathome.createChatRoom(chatRoomBId, "BAR").block();
86 log.debug("Created chat-room {}", infoB);
87 ChatRoomData chatroomB = chathome.getChatRoomData(chatRoomBId).block();
88 Message mb1 = chatroomB.addMessage(1l,"peter", "Hallo, ich heiße Uwe!").block();
89 Message mb2 = chatroomB.addMessage(1l, "ute", "Ich bin Ute...").block();
90 Message mb3 = chatroomB.addMessage(1l, "klaus", "Willst du mit mir gehen?").block();
91 Message mb4 = chatroomB.addMessage(2l, "peter", "Hä? Was jetzt?!? Isch glohb isch höb ühn däjah vüh...").block();
93 assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
94 assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
96 .getChatRoomData(chatRoomAId)
97 .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
98 assertThat(chathome.getChatRoomData(chatRoomBId)).emitsExactly(chatroomB);
100 .getChatRoomData(chatRoomBId)
101 .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
106 assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB));
107 assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA);
109 .getChatRoomData(chatRoomAId)
110 .flatMapMany(cr -> cr.getMessages())).emitsExactly(ma1, ma2, ma3, ma4);
111 assertThat(chathome.getChatRoomInfo(chatRoomBId)).emitsExactly(infoB);
113 .getChatRoomData(chatRoomBId)
114 .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4);
118 interface StorageStrategyITConfig
120 ChatHomeService getChatHome();