From: Kai Moritz Date: Sun, 11 Sep 2022 11:42:57 +0000 (+0200) Subject: Anzahl der Fehler für die Test-Logik verfügbar gemacht X-Git-Tag: sumup-adder--springified---lvm-2-tage~6 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=7a7926c1799495a3ed016cb1b204cbfe13f833f1;p=demos%2Fkafka%2Ftraining Anzahl der Fehler für die Test-Logik verfügbar gemacht --- 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;