Search in sources :

Example 16 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox 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 17 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox 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)

Example 18 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox 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 19 with TestInbox

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

the class WriteBufferedPTest method writeBuffered_smokeTest.

@Test
public void writeBuffered_smokeTest() {
    DistributedSupplier<Processor> supplier = getLoggingBufferedWriter();
    Processor p = supplier.get();
    Outbox outbox = mock(Outbox.class);
    p.init(outbox, mock(Context.class));
    TestInbox inbox = new TestInbox();
    inbox.add(1);
    inbox.add(2);
    p.process(0, inbox);
    inbox.add(3);
    inbox.add(4);
    p.process(0, inbox);
    // watermark should not be written
    p.tryProcessWatermark(new Watermark(0));
    // empty flush
    p.process(0, inbox);
    p.complete();
    assertEquals(asList("new", "add:1", "add:2", "flush", "add:3", "add:4", "flush", "flush", "dispose"), events);
    assertEquals(0, inbox.size());
    verifyZeroInteractions(outbox);
}
Also used : Context(com.hazelcast.jet.core.Processor.Context) Processor(com.hazelcast.jet.core.Processor) TestInbox(com.hazelcast.jet.core.test.TestInbox) Outbox(com.hazelcast.jet.core.Outbox) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 20 with TestInbox

use of com.hazelcast.jet.core.test.TestInbox 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

TestInbox (com.hazelcast.jet.core.test.TestInbox)22 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)16 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)16 Test (org.junit.Test)13 Processor (com.hazelcast.jet.core.Processor)11 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 Watermark (com.hazelcast.jet.core.Watermark)6 SimpleTestInClusterSupport (com.hazelcast.jet.SimpleTestInClusterSupport)4 Outbox (com.hazelcast.jet.core.Outbox)4 Before (org.junit.Before)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Traverser (com.hazelcast.jet.Traverser)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 ILogger (com.hazelcast.logging.ILogger)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collection (java.util.Collection)3 Collections.singletonList (java.util.Collections.singletonList)3 Entry (java.util.Map.Entry)3