Search in sources :

Example 41 with TestOutbox

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

the class StreamFilesPTest method initializeProcessor.

private void initializeProcessor(String glob) throws Exception {
    if (glob == null) {
        glob = "*";
    }
    processor = new StreamFilesP<>(workDir.getAbsolutePath(), UTF_8, glob, false, Util::entry);
    outbox = new TestOutbox(1);
    Context ctx = new TestProcessorContext().setLogger(Logger.getLogger(StreamFilesP.class));
    processor.init(outbox, ctx);
}
Also used : TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 42 with TestOutbox

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

Example 43 with TestOutbox

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

the class SlidingWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) {
    SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), wDef, aggrOp, TimestampedEntry::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) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) 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 44 with TestOutbox

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

the class ReadWithPartitionIteratorPTest method when_readFromTwoPartitions_then_emitRoundRobin.

@Test
@SuppressWarnings("unchecked")
public void when_readFromTwoPartitions_then_emitRoundRobin() {
    // Given
    final List<Integer> partitions = asList(0, 1);
    final Iterator<Entry<Integer, Integer>>[] content = new Iterator[] { iterate(51, 52, 53), iterate(71, 72, 73) };
    ReadWithPartitionIteratorP<Entry<Integer, Integer>> r = new ReadWithPartitionIteratorP<>(p -> content[p], partitions);
    TestOutbox outbox = new TestOutbox(3);
    Queue<Object> bucket = outbox.queue(0);
    r.init(outbox, mock(Processor.Context.class));
    // When
    assertFalse(r.complete());
    // Then
    assertEquals(entry(51), bucket.poll());
    assertEquals(entry(71), bucket.poll());
    assertEquals(entry(52), bucket.poll());
    outbox.reset();
    // When
    assertTrue(r.complete());
    // Then
    assertEquals(entry(72), bucket.poll());
    assertEquals(entry(53), bucket.poll());
    assertEquals(entry(73), bucket.poll());
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Entry(java.util.Map.Entry) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 45 with TestOutbox

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

the class StreamEventJournalPTest method when_lostItems_afterRestore.

@Test
public void when_lostItems_afterRestore() {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    final Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext());
    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);
    System.out.println("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) 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