Search in sources :

Example 11 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.

the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.

@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() throws Exception {
    // When
    StreamKafkaP processor = createProcessor(properties(), 2, r -> entry(r.key(), r.value()), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.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);
    assertBetween("elapsed time", elapsedMs, 3000, 30_000);
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.

the class StreamKafkaPTest method when_customProjectionToNull_then_filteredOut.

@Test
public void when_customProjectionToNull_then_filteredOut() throws Exception {
    // When
    EventTimePolicy<String> eventTimePolicy = eventTimePolicy(Long::parseLong, limitingLag(0), 1, 0, 0);
    StreamKafkaP processor = new StreamKafkaP<Integer, String, String>(properties(), singletonList(topic1Name), r -> "0".equals(r.value()) ? null : r.value(), eventTimePolicy);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.produce(topic1Name, 0, "0");
    kafkaTestSupport.produce(topic1Name, 0, "1");
    // Then
    assertTrueEventually(() -> {
        assertFalse(processor.complete());
        assertFalse("no item in outbox", outbox.queue(0).isEmpty());
    }, 3);
    assertEquals("1", outbox.queue(0).poll());
    assertNull(outbox.queue(0).poll());
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.

the class StreamKafkaPTest method when_customProjection_then_used.

@Test
public void when_customProjection_then_used() throws Exception {
    // When
    StreamKafkaP processor = createProcessor(properties(), 2, r -> r.key() + "=" + r.value(), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.

the class StreamSocketPTest method before.

@Before
public void before() {
    outbox = new TestOutbox(10);
    context = new TestProcessorContext();
    bucket = outbox.queue(0);
    input = input.replaceAll("%n", "\n").replaceAll("%r", "\r");
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Before(org.junit.Before)

Example 15 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast by hazelcast.

the class SlidingWindowP_changeWindowSizeTest method test.

private static void test(@Nonnull SlidingWindowPolicy policy1, @Nonnull SlidingWindowPolicy policy2, @Nullable List expectedOutboxAfterRestore) throws Exception {
    SlidingWindowP p = createProcessor(policy1);
    TestOutbox outbox = new TestOutbox(new int[] { 1024 }, 1024);
    p.init(outbox, new TestProcessorContext());
    TestInbox inbox = new TestInbox();
    inbox.addAll(asList(0, 1, 2, 3));
    p.process(0, inbox);
    p.tryProcessWatermark(wm(2));
    outbox.drainQueueAndReset(0, new ArrayList<>(), false);
    // take a snapshot and restore to a new processor with different window size
    p.saveToSnapshot();
    TestInbox snapshotInbox = new TestInbox();
    outbox.drainSnapshotQueueAndReset(snapshotInbox.queue(), false);
    p = createProcessor(policy2);
    p.init(outbox, new TestProcessorContext());
    for (Object o : snapshotInbox.queue()) {
        Entry e = (Entry) o;
        p.restoreFromSnapshot(e.getKey(), e.getValue());
    }
    p.finishSnapshotRestore();
    while (!p.complete()) {
    }
    if (expectedOutboxAfterRestore != null) {
        assertEquals(expectedOutboxAfterRestore, new ArrayList<>(outbox.queue(0)));
    }
    assertTrue("tsToKeyToAcc not empty", p.tsToKeyToAcc.isEmpty());
    assertTrue("slidingWindow not empty", p.slidingWindow == null || p.slidingWindow.isEmpty());
}
Also used : Entry(java.util.Map.Entry) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

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