use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.
the class PeekingWrapperTest method assertPeekInput.
private void assertPeekInput() throws Exception {
peekP.init(mock(Outbox.class), context);
TestInbox inbox = new TestInbox();
inbox.add(0);
peekP.process(0, inbox);
verify(logger).info("Input from ordinal 0: " + format(0));
inbox.add(0);
peekP.process(1, inbox);
verify(logger).info("Input from ordinal 1: " + format(0));
inbox.add(1);
peekP.process(0, inbox);
if (shouldLogFn == null) {
verify(logger).info("Input from ordinal 0: " + format(1));
} else {
verifyZeroInteractions(logger);
}
Watermark wm = new Watermark(1);
peekP.tryProcessWatermark(wm);
verify(logger).info("Input: " + wm);
inbox.add(TEST_JET_EVENT);
peekP.process(0, inbox);
verify(logger).info("Input from ordinal 0: " + testJetEventString);
}
use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.
the class SlidingWindowP_twoStageSnapshotTest method test.
@Test
public void test() throws Exception {
SlidingWindowP stage1p1 = stage1Supplier.get();
SlidingWindowP stage1p2 = stage1Supplier.get();
SlidingWindowP stage2p = stage2Supplier.get();
TestOutbox stage1p1Outbox = newOutbox();
TestOutbox stage1p2Outbox = newOutbox();
TestOutbox stage2Outbox = newOutbox();
TestInbox inbox = new TestInbox();
TestProcessorContext context = new TestProcessorContext().setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
stage1p1.init(stage1p1Outbox, context);
stage1p2.init(stage1p2Outbox, context);
stage2p.init(stage2Outbox, context);
// process some events in the 1st stage
// entry key is time
assertTrue(stage1p1.tryProcess(0, entry(1L, 1L)));
assertTrue(stage1p2.tryProcess(0, entry(2L, 2L)));
assertTrue(stage1p1Outbox.queue(0).isEmpty() && stage2Outbox.queue(0).isEmpty());
// save state in stage1
assertTrue(stage1p1.saveToSnapshot());
assertTrue(stage1p2.saveToSnapshot());
assertTrue("something put to snapshot outbox in stage1", stage1p1Outbox.snapshotQueue().isEmpty() && stage1p2Outbox.snapshotQueue().isEmpty());
assertEmptyState(stage1p1);
assertEmptyState(stage1p2);
// process normal outbox in stage2
processStage2(stage2p, stage1p1Outbox, stage1p2Outbox, inbox);
if (simulateRestore) {
// create new instances for stage1
stage1p1 = stage1Supplier.get();
stage1p2 = stage1Supplier.get();
stage1p1Outbox = newOutbox();
stage1p2Outbox = newOutbox();
stage1p1.init(stage1p1Outbox, context);
stage1p2.init(stage1p2Outbox, context);
}
// process some more events in 1st stage
assertTrue(stage1p1.tryProcess(0, entry(3L, 3L)));
assertTrue(stage1p1.tryProcess(0, entry(4L, 4L)));
// process flushing WM
assertTrue(stage1p1.tryProcessWatermark(wm(10)));
assertTrue(stage1p2.tryProcessWatermark(wm(10)));
processStage2(stage2p, stage1p1Outbox, stage1p2Outbox, inbox);
assertTrue(stage2p.tryProcessWatermark(wm(10)));
// Then
assertEquals(collectionToString(asList(outboxFrame(2, 1), outboxFrame(3, 3), outboxFrame(4, 6), outboxFrame(5, 10), outboxFrame(6, 9), outboxFrame(7, 7), outboxFrame(8, 4), wm(10))), collectionToString(stage2Outbox.queue(0)));
}
use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.
the class AsyncTransformUsingServicePTest method test_wmNotCountedToParallelOps.
@Test
public void test_wmNotCountedToParallelOps() 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();
inbox.add("foo");
processor.process(0, inbox);
assertTrue("inbox not empty", inbox.isEmpty());
assertTrue("wm rejected", processor.tryProcessWatermark(wm(0)));
inbox.add("bar");
processor.process(0, inbox);
assertTrue("2nd item rejected even though max parallel ops is 1", inbox.isEmpty());
}
use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.
the class AbstractProcessorTest method before.
@Before
public void before() throws Exception {
inbox = new TestInbox();
inbox.add(MOCK_ITEM);
int[] capacities = new int[OUTBOX_BUCKET_COUNT];
Arrays.fill(capacities, 1);
outbox = new TestOutbox(capacities);
final Processor.Context ctx = new TestProcessorContext();
p = new RegisteringMethodCallsP();
p.init(outbox, ctx);
tryProcessP = new SpecializedByOrdinalP();
tryProcessP.init(outbox, ctx);
nothingOverriddenP = new NothingOverriddenP();
nothingOverriddenP.init(outbox, ctx);
}
use of com.hazelcast.jet.core.test.TestInbox in project hazelcast by hazelcast.
the class WriteFilePTest method test_abortUnfinishedTransaction_whenNoItemsProcessed.
@Test
public void test_abortUnfinishedTransaction_whenNoItemsProcessed() throws Exception {
// test for https://github.com/hazelcast/hazelcast/issues/19774
ProcessorMetaSupplier metaSupplier = writeFileP(directory.toString(), StandardCharsets.UTF_8, null, DISABLE_ROLLING, true, Objects::toString);
TestProcessorContext processorContext = new TestProcessorContext().setProcessingGuarantee(EXACTLY_ONCE);
@SuppressWarnings("unchecked") WriteFileP<Integer> processor = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
processor.init(new TestOutbox(new int[] { 128 }, 128), processorContext);
processor.process(0, new TestInbox(singletonList(42)));
assertTrue(processor.snapshotCommitPrepare());
checkFileContents(0, 0, true, true, true);
// Now a tmp file is created. Let's simulate that the prepared snapshot wasn't successful and
// the job restarted
@SuppressWarnings("unchecked") WriteFileP<Integer> processor2 = (WriteFileP<Integer>) TestSupport.supplierFrom(metaSupplier).get();
processor2.init(new TestOutbox(128), processorContext);
processor2.close();
// now there should be no temp files
checkFileContents(0, 0, true, false, true);
}
Aggregations