|
26 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
27 | 27 |
|
28 | 28 | import com.michelin.kafka.error.handling.papi.handler.ExceptionTypeProcessingHandler;
|
| 29 | +import com.michelin.kafka.error.handling.papi.handler.ProcessorIdProcessingHandler; |
| 30 | +import com.michelin.kafka.error.handling.papi.handler.RecordTypeProcessingHandler; |
29 | 31 | import java.time.Duration;
|
30 | 32 | import java.util.List;
|
31 | 33 | import java.util.Properties;
|
| 34 | +import java.util.stream.Stream; |
32 | 35 | import org.apache.kafka.common.MetricName;
|
33 | 36 | import org.apache.kafka.common.serialization.StringDeserializer;
|
34 | 37 | import org.apache.kafka.common.serialization.StringSerializer;
|
|
38 | 41 | import org.apache.kafka.streams.TestOutputTopic;
|
39 | 42 | import org.apache.kafka.streams.TopologyTestDriver;
|
40 | 43 | import org.junit.jupiter.api.AfterEach;
|
41 |
| -import org.junit.jupiter.api.BeforeEach; |
42 |
| -import org.junit.jupiter.api.Test; |
| 44 | +import org.junit.jupiter.params.ParameterizedTest; |
| 45 | +import org.junit.jupiter.params.provider.MethodSource; |
43 | 46 |
|
44 | 47 | class KafkaStreamsAppTest {
|
45 | 48 | private TopologyTestDriver testDriver;
|
46 | 49 | private TestInputTopic<String, String> inputTopic;
|
47 | 50 | private TestOutputTopic<String, String> outputTopic;
|
48 | 51 |
|
49 |
| - @BeforeEach |
50 |
| - void setUp() { |
51 |
| - Properties properties = new Properties(); |
52 |
| - properties.setProperty(APPLICATION_ID_CONFIG, "processing-error-handling-papi-app"); |
53 |
| - properties.setProperty(BOOTSTRAP_SERVERS_CONFIG, "dummy:1234"); |
54 |
| - properties.setProperty( |
55 |
| - PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG, ExceptionTypeProcessingHandler.class.getName()); |
56 |
| - |
57 |
| - StreamsBuilder streamsBuilder = new StreamsBuilder(); |
58 |
| - KafkaStreamsApp.buildTopology(streamsBuilder); |
59 |
| - testDriver = new TopologyTestDriver(streamsBuilder.build(), properties); |
60 |
| - |
61 |
| - inputTopic = |
62 |
| - testDriver.createInputTopic("delivery_booked_topic", new StringSerializer(), new StringSerializer()); |
63 |
| - outputTopic = testDriver.createOutputTopic( |
64 |
| - "filtered_delivery_booked_papi_topic", new StringDeserializer(), new StringDeserializer()); |
65 |
| - } |
66 |
| - |
67 | 52 | @AfterEach
|
68 | 53 | void tearDown() {
|
69 | 54 | testDriver.close();
|
70 | 55 | }
|
71 | 56 |
|
72 |
| - @Test |
73 |
| - void shouldContinueOnInvalidDeliveryAndNullPointerExceptions() { |
| 57 | + static Stream<String> provideProcessingExceptionHandlerClassName() { |
| 58 | + return Stream.of( |
| 59 | + ExceptionTypeProcessingHandler.class.getName(), |
| 60 | + ProcessorIdProcessingHandler.class.getName(), |
| 61 | + RecordTypeProcessingHandler.class.getName()); |
| 62 | + } |
| 63 | + |
| 64 | + @ParameterizedTest |
| 65 | + @MethodSource("provideProcessingExceptionHandlerClassName") |
| 66 | + void shouldContinueOnInvalidDeliveryAndNullPointerExceptions(String processingExceptionHandlerClassName) { |
| 67 | + instantiateTopologyTestDriver(processingExceptionHandlerClassName); |
| 68 | + |
74 | 69 | inputTopic.pipeInput(
|
75 | 70 | "DEL12345",
|
76 | 71 | """
|
@@ -117,6 +112,22 @@ void shouldContinueOnInvalidDeliveryAndNullPointerExceptions() {
|
117 | 112 | testDriver.metrics().get(droppedRecordsRateMetric()).metricValue());
|
118 | 113 | }
|
119 | 114 |
|
| 115 | + void instantiateTopologyTestDriver(String processingExceptionHandlerClassName) { |
| 116 | + Properties properties = new Properties(); |
| 117 | + properties.setProperty(APPLICATION_ID_CONFIG, "processing-error-handling-papi-app"); |
| 118 | + properties.setProperty(BOOTSTRAP_SERVERS_CONFIG, "dummy:1234"); |
| 119 | + properties.setProperty(PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG, processingExceptionHandlerClassName); |
| 120 | + |
| 121 | + StreamsBuilder streamsBuilder = new StreamsBuilder(); |
| 122 | + KafkaStreamsApp.buildTopology(streamsBuilder); |
| 123 | + testDriver = new TopologyTestDriver(streamsBuilder.build(), properties); |
| 124 | + |
| 125 | + inputTopic = |
| 126 | + testDriver.createInputTopic("delivery_booked_topic", new StringSerializer(), new StringSerializer()); |
| 127 | + outputTopic = testDriver.createOutputTopic( |
| 128 | + "filtered_delivery_booked_papi_topic", new StringDeserializer(), new StringDeserializer()); |
| 129 | + } |
| 130 | + |
120 | 131 | private MetricName droppedRecordsTotalMetric() {
|
121 | 132 | return createMetric("dropped-records-total", "The total number of dropped records");
|
122 | 133 | }
|
|
0 commit comments