Search in sources :

Example 16 with TestProcessorContext

use of com.hazelcast.jet.core.test.TestProcessorContext 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)

Example 17 with TestProcessorContext

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

the class AsyncTransformUsingServicePTest method test_watermarksConflated.

@Test
public void test_watermarksConflated() 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();
    // i have to add an item first because otherwise the WMs are forwarded right away
    inbox.add("foo");
    processor.process(0, inbox);
    assertTrue("inbox not empty", inbox.isEmpty());
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(0)));
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(1)));
    assertTrue("wm rejected", processor.tryProcessWatermark(wm(2)));
}
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 18 with TestProcessorContext

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

the class SinksTest method mapWithMerging_when_multipleValuesForSingleKeyInABatch.

@Test
public void mapWithMerging_when_multipleValuesForSingleKeyInABatch() throws Exception {
    ProcessorMetaSupplier metaSupplier = adaptSupplier(SinkProcessors.<Entry<String, Integer>, String, Integer>mergeMapP(sinkName, Entry::getKey, Entry::getValue, Integer::sum));
    TestProcessorSupplierContext psContext = new TestProcessorSupplierContext().setHazelcastInstance(member);
    Processor p = TestSupport.supplierFrom(metaSupplier, psContext).get();
    TestOutbox outbox = new TestOutbox();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(member));
    TestInbox inbox = new TestInbox();
    inbox.add(entry("k", 1));
    inbox.add(entry("k", 2));
    p.process(0, inbox);
    assertTrue("inbox.isEmpty()", inbox.isEmpty());
    assertTrueEventually(() -> {
        assertTrue("p.complete()", p.complete());
    }, 10);
    p.close();
    // assert the output map contents
    IMap<Object, Object> actual = member.getMap(sinkName);
    assertEquals(1, actual.size());
    assertEquals(3, actual.get("k"));
}
Also used : Processor(com.hazelcast.jet.core.Processor) EntryProcessor(com.hazelcast.map.EntryProcessor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) TestProcessorSupplierContext(com.hazelcast.jet.core.test.TestProcessorSupplierContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 19 with TestProcessorContext

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

the class SessionWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) throws Exception {
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SessionWindowP<>(5000, 0L, singletonList((ToLongFunctionEx<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, KeyedWindowResult::new);
    Outbox outbox = new TestOutbox(128);
    Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
    p.init(outbox, context);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 20 with TestProcessorContext

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

the class StreamEventJournalPTest method when_lostItems.

@Test
public void when_lostItems() throws Exception {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    // overflow the journal
    fillJournal(CAPACITY_PER_PARTITION + 1);
    // fill and consume
    List<Object> actual = new ArrayList<>();
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertTrue("consumed different number of items than expected", actual.size() == JOURNAL_CAPACITY);
    }, 3);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ArrayList(java.util.ArrayList) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)58 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)50 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Processor (com.hazelcast.jet.core.Processor)17 TestInbox (com.hazelcast.jet.core.test.TestInbox)16 Watermark (com.hazelcast.jet.core.Watermark)13 ArrayList (java.util.ArrayList)12 Before (org.junit.Before)10 Entry (java.util.Map.Entry)9 Outbox (com.hazelcast.jet.core.Outbox)7 Context (com.hazelcast.jet.core.Processor.Context)6 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)6 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)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 HashSet (java.util.HashSet)4