--- /dev/null
+package de.juplo.kafka;
+
+import org.junit.jupiter.api.extension.ConditionEvaluationResult;
+import org.junit.jupiter.api.extension.ExecutionCondition;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.platform.commons.util.AnnotationUtils;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+
+public class ErrorCannotBeGeneratedCondition implements ExecutionCondition
+{
+ @Override
+ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context)
+ {
+ final Optional<SkipWhenErrorCannotBeGenerated> optional =
+ AnnotationUtils.findAnnotation(
+ context.getElement(),
+ SkipWhenErrorCannotBeGenerated.class);
+
+ if (context.getTestInstance().isEmpty())
+ return ConditionEvaluationResult.enabled("Test-instance ist not available");
+
+ if (optional.isPresent())
+ {
+ SkipWhenErrorCannotBeGenerated skipWhenErrorCannotBeGenerated = optional.get();
+ GenericApplicationTest instance = (GenericApplicationTest)context.getTestInstance().get();
+ List<String> missingRequiredErrors = new LinkedList<>();
+
+ if (skipWhenErrorCannotBeGenerated.poisonPill() && !instance.recordGenerator.canGeneratePoisionPill())
+ missingRequiredErrors.add("Poison-Pill");
+
+ if (skipWhenErrorCannotBeGenerated.logicError() && !instance.recordGenerator.canGenerateLogicError())
+ missingRequiredErrors.add("Logic-Error");
+
+ StringBuilder builder = new StringBuilder();
+ builder.append(context.getTestClass().get().getSimpleName());
+
+ if (missingRequiredErrors.isEmpty())
+ {
+ builder.append(" can generate all required types of errors");
+ return ConditionEvaluationResult.enabled(builder.toString());
+ }
+
+ builder.append(" cannot generate the required error(s): ");
+ builder.append(
+ missingRequiredErrors
+ .stream()
+ .collect(Collectors.joining(", ")));
+
+ return ConditionEvaluationResult.disabled(builder.toString());
+ }
+
+ return ConditionEvaluationResult.enabled(
+ "Not annotated with " + SkipWhenErrorCannotBeGenerated.class.getSimpleName());
+ }
+}
}
@Test
+ @SkipWhenErrorCannotBeGenerated(poisonPill = true)
void commitsOffsetOfErrorForReprocessingOnDeserializationError()
{
recordGenerator.generate(100, Set.of(77), Set.of(), messageSender);
}
@Test
+ @SkipWhenErrorCannotBeGenerated(logicError = true)
void doesNotCommitOffsetsOnLogicError()
{
recordGenerator.generate(100, Set.of(), Set.of(77), messageSender);
Set<Integer> poisonPills,
Set<Integer> logicErrors,
Consumer<ProducerRecord<Bytes, Bytes>> messageSender);
+
+ default boolean canGeneratePoisionPill()
+ {
+ return true;
+ }
+
+ default boolean canGenerateLogicError()
+ {
+ return true;
+ }
}
void sendMessage(ProducerRecord<Bytes, Bytes> record)
--- /dev/null
+package de.juplo.kafka;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+@Retention(RetentionPolicy.RUNTIME)
+@ExtendWith(ErrorCannotBeGeneratedCondition.class)
+public @interface SkipWhenErrorCannotBeGenerated
+{
+ boolean poisonPill() default false;
+ boolean logicError() default false;
+}