bfb665ff16e8f6523c4604273f2fdbb7133dcd9b
[demos/kafka/training] / src / test / java / de / juplo / kafka / ApplicationTests.java
1 package de.juplo.kafka;
2
3 import lombok.extern.slf4j.Slf4j;
4 import org.junit.jupiter.api.*;
5 import org.junit.jupiter.api.extension.ExtendWith;
6 import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.kafka.test.context.EmbeddedKafka;
8 import org.springframework.test.context.junit.jupiter.SpringExtension;
9
10 import java.time.Duration;
11 import java.util.concurrent.CompletableFuture;
12
13 import static de.juplo.kafka.ApplicationTests.PARTITIONS;
14 import static de.juplo.kafka.ApplicationTests.TOPIC;
15 import static org.awaitility.Awaitility.*;
16
17
18 @ExtendWith(SpringExtension.class)
19 @EmbeddedKafka(topics = TOPIC, partitions = PARTITIONS)
20 @Slf4j
21 public class ApplicationTests
22 {
23         static final String TOPIC = "FOO";
24         static final int PARTITIONS = 10;
25
26   @Value("${spring.embedded.kafka.brokers}")
27   String bootstrapServers;
28
29         @Test
30         void testConcurrentProducers() throws Exception
31         {
32     SimpleProducer instanceA = new SimpleProducer(
33       bootstrapServers,
34       TOPIC,
35       "A");
36     SimpleProducer instanceB = new SimpleProducer(
37       bootstrapServers,
38       TOPIC,
39       "B");
40
41     CompletableFuture<Long> result;
42
43     result = instanceA.send("a","message #1");
44                 await("Sending of 1. message for A is completed")
45                                 .atMost(Duration.ofSeconds(5))
46                                 .until(() -> result.isDone());
47         }
48 }