use of org.apache.kafka.test.MockApiProcessorSupplier in project kafka by apache.
the class KStreamKStreamLeftJoinTest method testRightNonJoinedRecordsAreNeverEmittedByTheLeftProcessor.
@Test
public void testRightNonJoinedRecordsAreNeverEmittedByTheLeftProcessor() {
final StreamsBuilder builder = new StreamsBuilder();
final KStream<Integer, String> stream1;
final KStream<Integer, String> stream2;
final KStream<Integer, String> joined;
final MockApiProcessorSupplier<Integer, String, Void, Void> supplier = new MockApiProcessorSupplier<>();
stream1 = builder.stream(topic1, consumed);
stream2 = builder.stream(topic2, consumed);
joined = stream1.leftJoin(stream2, MockValueJoiner.TOSTRING_JOINER, JoinWindows.ofTimeDifferenceAndGrace(ofMillis(100L), ofMillis(0L)), StreamJoined.with(Serdes.Integer(), Serdes.String(), Serdes.String()));
joined.process(supplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<Integer, String> inputTopic1 = driver.createInputTopic(topic1, new IntegerSerializer(), new StringSerializer(), Instant.ofEpochMilli(0L), Duration.ZERO);
final TestInputTopic<Integer, String> inputTopic2 = driver.createInputTopic(topic2, new IntegerSerializer(), new StringSerializer(), Instant.ofEpochMilli(0L), Duration.ZERO);
final MockApiProcessor<Integer, String, Void, Void> processor = supplier.theCapturedProcessor();
final long windowStart = 0L;
// No joins detected; No null-joins emitted
inputTopic2.pipeInput(0, "A0", windowStart + 1L);
inputTopic2.pipeInput(1, "A1", windowStart + 2L);
inputTopic2.pipeInput(0, "A0-0", windowStart + 3L);
processor.checkAndClearProcessResult();
// Join detected; No null-joins emitted
inputTopic1.pipeInput(1, "a1", windowStart + 3L);
processor.checkAndClearProcessResult(new KeyValueTimestamp<>(1, "a1+A1", windowStart + 3L));
// Dummy record in left topic will not emit records
inputTopic1.pipeInput(2, "dummy", windowStart + 401L);
processor.checkAndClearProcessResult();
// Process the dummy joined record
inputTopic2.pipeInput(2, "dummy", windowStart + 402L);
processor.checkAndClearProcessResult(new KeyValueTimestamp<>(2, "dummy+dummy", windowStart + 402L));
}
}
use of org.apache.kafka.test.MockApiProcessorSupplier in project kafka by apache.
the class InternalTopologyBuilderTest method shouldNotAllowToAddStoresWithSameNameWhenSecondStoreIsGlobal.
@Test
public void shouldNotAllowToAddStoresWithSameNameWhenSecondStoreIsGlobal() {
final StoreBuilder<KeyValueStore<Object, Object>> globalBuilder = new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled();
builder.addStateStore(storeBuilder);
final TopologyException exception = assertThrows(TopologyException.class, () -> builder.addGlobalStore(globalBuilder, "global-store", null, null, null, "global-topic", "global-processor", new MockApiProcessorSupplier<>()));
assertThat(exception.getMessage(), equalTo("Invalid topology: A different StateStore has already been added with the name testStore"));
}
use of org.apache.kafka.test.MockApiProcessorSupplier in project kafka by apache.
the class TimeWindowedKStreamImplTest method shouldReduceWindowed.
@Test
public void shouldReduceWindowed() {
final MockApiProcessorSupplier<Windowed<String>, String, Void, Void> supplier = new MockApiProcessorSupplier<>();
windowedStream.reduce(MockReducer.STRING_ADDER).toStream().process(supplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
processData(driver);
}
assertThat(supplier.theCapturedProcessor().lastValueAndTimestampPerKey().get(new Windowed<>("1", new TimeWindow(0L, 500L))), equalTo(ValueAndTimestamp.make("1+2", 15L)));
assertThat(supplier.theCapturedProcessor().lastValueAndTimestampPerKey().get(new Windowed<>("2", new TimeWindow(500L, 1000L))), equalTo(ValueAndTimestamp.make("10+20", 550L)));
assertThat(supplier.theCapturedProcessor().lastValueAndTimestampPerKey().get(new Windowed<>("1", new TimeWindow(500L, 1000L))), equalTo(ValueAndTimestamp.make("3", 500L)));
}
use of org.apache.kafka.test.MockApiProcessorSupplier in project kafka by apache.
the class StreamsBuilderTest method shouldProcessingFromSinkTopic.
@Test
public void shouldProcessingFromSinkTopic() {
final KStream<String, String> source = builder.stream("topic-source");
source.to("topic-sink");
final MockApiProcessorSupplier<String, String, Void, Void> processorSupplier = new MockApiProcessorSupplier<>();
source.process(processorSupplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, String> inputTopic = driver.createInputTopic("topic-source", new StringSerializer(), new StringSerializer(), Instant.ofEpochMilli(0L), Duration.ZERO);
inputTopic.pipeInput("A", "aa");
}
// no exception was thrown
assertEquals(Collections.singletonList(new KeyValueTimestamp<>("A", "aa", 0)), processorSupplier.theCapturedProcessor().processed());
}
use of org.apache.kafka.test.MockApiProcessorSupplier in project kafka by apache.
the class StreamsBuilderTest method shouldProcessViaRepartitionTopic.
@Test
public void shouldProcessViaRepartitionTopic() {
final KStream<String, String> source = builder.stream("topic-source");
final KStream<String, String> through = source.repartition();
final MockApiProcessorSupplier<String, String, Void, Void> sourceProcessorSupplier = new MockApiProcessorSupplier<>();
source.process(sourceProcessorSupplier);
final MockApiProcessorSupplier<String, String, Void, Void> throughProcessorSupplier = new MockApiProcessorSupplier<>();
through.process(throughProcessorSupplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, String> inputTopic = driver.createInputTopic("topic-source", new StringSerializer(), new StringSerializer(), Instant.ofEpochMilli(0L), Duration.ZERO);
inputTopic.pipeInput("A", "aa");
}
assertEquals(Collections.singletonList(new KeyValueTimestamp<>("A", "aa", 0)), sourceProcessorSupplier.theCapturedProcessor().processed());
assertEquals(Collections.singletonList(new KeyValueTimestamp<>("A", "aa", 0)), throughProcessorSupplier.theCapturedProcessor().processed());
}
Aggregations