1 package de.juplo.kafka;
3 import lombok.extern.slf4j.Slf4j;
4 import org.assertj.core.api.Assertions;
5 import org.junit.jupiter.api.*;
6 import org.junit.jupiter.api.extension.ExtendWith;
7 import org.springframework.beans.factory.annotation.Value;
8 import org.springframework.kafka.test.context.EmbeddedKafka;
9 import org.springframework.test.context.junit.jupiter.SpringExtension;
11 import java.time.Duration;
12 import java.util.concurrent.CompletableFuture;
14 import static de.juplo.kafka.ApplicationTests.PARTITIONS;
15 import static de.juplo.kafka.ApplicationTests.TOPIC;
16 import static org.awaitility.Awaitility.*;
19 @ExtendWith(SpringExtension.class)
22 partitions = PARTITIONS,
24 "transaction.state.log.replication.factor=1",
25 "transaction.state.log.min.isr=1" })
27 public class ApplicationTests
29 static final String TOPIC = "FOO";
30 static final int PARTITIONS = 10;
32 @Value("${spring.embedded.kafka.brokers}")
33 String bootstrapServers;
36 void testConcurrentProducers() throws Exception
38 SimpleProducer instanceA = new SimpleProducer(
42 SimpleProducer instanceB = new SimpleProducer(
47 CompletableFuture<Long> result;
50 result = instanceA.send("a","message #1");
51 Assertions.assertThat(result.isCompletedExceptionally()).isFalse();
54 result = instanceB.send("b","message #1");
55 Assertions.assertThat(result.isCompletedExceptionally()).isFalse();
57 result = instanceA.send("a","message #2");
58 Assertions.assertThat(result.isCompletedExceptionally()).isTrue();
60 result = instanceB.send("b","message #2");
61 Assertions.assertThat(result.isCompletedExceptionally()).isFalse();