Search in sources :

Example 46 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.

the class StreamEventJournalPTest method when_lostItems.

@Test
public void when_lostItems() {
    TestOutbox outbox = new TestOutbox(new int[] { 16 }, 16);
    Processor p = supplier.get();
    p.init(outbox, new TestProcessorContext());
    // 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);
}
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) Test(org.junit.Test)

Example 47 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox 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);
}
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 48 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox 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);
}
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) Test(org.junit.Test)

Example 49 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.

the class StreamFilesPTest method initializeProcessor.

private void initializeProcessor(String glob) {
    if (glob == null) {
        glob = "*";
    }
    processor = new StreamFilesP(workDir.getAbsolutePath(), UTF_8, glob, 1, 0, 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 50 with TestOutbox

use of com.hazelcast.jet.core.test.TestOutbox in project hazelcast-jet by hazelcast.

the class AbstractProcessorTest method before.

@Before
public void before() {
    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 = mock(Processor.Context.class);
    Mockito.when(ctx.logger()).thenReturn(mock(ILogger.class));
    p = new RegisteringMethodCallsP();
    p.init(outbox, ctx);
    tryProcessP = new SpecializedByOrdinalP();
    tryProcessP.init(outbox, ctx);
    nothingOverriddenP = new NothingOverriddenP();
    nothingOverriddenP.init(outbox, ctx);
}
Also used : TestInbox(com.hazelcast.jet.core.test.TestInbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) ILogger(com.hazelcast.logging.ILogger) Before(org.junit.Before)

Aggregations

TestOutbox (com.hazelcast.jet.core.test.TestOutbox)56 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)50 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Processor (com.hazelcast.jet.core.Processor)14 TestInbox (com.hazelcast.jet.core.test.TestInbox)14 ArrayList (java.util.ArrayList)12 Watermark (com.hazelcast.jet.core.Watermark)11 Entry (java.util.Map.Entry)10 Before (org.junit.Before)8 Context (com.hazelcast.jet.core.Processor.Context)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 Outbox (com.hazelcast.jet.core.Outbox)4 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)4 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)4 HashSet (java.util.HashSet)4