import org.springframework.context.annotation.Primary;
import org.springframework.test.context.ContextConfiguration;
-import java.util.Set;
import java.util.function.Consumer;
@Override
- public void generate(
- int numberOfMessagesToGenerate,
- Set<Integer> poisonPills,
- Set<Integer> logicErrors,
+ public int generate(
+ boolean poisonPills,
+ boolean logicErrors,
Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
{
int i = 0;
{
for (int key = 0; key < 10; key++)
{
- if (++i > numberOfMessagesToGenerate)
- 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<Bytes, Bytes> record =
messageSender.accept(record);
}
}
+
+ return i;
}
});
}
{
@Primary
@Bean
- public Consumer<ConsumerRecord<String, Long>> 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<String, Long> record)
+ {
+ if (record.value() == Long.MIN_VALUE)
+ throw new RuntimeException("BOOM (Logic-Error)!");
+ super.accept(record);
+ }
};
}
}