1 package de.juplo.kafka;
3 import org.apache.kafka.clients.consumer.ConsumerRecord;
4 import org.apache.kafka.clients.producer.ProducerRecord;
5 import org.apache.kafka.common.serialization.LongSerializer;
6 import org.apache.kafka.common.serialization.StringSerializer;
7 import org.apache.kafka.common.utils.Bytes;
8 import org.springframework.boot.test.context.TestConfiguration;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Primary;
11 import org.springframework.test.context.ContextConfiguration;
14 import java.util.function.Consumer;
17 @ContextConfiguration(classes = ApplicationTests.Configuration.class)
18 public class ApplicationTests extends GenericApplicationTests<String, Long>
20 public ApplicationTests()
25 final StringSerializer stringSerializer = new StringSerializer();
26 final LongSerializer longSerializer = new LongSerializer();
31 int numberOfMessagesToGenerate,
32 Set<Integer> poisonPills,
33 Set<Integer> logicErrors,
34 Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
38 for (int partition = 0; partition < 10; partition++)
40 for (int key = 0; key < 10; key++)
42 if (++i > numberOfMessagesToGenerate)
45 Bytes value = new Bytes(longSerializer.serialize(TOPIC, (long)i));
46 if (logicErrors.contains(i))
48 value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE));
50 if (poisonPills.contains(i))
52 value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!"));
55 ProducerRecord<Bytes, Bytes> record =
59 new Bytes(stringSerializer.serialize(TOPIC,Integer.toString(partition*10+key%2))),
62 messageSender.accept(record);
71 public static class Configuration
75 public Consumer<ConsumerRecord<String, Long>> consumer()
79 if (record.value() == Long.MIN_VALUE)
80 throw new RuntimeException("BOOM (Logic-Error)!");