Search in sources :

Example 11 with TestInbox

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

the class PeekingWrapperTest method assertPeekInput.

private void assertPeekInput() throws Exception {
    peekP.init(mock(Outbox.class), context);
    TestInbox inbox = new TestInbox();
    inbox.add(0);
    peekP.process(0, inbox);
    verify(logger).info("Input from ordinal 0: " + format(0));
    inbox.add(0);
    peekP.process(1, inbox);
    verify(logger).info("Input from ordinal 1: " + format(0));
    inbox.add(1);
    peekP.process(0, inbox);
    if (shouldLogFn == null) {
        verify(logger).info("Input from ordinal 0: " + format(1));
    } else {
        verifyZeroInteractions(logger);
    }
    Watermark wm = new Watermark(1);
    peekP.tryProcessWatermark(wm);
    verify(logger).info("Input: " + wm);
    inbox.add(TEST_JET_EVENT);
    peekP.process(0, inbox);
    verify(logger).info("Input from ordinal 0: " + testJetEventString);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox)

Example 12 with TestInbox

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

the class SlidingWindowP_twoStageSnapshotTest method test.

@Test
public void test() throws Exception {
    SlidingWindowP stage1p1 = stage1Supplier.get();
    SlidingWindowP stage1p2 = stage1Supplier.get();
    SlidingWindowP stage2p = stage2Supplier.get();
    TestOutbox stage1p1Outbox = newOutbox();
    TestOutbox stage1p2Outbox = newOutbox();
    TestOutbox stage2Outbox = newOutbox();
    TestInbox inbox = new TestInbox();
    TestProcessorContext context = new TestProcessorContext().setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    stage1p1.init(stage1p1Outbox, context);
    stage1p2.init(stage1p2Outbox, context);
    stage2p.init(stage2Outbox, context);
    // process some events in the 1st stage
    // entry key is time
    assertTrue(stage1p1.tryProcess(0, entry(1L, 1L)));
    assertTrue(stage1p2.tryProcess(0, entry(2L, 2L)));
    assertTrue(stage1p1Outbox.queue(0).isEmpty() && stage2Outbox.queue(0).isEmpty());
    // save state in stage1
    assertTrue(stage1p1.saveToSnapshot());
    assertTrue(stage1p2.saveToSnapshot());
    assertTrue("something put to snapshot outbox in stage1", stage1p1Outbox.snapshotQueue().isEmpty() && stage1p2Outbox.snapshotQueue().isEmpty());
    assertEmptyState(stage1p1);
    assertEmptyState(stage1p2);
    // process normal outbox in stage2
    processStage2(stage2p, stage1p1Outbox, stage1p2Outbox, inbox);
    if (simulateRestore) {
        // create new instances for stage1
        stage1p1 = stage1Supplier.get();
        stage1p2 = stage1Supplier.get();
        stage1p1Outbox = newOutbox();
        stage1p2Outbox = newOutbox();
        stage1p1.init(stage1p1Outbox, context);
        stage1p2.init(stage1p2Outbox, context);
    }
    // process some more events in 1st stage
    assertTrue(stage1p1.tryProcess(0, entry(3L, 3L)));
    assertTrue(stage1p1.tryProcess(0, entry(4L, 4L)));
    // process flushing WM
    assertTrue(stage1p1.tryProcessWatermark(wm(10)));
    assertTrue(stage1p2.tryProcessWatermark(wm(10)));
    processStage2(stage2p, stage1p1Outbox, stage1p2Outbox, inbox);
    assertTrue(stage2p.tryProcessWatermark(wm(10)));
    // Then
    assertEquals(collectionToString(asList(outboxFrame(2, 1), outboxFrame(3, 3), outboxFrame(4, 6), outboxFrame(5, 10), outboxFrame(6, 9), outboxFrame(7, 7), outboxFrame(8, 4), wm(10))), collectionToString(stage2Outbox.queue(0)));
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Processors.combineToSlidingWindowP(com.hazelcast.jet.core.processor.Processors.combineToSlidingWindowP) 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 TestInbox

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

the class AsyncTransformUsingServicePTest method test_wmNotCountedToParallelOps.

@Test
public void test_wmNotCountedToParallelOps() throws Exception {
    Processor processor = getSupplier(2, (ctx, item) -> new CompletableFuture<>()).get(1).iterator().next();
    processor.init(new TestOutbox(128), new TestProcessorContext());
    TestInbox inbox = new TestInbox();
    inbox.add("foo");
    processor.process(0, inbox);
    assertTrue("inbox not empty", inbox.isEmpty());
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(0)));
    inbox.add("bar");
    processor.process(0, inbox);
    assertTrue("2nd item rejected even though max parallel ops is 1", inbox.isEmpty());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Processor(com.hazelcast.jet.core.Processor) CompletableFuture(java.util.concurrent.CompletableFuture) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Util.exceptionallyCompletedFuture(com.hazelcast.jet.impl.util.Util.exceptionallyCompletedFuture) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) JetException(com.hazelcast.jet.JetException) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Watermark(com.hazelcast.jet.core.Watermark) Arrays.asList(java.util.Arrays.asList) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) ExpectedException(org.junit.rules.ExpectedException) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Parameterized(org.junit.runners.Parameterized) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) TestInbox(com.hazelcast.jet.core.test.TestInbox) FunctionEx(com.hazelcast.function.FunctionEx) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Parameter(org.junit.runners.Parameterized.Parameter) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Rule(org.junit.Rule) TestSupport(com.hazelcast.jet.core.test.TestSupport) CompletableFuture(java.util.concurrent.CompletableFuture) Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) 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 TestInbox

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

