use of com.hazelcast.jet.core.test.TestProcessorContext 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);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class StreamEventJournalPTest method assertRestore.
private void assertRestore(List<Entry> snapshotItems) throws Exception {
Processor p = supplier.get();
TestOutbox newOutbox = new TestOutbox(new int[] { 16 }, 16);
List<Object> output = new ArrayList<>();
p.init(newOutbox, new TestProcessorContext().setHazelcastInstance(instance));
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.test.TestProcessorContext in project hazelcast by hazelcast.
the class StreamEventJournalPTest method when_newData.
@Test
public void when_newData() throws Exception {
TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
List<Object> actual = new ArrayList<>();
Processor p = supplier.get();
p.init(outbox, new TestProcessorContext().setHazelcastInstance(instance));
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.test.TestProcessorContext 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);
}
use of com.hazelcast.jet.core.test.TestProcessorContext in project hazelcast by hazelcast.
the class WriteLoggerPTest method test.
@Test
public void test() throws Exception {
// Given
Processor p = supplierFrom(writeLoggerP()).get();
TestInbox inbox = new TestInbox();
Outbox outbox = mock(Outbox.class);
ILogger logger = mock(ILogger.class);
p.init(outbox, new TestProcessorContext().setLogger(logger));
// When
inbox.add(1);
p.process(0, inbox);
Watermark wm = new Watermark(2);
p.tryProcessWatermark(wm);
// Then
verifyZeroInteractions(outbox);
verify(logger).info("1");
verify(logger).fine(wm.toString());
verifyZeroInteractions(logger);
}
Aggregations