Search in sources :

Example 51 with TestProcessorContext

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

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

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.nio.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test)

Example 53 with TestProcessorContext

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

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

the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.

@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() {
    // When
    StreamKafkaP processor = createProcessor(2, StreamKafkaP::recordToEntry, 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    produce(topic1Name, 10, "foo");
    // Then
    assertEquals(entry(10, "foo"), consumeEventually(processor, outbox));
    long time1 = System.nanoTime();
    assertEquals(new Watermark(10 - LAG), consumeEventually(processor, outbox));
    long time2 = System.nanoTime();
    long elapsedMs = NANOSECONDS.toMillis(time2 - time1);
    assertTrue("elapsed time: " + elapsedMs + " ms, should be larger", elapsedMs > 3000 && elapsedMs <= 10_000);
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Example 55 with TestProcessorContext

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

the class StreamKafkaPTest method when_customProjection_then_used.

@Test
public void when_customProjection_then_used() {
    // When
    StreamKafkaP processor = createProcessor(2, r -> r.key() + "=" + r.value(), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    produce(topic1Name, 0, "0");
    // Then
    assertEquals("0=0", consumeEventually(processor, outbox));
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) 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