Search in sources :

Example 31 with Watermark

use of com.hazelcast.jet.core.Watermark 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 32 with Watermark

use of com.hazelcast.jet.core.Watermark in project hazelcast-jet by hazelcast.

the class StreamKafkaPTest method when_noAssignedPartitionAndAddedLater_then_resumesFromIdle.

@Test
public void when_noAssignedPartitionAndAddedLater_then_resumesFromIdle() throws Exception {
    // we ask to create 5th out of 5 processors, but we have only 4 partitions and 1 topic
    // --> our processor will have nothing assigned
    StreamKafkaP processor = createProcessor(1, StreamKafkaP::recordToEntry, 10_000);
    TestOutbox outbox = new TestOutbox(new int[] { 10 }, 10);
    processor.init(outbox, new TestProcessorContext().setTotalParallelism(INITIAL_PARTITION_COUNT + 1).setGlobalProcessorIndex(INITIAL_PARTITION_COUNT));
    assertTrue(processor.currentAssignment.isEmpty());
    assertEquals(IDLE_MESSAGE, consumeEventually(processor, outbox));
    setPartitionCount(topic1Name, INITIAL_PARTITION_COUNT + 1);
    Thread.sleep(1000);
    // this allows production to the added partition
    resetProducer();
    // produce events until the event happens to go to the added partition
    Entry<Integer, String> event;
    for (int i = 0; ; i++) {
        event = entry(i, Integer.toString(i));
        Future<RecordMetadata> future = produce(topic1Name, event.getKey(), event.getValue());
        RecordMetadata recordMetadata = future.get();
        if (recordMetadata.partition() == 4) {
            break;
        }
    }
    assertEquals(new Watermark(event.getKey() - LAG), consumeEventually(processor, outbox));
    assertEquals(event, consumeEventually(processor, outbox));
}
Also used : RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Watermark(com.hazelcast.jet.core.Watermark) Test(org.junit.Test)

Aggregations

Watermark (com.hazelcast.jet.core.Watermark)32 Test (org.junit.Test)17 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)12 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Processor (com.hazelcast.jet.core.Processor)7 ArrayList (java.util.ArrayList)6 ProgressState (com.hazelcast.jet.impl.util.ProgressState)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Random (java.util.Random)4 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)4 JetException (com.hazelcast.jet.JetException)3 Outbox (com.hazelcast.jet.core.Outbox)3 TestInbox (com.hazelcast.jet.core.test.TestInbox)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Traverser (com.hazelcast.jet.Traverser)2 Util.entry (com.hazelcast.jet.Util.entry)2 AggregateOperations (com.hazelcast.jet.aggregate.AggregateOperations)2