Search in sources :

Example 21 with TestProcessorContext

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

the class StreamEventJournalPTest method when_lostItems_afterRestore.

@Test
public void when_lostItems_afterRestore() throws Exception {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    final Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    List<Object> output = new ArrayList<>();
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, output, true);
        assertTrue("consumed different number of items than expected", output.size() == 0);
    }, 3);
    assertTrueEventually(() -> {
        assertTrue("Processor did not finish snapshot", p.saveToSnapshot());
    }, 3);
    // overflow journal
    fillJournal(CAPACITY_PER_PARTITION + 1);
    List<Entry> snapshotItems = new ArrayList<>();
    outbox.drainSnapshotQueueAndReset(snapshotItems, false);
    logger.info("Restoring journal");
    // restore from snapshot
    assertRestore(snapshotItems);
}
Also used : Entry(java.util.Map.Entry) 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)

Example 22 with TestProcessorContext

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

the class StreamEventJournalPTest method when_futureSequence_thenResetOffset.

@Test
public void when_futureSequence_thenResetOffset() throws Exception {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    StreamEventJournalP p = (StreamEventJournalP) supplier.get();
    // fill journal so that it overflows
    fillJournal(CAPACITY_PER_PARTITION + 1);
    // initial offsets will be 5, since capacity per partition is 5
    p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
    // clear partitions before doing any read, but after initializing offsets
    map.destroy();
    // when we consume, we should not retrieve anything because we will ask for
    // offset 5, but current head is 0. This should not cause any error
    List<Object> actual = new ArrayList<>();
    // we should not receive any items, but the offset should be reset back to 0
    assertTrueFiveSeconds(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertTrue("consumed different number of items than expected", actual.size() == 0);
    });
    // add one item to each partition
    fillJournal(1);
    // receive the items we just added
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertTrue("consumed different number of items than expected", actual.size() == 2);
    });
}
Also used : 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)

Example 23 with TestProcessorContext

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

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() throws Exception {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", false, Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.cluster.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.internal.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with TestProcessorContext

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

the class SlidingWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) throws Exception {
    SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((ToLongFunctionEx<Entry<?, Long>>) Entry::getValue), wDef, 0L, aggrOp, KeyedWindowResult::new, true);
    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) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) 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 25 with TestProcessorContext

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

the class SessionWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) {
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SessionWindowP<>(5000, singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, WindowResult::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)

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