Search in sources :

Example 46 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet by hazelcast.

the class StreamEventJournalPTest method assertRestore.

private void assertRestore(List<Entry> snapshotItems) {
    Processor p = supplier.get();
    TestOutbox newOutbox = new TestOutbox(new int[] { 16 }, 16);
    List<Object> output = new ArrayList<>();
    p.init(newOutbox, new TestProcessorContext());
    TestInbox inbox = new TestInbox();
    inbox.addAll(snapshotItems);
    p.restoreFromSnapshot(inbox);
    p.finishSnapshotRestore();
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        newOutbox.drainQueueAndReset(0, output, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY, output.size());
    }, 3);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ArrayList(java.util.ArrayList) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 47 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet by hazelcast.

the class StreamEventJournalPTest method when_newData.

@Test
public void when_newData() {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    List<Object> actual = new ArrayList<>();
    Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext());
    fillJournal(CAPACITY_PER_PARTITION);
    // consume
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY, actual.size());
        assertEquals(IntStream.range(0, JOURNAL_CAPACITY).boxed().collect(Collectors.toSet()), new HashSet<>(actual));
    }, 3);
    fillJournal(CAPACITY_PER_PARTITION);
    // consume again
    assertTrueEventually(() -> {
        assertFalse("Processor should never complete", p.complete());
        outbox.drainQueueAndReset(0, actual, true);
        assertEquals("consumed different number of items than expected", JOURNAL_CAPACITY + 2, actual.size());
        assertEquals(IntStream.range(0, JOURNAL_CAPACITY).boxed().collect(Collectors.toSet()), new HashSet<>(actual));
    }, 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) Test(org.junit.Test)

Example 48 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet by hazelcast.

the class WriteBufferedPTest method writeBuffered_smokeTest.

@Test
public void writeBuffered_smokeTest() {
    DistributedSupplier<Processor> supplier = getLoggingBufferedWriter();
    Processor p = supplier.get();
    Outbox outbox = mock(Outbox.class);
    p.init(outbox, mock(Context.class));
    TestInbox inbox = new TestInbox();
    inbox.add(1);
    inbox.add(2);
    p.process(0, inbox);
    inbox.add(3);
    inbox.add(4);
    p.process(0, inbox);
    // watermark should not be written
    p.tryProcessWatermark(new Watermark(0));
    // empty flush
    p.process(0, inbox);
    p.complete();
    assertEquals(asList("new", "add:1", "add:2", "flush", "add:3", "add:4", "flush", "flush", "dispose"), events);
    assertEquals(0, inbox.size());
    verifyZeroInteractions(outbox);
}
Also used : Context(com.hazelcast.jet.core.Processor.Context) Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) Outbox(com.hazelcast.jet.core.Outbox) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 49 with Processor

use of com.hazelcast.jet.core.Processor in project hazelcast-jet-reference-manual by hazelcast.

the class S8 method get.

@Override
@Nonnull
public Function<Address, ProcessorSupplier> get(@Nonnull List<Address> addresses) {
    Map<Address, ProcessorSupplier> map = new HashMap<>();
    for (int i = 0; i < addresses.size(); i++) {
        // We'll calculate the global index of each processor in the cluster:
        int globalIndexBase = localParallelism * i;
        // Capture the value of the transient field for the lambdas below:
        int divisor = totalParallelism;
        // processorCount will be equal to localParallelism:
        ProcessorSupplier supplier = processorCount -> range(globalIndexBase, globalIndexBase + processorCount).mapToObj(globalIndex -> new GenerateNumbersP(upperBound, divisor, globalIndex)).collect(toList());
        map.put(addresses.get(i), supplier);
    }
    return map::get;
}
Also used : IntStream(java.util.stream.IntStream) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) DiagnosticProcessors(com.hazelcast.jet.core.processor.DiagnosticProcessors) JetInstance(com.hazelcast.jet.JetInstance) IntStream.range(java.util.stream.IntStream.range) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Processor(com.hazelcast.jet.core.Processor) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Traversers(com.hazelcast.jet.Traversers) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) Context(com.hazelcast.jet.core.Processor.Context) Jet(com.hazelcast.jet.Jet) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Nonnull(javax.annotation.Nonnull)

Aggregations

Processor (com.hazelcast.jet.core.Processor)49 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)22 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)17 QuickTest (com.hazelcast.test.annotation.QuickTest)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)14 List (java.util.List)13 Nonnull (javax.annotation.Nonnull)13 TestInbox (com.hazelcast.jet.core.test.TestInbox)11 Watermark (com.hazelcast.jet.core.Watermark)10 Collection (java.util.Collection)9 Collections.singletonList (java.util.Collections.singletonList)9 Entry (java.util.Map.Entry)9 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)8 FunctionEx (com.hazelcast.function.FunctionEx)7 Job (com.hazelcast.jet.Job)7 JobConfig (com.hazelcast.jet.config.JobConfig)7 DAG (com.hazelcast.jet.core.DAG)7 Arrays (java.util.Arrays)6