{
public ApplicationTests()
{
- super(
- new RecordGenerator()
+ super(new ApplicationTestRecrodGenerator());
+ }
+
+
+ static class ApplicationTestRecrodGenerator implements RecordGenerator
+ {
+ final int[] numbers = {1, 7, 3, 2, 33, 6, 11};
+ final String[] dieWilden13 =
+ IntStream
+ .range(1, 14)
+ .mapToObj(i -> "seeräuber-" + i)
+ .toArray(i -> new String[i]);
+ final StringSerializer stringSerializer = new StringSerializer();
+ final Bytes calculateMessage = new Bytes(stringSerializer.serialize(TOPIC, "CALCULATE"));
+
+ int counter = 0;
+
+ @Override
+ public int generate(
+ boolean poisonPills,
+ boolean logicErrors,
+ Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
+ {
+ counter = 0;
+
+ for (int i = 0; i < 33; i++)
+ {
+ String seeräuber = dieWilden13[i % 13];
+ int number = numbers[i % 7];
+
+ Bytes key = new Bytes(stringSerializer.serialize(TOPIC, seeräuber));
+
+ for (int message = 1; message <= number; message++)
{
- final int[] numbers = { 1, 7, 3, 2, 33, 6, 11 };
- final String[] dieWilden13 =
- IntStream
- .range(1,14)
- .mapToObj(i -> "seeräuber-" + i)
- .toArray(i -> new String[i]);
- final StringSerializer stringSerializer = new StringSerializer();
- final Bytes calculateMessage = new Bytes(stringSerializer.serialize(TOPIC, "CALCULATE"));
-
- int counter = 0;
-
-
- @Override
- public int generate(
- boolean poisonPills,
- boolean logicErrors,
- Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
- {
- counter = 0;
-
- for (int i = 0; i < 33; i++)
- {
- String seeräuber = dieWilden13[i%13];
- int number = numbers[i%7];
-
- Bytes key = new Bytes(stringSerializer.serialize(TOPIC, seeräuber));
-
- for (int message = 1; message <= number; message++)
- {
- Bytes value = new Bytes(stringSerializer.serialize(TOPIC, Integer.toString(message)));
- send(key, value, logicErrors, messageSender);
- }
- send(key, calculateMessage, logicErrors, messageSender);
- }
-
- return counter;
- }
-
- void send(
- Bytes key,
- Bytes value,
- boolean logicErrors,
- Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
- {
- counter++;
-
- if (counter == 77)
- {
- if (logicErrors)
- {
- value = new Bytes(stringSerializer.serialize(TOPIC, Integer.toString(-1)));
- }
- }
-
- messageSender.accept(new ProducerRecord<>(TOPIC, key, value));
- }
-
- @Override
- public boolean canGeneratePoisonPill()
- {
- return false;
- }
- });
+ Bytes value = new Bytes(stringSerializer.serialize(TOPIC, Integer.toString(message)));
+ send(key, value, logicErrors, messageSender);
+ }
+ send(key, calculateMessage, logicErrors, messageSender);
+ }
+
+ return counter;
+ }
+
+ void send(
+ Bytes key,
+ Bytes value,
+ boolean logicErrors,
+ Consumer<ProducerRecord<Bytes, Bytes>> messageSender)
+ {
+ counter++;
+
+ if (counter == 77)
+ {
+ if (logicErrors)
+ {
+ value = new Bytes(stringSerializer.serialize(TOPIC, Integer.toString(-1)));
+ }
+ }
+
+ messageSender.accept(new ProducerRecord<>(TOPIC, key, value));
+ }
+
+ @Override
+ public boolean canGeneratePoisonPill()
+ {
+ return false;
+ }
}
}