use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.
the class PeekingWrapperTest method assertPeekOutput.
private void assertPeekOutput() {
TestOutbox outbox = new TestOutbox(1, 1);
peekP.init(outbox, context);
peekP.complete();
verify(logger).info("Output to ordinal 0: " + format(0));
verify(logger).info("Output to ordinal 1: " + format(0));
outbox.queue(0).clear();
outbox.queue(1).clear();
outbox.reset();
// only one queue has available space, call complete() again to emit another object
peekP.complete();
if (shouldLogFn == null) {
verify(logger).info("Output to ordinal 1: " + format(1));
verify(logger).info("Output to ordinal 0: " + format(1));
}
outbox.queue(0).clear();
outbox.queue(1).clear();
outbox.reset();
verifyZeroInteractions(logger);
peekP.complete();
Watermark wm = new Watermark(2);
verify(logger).info("Output to ordinal 0: " + wm);
verify(logger).info("Output to ordinal 1: " + wm);
wm = new Watermark(3);
peekP.tryProcessWatermark(wm);
verify(logger).info("Output forwarded: " + wm);
verifyZeroInteractions(logger);
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.
@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() {
// When
StreamKafkaP processor = createProcessor(2, StreamKafkaP::recordToEntry, 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
produce(topic1Name, 10, "foo");
// Then
assertEquals(entry(10, "foo"), consumeEventually(processor, outbox));
long time1 = System.nanoTime();
assertEquals(new Watermark(10 - LAG), consumeEventually(processor, outbox));
long time2 = System.nanoTime();
long elapsedMs = NANOSECONDS.toMillis(time2 - time1);
assertTrue("elapsed time: " + elapsedMs + " ms, should be larger", elapsedMs > 3000 && elapsedMs <= 10_000);
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_customProjection_then_used.
@Test
public void when_customProjection_then_used() {
// When
StreamKafkaP processor = createProcessor(2, r -> r.key() + "=" + r.value(), 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext());
produce(topic1Name, 0, "0");
// Then
assertEquals("0=0", consumeEventually(processor, outbox));
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_noAssignedPartitionAndAddedLater_then_resumesFromIdle.
@Test
public void when_noAssignedPartitionAndAddedLater_then_resumesFromIdle() throws Exception {
// we ask to create 5th out of 5 processors, but we have only 4 partitions and 1 topic
// --> our processor will have nothing assigned
StreamKafkaP processor = createProcessor(1, StreamKafkaP::recordToEntry, 10_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
processor.init(outbox, new TestProcessorContext().setTotalParallelism(INITIAL_PARTITION_COUNT + 1).setGlobalProcessorIndex(INITIAL_PARTITION_COUNT));
assertTrue(processor.currentAssignment.isEmpty());
assertEquals(IDLE_MESSAGE, consumeEventually(processor, outbox));
setPartitionCount(topic1Name, INITIAL_PARTITION_COUNT + 1);
Thread.sleep(1000);
// this allows production to the added partition
resetProducer();
// produce events until the event happens to go to the added partition
Entry<Integer, String> event;
for (int i = 0; ; i++) {
event = entry(i, Integer.toString(i));
Future<RecordMetadata> future = produce(topic1Name, event.getKey(), event.getValue());
RecordMetadata recordMetadata = future.get();
if (recordMetadata.partition() == 4) {
break;
}
}
assertEquals(new Watermark(event.getKey() - LAG), consumeEventually(processor, outbox));
assertEquals(event, consumeEventually(processor, outbox));
}
use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.
the class StreamKafkaPTest method when_noAssignedPartitions_thenEmitIdleMsgImmediately.
@Test
public void when_noAssignedPartitions_thenEmitIdleMsgImmediately() {
StreamKafkaP processor = createProcessor(2, StreamKafkaP::recordToEntry, 100_000);
TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
TestProcessorContext context = new TestProcessorContext().setTotalParallelism(INITIAL_PARTITION_COUNT * 2 + 1).setGlobalProcessorIndex(INITIAL_PARTITION_COUNT * 2);
processor.init(outbox, context);
processor.complete();
assertEquals(IDLE_MESSAGE, outbox.queue(0).poll());
}
Aggregations