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);
}
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);
}
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);
}
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;
}
Aggregations