From 7a7926c1799495a3ed016cb1b204cbfe13f833f1 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 11 Sep 2022 13:42:57 +0200 Subject: [PATCH] =?utf8?q?Anzahl=20der=20Fehler=20f=C3=BCr=20die=20Test-Lo?= =?utf8?q?gik=20verf=C3=BCgbar=20gemacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/de/juplo/kafka/ApplicationTests.java | 41 +++++++++++++++---- .../juplo/kafka/GenericApplicationTests.java | 21 ++++++---- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/test/java/de/juplo/kafka/ApplicationTests.java b/src/test/java/de/juplo/kafka/ApplicationTests.java index bd9f449..e01fdd1 100644 --- a/src/test/java/de/juplo/kafka/ApplicationTests.java +++ b/src/test/java/de/juplo/kafka/ApplicationTests.java @@ -41,17 +41,22 @@ public class ApplicationTests extends GenericApplicationTests final StringSerializer stringSerializer = new StringSerializer(); final Bytes calculateMessage = new Bytes(stringSerializer.serialize(TOPIC, "{}")); - int counter = 0; + int counterMessages; + int counterPoisonPills; + int counterLogicErrors; Map> state; @Override - public int generate( + public void generate( boolean poisonPills, boolean logicErrors, Consumer> messageSender) { - counter = 0; + counterMessages = 0; + counterPoisonPills = 0; + counterLogicErrors = 0; + state = Arrays .stream(dieWilden13) @@ -76,8 +81,8 @@ public class ApplicationTests extends GenericApplicationTests key, calculateMessage, Message.Type.CALC, - poisonPill(poisonPills, pass, counter), - logicError(logicErrors, pass, counter), + poisonPill(poisonPills, pass, counterMessages), + logicError(logicErrors, pass, counterMessages), messageSender); state.get(seeräuber).add(new AdderResult(number[i], (number[i] + 1) * number[i] / 2)); // Pick next number to calculate @@ -90,13 +95,29 @@ public class ApplicationTests extends GenericApplicationTests key, new Bytes(stringSerializer.serialize(TOPIC, "{\"next\":" + message[i]++ + "}")), Message.Type.ADD, - poisonPill(poisonPills, pass, counter), - logicError(logicErrors, pass, counter), + poisonPill(poisonPills, pass, counterMessages), + logicError(logicErrors, pass, counterMessages), messageSender); } } + } + + @Override + public int getNumberOfMessages() + { + return counterMessages; + } - return counter; + @Override + public int getNumberOfPoisonPills() + { + return counterPoisonPills; + } + + @Override + public int getNumberOfLogicErrors() + { + return counterLogicErrors; } boolean poisonPill (boolean poisonPills, int pass, int counter) @@ -117,15 +138,17 @@ public class ApplicationTests extends GenericApplicationTests boolean logicError, Consumer> messageSender) { - counter++; + counterMessages++; if (logicError) { value = new Bytes(stringSerializer.serialize(TOPIC, "{\"next\":-1}")); + counterLogicErrors++; } if (poisonPill) { value = new Bytes("BOOM!".getBytes()); + counterPoisonPills++; } ProducerRecord record = new ProducerRecord<>(TOPIC, key, value); diff --git a/src/test/java/de/juplo/kafka/GenericApplicationTests.java b/src/test/java/de/juplo/kafka/GenericApplicationTests.java index 66a80ad..4793d96 100644 --- a/src/test/java/de/juplo/kafka/GenericApplicationTests.java +++ b/src/test/java/de/juplo/kafka/GenericApplicationTests.java @@ -92,8 +92,9 @@ abstract class GenericApplicationTests @Test void commitsCurrentOffsetsOnSuccess() throws Exception { - int numberOfGeneratedMessages = - recordGenerator.generate(false, false, messageSender); + recordGenerator.generate(false, false, messageSender); + + int numberOfGeneratedMessages = recordGenerator.getNumberOfMessages(); await(numberOfGeneratedMessages + " records received") .atMost(Duration.ofSeconds(30)) @@ -121,8 +122,9 @@ abstract class GenericApplicationTests @SkipWhenErrorCannotBeGenerated(poisonPill = true) void commitsOffsetOfErrorForReprocessingOnDeserializationError() { - int numberOfGeneratedMessages = - recordGenerator.generate(true, false, messageSender); + recordGenerator.generate(true, false, messageSender); + + int numberOfGeneratedMessages = recordGenerator.getNumberOfMessages(); await("Consumer failed") .atMost(Duration.ofSeconds(30)) @@ -155,8 +157,9 @@ abstract class GenericApplicationTests @SkipWhenErrorCannotBeGenerated(logicError = true) void commitsOffsetsOfUnseenRecordsOnLogicError() { - int numberOfGeneratedMessages = - recordGenerator.generate(false, true, messageSender); + recordGenerator.generate(false, true, messageSender); + + int numberOfGeneratedMessages = recordGenerator.getNumberOfMessages(); await("Consumer failed") .atMost(Duration.ofSeconds(30)) @@ -271,11 +274,15 @@ abstract class GenericApplicationTests public interface RecordGenerator { - int generate( + void generate( boolean poisonPills, boolean logicErrors, Consumer> messageSender); + int getNumberOfMessages(); + int getNumberOfPoisonPills(); + int getNumberOfLogicErrors(); + default boolean canGeneratePoisonPill() { return true; -- 2.20.1