Search in sources :

Example 51 with TestOutbox

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);
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox)

Example 52 with TestOutbox

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);
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 53 with TestOutbox

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));
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Test(org.junit.Test)

Example 54 with TestOutbox

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));
}
Also used : RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 55 with TestOutbox

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());
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Test(org.junit.Test)

Aggregations

TestOutbox (com.hazelcast.jet.core.test.TestOutbox)56 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)50 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Processor (com.hazelcast.jet.core.Processor)14 TestInbox (com.hazelcast.jet.core.test.TestInbox)14 ArrayList (java.util.ArrayList)12 Watermark (com.hazelcast.jet.core.Watermark)11 Entry (java.util.Map.Entry)10 Before (org.junit.Before)8 Context (com.hazelcast.jet.core.Processor.Context)6 FunctionEx (com.hazelcast.function.FunctionEx)4 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Traverser (com.hazelcast.jet.Traverser)4 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)4 Outbox (com.hazelcast.jet.core.Outbox)4 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)4 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)4 HashSet (java.util.HashSet)4