From: Kai Moritz Date: Thu, 20 Apr 2023 12:14:40 +0000 (+0200) Subject: NEU X-Git-Tag: rebase--2023-08-18~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=9decca68f2b60cea57b221d0952a6a1d1bd6b03b;p=demos%2Fkafka%2Fchat NEU --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java index e633cb92..9692a5bd 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java @@ -1,8 +1,14 @@ package de.juplo.kafka.chat.backend; +import de.juplo.kafka.chat.backend.domain.ShardingStrategy; +import org.junit.jupiter.api.BeforeAll; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.test.context.EmbeddedKafka; +import java.util.UUID; + import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.TOPIC; @@ -12,10 +18,26 @@ import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.TOPIC; "chat.backend.services=kafka", "chat.backend.kafka.client-id=TEST", "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", + "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", "chat.backend.kafka.topic=" + TOPIC, "chat.backend.kafka.num-partitions=3" }) @EmbeddedKafka(topics = TOPIC, partitions = 3) class KafkaConfigurationIT extends AbstractConfigurationIT { final static String TOPIC = "TEST"; + + @BeforeAll + public static void test( + @Autowired ShardingStrategy shardingStrategy, + @Autowired KafkaTemplate messageTemplate, + @Autowired KafkaTemplate chatRoomTemplate) + { + UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7"); + int shard = shardingStrategy.selectShard(chatRoomId); + chatRoomTemplate.send(TOPIC, null,"{\"id\":\"5c73531c-6fc4-426c-adcb-afc5c140a0f7\",\"shard\":" + shard + ",\"name\":\"FOO\""); + messageTemplate.send(TOPIC,"5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"peter\", \"text\" : \"Hallo, ich heiße Peter!\" }"); + messageTemplate.send(TOPIC,"5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"ute\", \"text\" : \"Ich bin Ute...\" }"); + messageTemplate.send(TOPIC,"5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 2, \"user\" : \"peter\", \"text\" : \"Willst du mit mir gehen?\" }"); + messageTemplate.send(TOPIC,"5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"klaus\", \"text\" : \"Ja? Nein? Vielleicht??\" }"); + } } diff --git a/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json b/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json index af5e6e01..cedabf73 100644 --- a/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json +++ b/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json @@ -1,25 +1,4 @@ -[ { - "id" : 1, - "serial" : 0, - "time" : "2023-01-13T21:46:51.846312215", - "user" : "peter", - "text" : "Hallo, ich heiße Peter!" -}, { - "id" : 1, - "serial" : 1, - "time" : "2023-01-13T21:46:51.847319045", - "user" : "ute", - "text" : "Ich bin Ute..." -}, { - "id" : 2, - "serial" : 2, - "time" : "2023-01-13T21:46:51.847415356", - "user" : "peter", - "text" : "Willst du mit mir gehen?" -}, { - "id" : 1, - "serial" : 3, - "time" : "2023-01-13T21:46:51.847465432", - "user" : "klaus", - "text" : "Ja? Nein? Vielleicht??" -} ] \ No newline at end of file +{ "id" : 1, "user" : "peter", "text" : "Hallo, ich heiße Peter!" } +{ "id" : 1, "user" : "ute", "text" : "Ich bin Ute..." } +{ "id" : 2, "user" : "peter", "text" : "Willst du mit mir gehen?" } +{ "id" : 1, "user" : "klaus", "text" : "Ja? Nein? Vielleicht??" }