the class AbstractProcessorTest method before.

@Before
public void before() throws Exception {
    inbox = new TestInbox();
    inbox.add(MOCK_ITEM);
    int[] capacities = new int[OUTBOX_BUCKET_COUNT];
    Arrays.fill(capacities, 1);
    outbox = new TestOutbox(capacities);
    final Processor.Context ctx = new TestProcessorContext();
    p = new RegisteringMethodCallsP();
    p.init(outbox, ctx);
    tryProcessP = new SpecializedByOrdinalP();
    tryProcessP.init(outbox, ctx);
    nothingOverriddenP = new NothingOverriddenP();
    nothingOverriddenP.init(outbox, ctx);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Before(org.junit.Before)

Example 15 with TestInbox

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

the class WriteFilePTest method test_abortUnfinishedTransaction_whenNoItemsProcessed.

@Test
public void test_abortUnfinishedTransaction_whenNoItemsProcessed() throws Exception {
    // test for https://github.com/hazelcast/hazelcast/issues/19774
    ProcessorMetaSupplier metaSupplier = writeFileP(directory.toString(), StandardCharsets.UTF_8, null, DISABLE_ROLLING, true, Objects::toString);
    TestProcessorContext processorContext = new TestProcessorContext().setProcessingGuarantee(EXACTLY_ONCE);
    @SuppressWarnings("unchecked") WriteFileP<Integer> processor = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
    processor.init(new TestOutbox(new int[] { 128 }, 128), processorContext);
    processor.process(0, new TestInbox(singletonList(42)));
    assertTrue(processor.snapshotCommitPrepare());
    checkFileContents(0, 0, true, true, true);
    // Now a tmp file is created. Let's simulate that the prepared snapshot wasn't successful and
    // the job restarted
    @SuppressWarnings("unchecked") WriteFileP<Integer> processor2 = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
    processor2.init(new TestOutbox(128), processorContext);
    processor2.close();
    // now there should be no temp files
    checkFileContents(0, 0, true, false, true);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Objects(java.util.Objects) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TestInbox (com.hazelcast.jet.core.test.TestInbox)22 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)16 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)16 Test (org.junit.Test)13 Processor (com.hazelcast.jet.core.Processor)11 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 Watermark (com.hazelcast.jet.core.Watermark)6 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Outbox (com.hazelcast.jet.core.Outbox)4 Before (org.junit.Before)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Traverser (com.hazelcast.jet.Traverser)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 ILogger (com.hazelcast.logging.ILogger)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collection (java.util.Collection)3 Collections.singletonList (java.util.Collections.singletonList)3 Entry (java.util.Map.Entry)3