X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2FApplicationTests.java;h=516622747d135c5c93a89c711ac2a46ea976ec2c;hb=f1eec82fb197f9fc7906eb9a90d75468e9e4356f;hp=1272124cbe58981aeea2fd5483fd79b9bb53540a;hpb=27768041f2c2f4b1cbb8c45c9a5d665490050f76;p=demos%2Fkafka%2Ftraining diff --git a/src/test/java/de/juplo/kafka/ApplicationTests.java b/src/test/java/de/juplo/kafka/ApplicationTests.java index 1272124..5166227 100644 --- a/src/test/java/de/juplo/kafka/ApplicationTests.java +++ b/src/test/java/de/juplo/kafka/ApplicationTests.java @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.test.context.ContextConfiguration; -import java.util.Set; import java.util.function.Consumer; @@ -27,9 +26,9 @@ public class ApplicationTests extends GenericApplicationTests @Override - public void generate( - Set poisonPills, - Set logicErrors, + public int generate( + boolean poisonPills, + boolean logicErrors, Consumer> messageSender) { int i = 0; @@ -38,17 +37,19 @@ public class ApplicationTests extends GenericApplicationTests { for (int key = 0; key < 10; key++) { - if (++i > 100) - return; + i++; Bytes value = new Bytes(longSerializer.serialize(TOPIC, (long)i)); - if (logicErrors.contains(i)) + if (i == 77) { - value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE)); - } - if (poisonPills.contains(i)) - { - value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!")); + if (logicErrors) + { + value = new Bytes(longSerializer.serialize(TOPIC, Long.MIN_VALUE)); + } + if (poisonPills) + { + value = new Bytes(stringSerializer.serialize(TOPIC, "BOOM (Poison-Pill)!")); + } } ProducerRecord record = @@ -61,6 +62,8 @@ public class ApplicationTests extends GenericApplicationTests messageSender.accept(record); } } + + return i; } }); } @@ -71,12 +74,18 @@ public class ApplicationTests extends GenericApplicationTests { @Primary @Bean - public Consumer> consumer() + public ApplicationRecordHandler recordHandler() { - return (record) -> + ApplicationRecordHandler recordHandler = new ApplicationRecordHandler(); + return new ApplicationRecordHandler() { - if (record.value() == Long.MIN_VALUE) - throw new RuntimeException("BOOM (Logic-Error)!"); + @Override + public void accept(ConsumerRecord record) + { + if (record.value() == Long.MIN_VALUE) + throw new RuntimeException("BOOM (Logic-Error)!"); + super.accept(record); + } }; } }