Search in sources :

Example 11 with TestProcessorContext

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

the class WriteSocketTest method unitTest.

@Test
public void unitTest() throws Exception {
    AtomicInteger counter = new AtomicInteger();
    ServerSocket serverSocket = new ServerSocket(0);
    new Thread(() -> uncheckRun(() -> {
        Socket socket = serverSocket.accept();
        serverSocket.close();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
            while (reader.readLine() != null) {
                counter.incrementAndGet();
            }
        }
    })).start();
    TestInbox inbox = new TestInbox();
    range(0, ITEM_COUNT).forEach(inbox::add);
    Processor p = supplierFrom(writeSocketP("localhost", serverSocket.getLocalPort(), Object::toString, UTF_8)).get();
    p.init(mock(Outbox.class), new TestProcessorContext());
    p.process(0, inbox);
    p.complete();
    assertTrueEventually(() -> assertTrue(counter.get() >= ITEM_COUNT));
    // wait a little to check, if the counter doesn't get too far
    Thread.sleep(500);
    assertEquals(ITEM_COUNT, counter.get());
}
Also used : Processor(com.hazelcast.jet.core.Processor) InputStreamReader(java.io.InputStreamReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestInbox(com.hazelcast.jet.core.test.TestInbox) BufferedReader(java.io.BufferedReader) Outbox(com.hazelcast.jet.core.Outbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 12 with TestProcessorContext

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

the class StreamKafkaPTest method when_eventsInSinglePartition_then_watermarkAfterIdleTime.

@Test
public void when_eventsInSinglePartition_then_watermarkAfterIdleTime() throws Exception {
    // When
    StreamKafkaP processor = createProcessor(properties(), 2, r -> entry(r.key(), r.value()), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.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);
    assertBetween("elapsed time", elapsedMs, 3000, 30_000);
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with TestProcessorContext

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

the class StreamKafkaPTest method when_customProjectionToNull_then_filteredOut.

@Test
public void when_customProjectionToNull_then_filteredOut() throws Exception {
    // When
    EventTimePolicy<String> eventTimePolicy = eventTimePolicy(Long::parseLong, limitingLag(0), 1, 0, 0);
    StreamKafkaP processor = new StreamKafkaP<Integer, String, String>(properties(), singletonList(topic1Name), r -> "0".equals(r.value()) ? null : r.value(), eventTimePolicy);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.produce(topic1Name, 0, "0");
    kafkaTestSupport.produce(topic1Name, 0, "1");
    // Then
    assertTrueEventually(() -> {
        assertFalse(processor.complete());
        assertFalse("no item in outbox", outbox.queue(0).isEmpty());
    }, 3);
    assertEquals("1", outbox.queue(0).poll());
    assertNull(outbox.queue(0).poll());
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with TestProcessorContext

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

the class StreamKafkaPTest method when_customProjection_then_used.

@Test
public void when_customProjection_then_used() throws Exception {
    // When
    StreamKafkaP processor = createProcessor(properties(), 2, r -> r.key() + "=" + r.value(), 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext());
    kafkaTestSupport.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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with TestProcessorContext

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

the class StreamSocketPTest method before.

@Before
public void before() {
    outbox = new TestOutbox(10);
    context = new TestProcessorContext();
    bucket = outbox.queue(0);
    input = input.replaceAll("%n", "\n").replaceAll("%r", "\r");
}
Also used : TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Before(org.junit.Before)

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