TMP
[demos/kafka/training] / src / test / java / de / juplo / kafka / ApplicationTests.java
index fc5d4c9..09614b8 100644 (file)
@@ -6,7 +6,6 @@ import org.apache.kafka.clients.consumer.KafkaConsumer;
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.ProducerRecord;
 import org.apache.kafka.common.TopicPartition;
-import org.apache.kafka.common.errors.RecordDeserializationException;
 import org.apache.kafka.common.serialization.*;
 import org.apache.kafka.common.utils.Bytes;
 import org.junit.jupiter.api.*;
@@ -60,7 +59,7 @@ class ApplicationTests
        @Autowired
        KafkaProducer<String, Bytes> kafkaProducer;
        @Autowired
-       KafkaConsumer<String, Long> kafkaConsumer;
+       KafkaConsumer<String, String> kafkaConsumer;
        @Autowired
        KafkaConsumer<Bytes, Bytes> offsetConsumer;
        @Autowired
@@ -72,14 +71,14 @@ class ApplicationTests
        @Autowired
        PartitionStatisticsRepository repository;
        @Autowired
-       KeyCountingRebalanceListener keyCountingRebalanceListener;
+       SumRebalanceListener sumRebalanceListener;
        @Autowired
-       KeyCountingRecordHandler keyCountingRecordHandler;
+       SumRecordHandler sumRecordHandler;
 
-       EndlessConsumer<String, Long> endlessConsumer;
+       EndlessConsumer<String, String> endlessConsumer;
        Map<TopicPartition, Long> oldOffsets;
        Map<TopicPartition, Long> newOffsets;
-       Set<ConsumerRecord<String, Long>> receivedRecords;
+       Set<ConsumerRecord<String, String>> receivedRecords;
 
 
        /** Tests methods */
@@ -112,45 +111,6 @@ class ApplicationTests
                                .describedAs("Consumer should still be running");
        }
 
-       @Test
-       void commitsOffsetOfErrorForReprocessingOnDeserializationError()
-       {
-               send100Messages((partition, key, counter) ->
-               {
-                       Bytes value = counter == 77
-                                       ? new Bytes(stringSerializer.serialize(TOPIC, "BOOM!"))
-                                       : new Bytes(valueSerializer.serialize(TOPIC, counter));
-                       return new ProducerRecord<>(TOPIC, partition, key, value);
-               });
-
-               await("Consumer failed")
-                               .atMost(Duration.ofSeconds(30))
-                               .pollInterval(Duration.ofSeconds(1))
-                               .until(() -> !endlessConsumer.running());
-
-               checkSeenOffsetsForProgress();
-               compareToCommitedOffsets(newOffsets);
-
-               endlessConsumer.start();
-               await("Consumer failed")
-                               .atMost(Duration.ofSeconds(30))
-                               .pollInterval(Duration.ofSeconds(1))
-                               .until(() -> !endlessConsumer.running());
-
-               checkSeenOffsetsForProgress();
-               compareToCommitedOffsets(newOffsets);
-               assertThat(receivedRecords.size())
-                               .describedAs("Received not all sent events")
-                               .isLessThan(100);
-
-               assertThatNoException()
-                               .describedAs("Consumer should not be running")
-                               .isThrownBy(() -> endlessConsumer.exitStatus());
-               assertThat(endlessConsumer.exitStatus())
-                               .describedAs("Consumer should have exited abnormally")
-                               .containsInstanceOf(RecordDeserializationException.class);
-       }
-
 
        /** Helper methods for the verification of expectations */
 
@@ -214,7 +174,7 @@ class ApplicationTests
                        Optional<Long> offset = partitionStatisticsRepository.findById(partition).map(document -> document.offset);
                        consumer.accept(tp, offset.orElse(0l));
                });
-               }
+       }
 
        List<TopicPartition> partitions()
        {
@@ -282,10 +242,10 @@ class ApplicationTests
                        newOffsets.put(tp, offset - 1);
                });
 
-               TestRecordHandler<String, Long> captureOffsetAndExecuteTestHandler =
-                               new TestRecordHandler<String, Long>(keyCountingRecordHandler) {
+               TestRecordHandler<String, String> captureOffsetAndExecuteTestHandler =
+                               new TestRecordHandler<String, String>(sumRecordHandler) {
                                        @Override
-                                       public void onNewRecord(ConsumerRecord<String, Long> record)
+                                       public void onNewRecord(ConsumerRecord<String, String> record)
                                        {
                                                newOffsets.put(
                                                                new TopicPartition(record.topic(), record.partition()),
@@ -300,7 +260,7 @@ class ApplicationTests
                                                properties.getClientId(),
                                                properties.getTopic(),
                                                kafkaConsumer,
-                                               keyCountingRebalanceListener,
+                                               sumRebalanceListener,
                                                captureOffsetAndExecuteTestHandler);
 
                endlessConsumer.start();