use of org.apache.kafka.test.MockProcessor in project kafka by apache.
the class KStreamBranchTest method testKStreamBranch.
// Old PAPI. Needs to be migrated.
@SuppressWarnings({ "unchecked", "deprecation" })
@Test
public void testKStreamBranch() {
final StreamsBuilder builder = new StreamsBuilder();
final Predicate<Integer, String> isEven = (key, value) -> (key % 2) == 0;
final Predicate<Integer, String> isMultipleOfThree = (key, value) -> (key % 3) == 0;
final Predicate<Integer, String> isOdd = (key, value) -> (key % 2) != 0;
final int[] expectedKeys = new int[] { 1, 2, 3, 4, 5, 6 };
final KStream<Integer, String> stream;
final KStream<Integer, String>[] branches;
stream = builder.stream(topicName, Consumed.with(Serdes.Integer(), Serdes.String()));
branches = stream.branch(isEven, isMultipleOfThree, isOdd);
assertEquals(3, branches.length);
final MockProcessorSupplier<Integer, String> supplier = new MockProcessorSupplier<>();
for (final KStream<Integer, String> branch : branches) {
branch.process(supplier);
}
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<Integer, String> inputTopic = driver.createInputTopic(topicName, new IntegerSerializer(), new StringSerializer());
for (final int expectedKey : expectedKeys) {
inputTopic.pipeInput(expectedKey, "V" + expectedKey);
}
}
final List<MockProcessor<Integer, String>> processors = supplier.capturedProcessors(3);
assertEquals(3, processors.get(0).processed().size());
assertEquals(1, processors.get(1).processed().size());
assertEquals(2, processors.get(2).processed().size());
}
Aggregations