1 package de.juplo.kafka;
3 import org.apache.kafka.clients.producer.ProducerRecord;
4 import org.apache.kafka.common.serialization.LongSerializer;
5 import org.apache.kafka.common.serialization.StringSerializer;
6 import org.apache.kafka.common.utils.Bytes;
7 import org.springframework.boot.test.context.TestConfiguration;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.test.context.ContextConfiguration;
11 import java.util.function.Consumer;
14 @ContextConfiguration(classes = ApplicationTests.Configuration.class)
15 public class ApplicationTests extends GenericApplicationTests<String, Long>
17 public ApplicationTests()
22 final StringSerializer stringSerializer = new StringSerializer();
23 final LongSerializer longSerializer = new LongSerializer();
30 Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
34 for (int partition = 0; partition < 10; partition++)
36 for (int key = 0; key < 10000; key++)
40 Bytes value = new Bytes(longSerializer.serialize(TOPIC, (long)i));
45 value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE));
49 value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!"));
53 ProducerRecord<Bytes, Bytes> record =
57 new Bytes(stringSerializer.serialize(TOPIC,Integer.toString(partition*10+key%2))),
60 messageSender.accept(record);
71 public static class Configuration
74 public RecordHandler<String, Long> applicationRecordHandler()
78 if (record.value() == Long.MIN_VALUE)
79 throw new RuntimeException("BOOM (Logic-Error)!");