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