Search in sources :

Example 41 with TestProcessorContext

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);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Objects(java.util.Objects) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with TestProcessorContext

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);
}
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 43 with TestProcessorContext

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);
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with TestProcessorContext

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);
}
Also used : TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 45 with TestProcessorContext

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);
}
Also used : Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) Outbox(com.hazelcast.jet.core.Outbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ILogger(com.hazelcast.logging.ILogger) Watermark(com.hazelcast.jet.core.Watermark) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)58 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)50 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Processor (com.hazelcast.jet.core.Processor)17 TestInbox (com.hazelcast.jet.core.test.TestInbox)16 Watermark (com.hazelcast.jet.core.Watermark)13 ArrayList (java.util.ArrayList)12 Before (org.junit.Before)10 Entry (java.util.Map.Entry)9 Outbox (com.hazelcast.jet.core.Outbox)7 Context (com.hazelcast.jet.core.Processor.Context)6 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)6 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)6 FunctionEx (com.hazelcast.function.FunctionEx)4 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Traverser (com.hazelcast.jet.Traverser)4 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)4 HashSet (java.util.HashSet)4