Search in sources :

Example 11 with Watermark

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

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

the class AsyncTransformUsingServicePTest method test_futuresCompletedInSeparateThread.

@Test
public void test_futuresCompletedInSeparateThread() {
    TestSupport.verifyProcessor(getSupplier((ctx, item) -> {
        CompletableFuture<Traverser<String>> f = new CompletableFuture<>();
        spawn(() -> f.complete(traverseItems(item + "-1", item + "-2")));
        return f;
    })).hazelcastInstance(instance()).input(asList("a", "b", new Watermark(10))).outputChecker((expected, actual) -> actual.equals(asList("a-1", "a-2", "b-1", "b-2", wm(10))) || !ordered && actual.equals(asList("b-1", "b-2", "a-1", "a-2", wm(10)))).disableProgressAssertion().expectOutput(singletonList("<see code>"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Traverser(com.hazelcast.jet.Traverser) 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 Watermark

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

the class AsyncTransformUsingServiceBatchedPTest method test_futuresCompletedInSeparateThread.

@Test
public void test_futuresCompletedInSeparateThread() {
    TestSupport.verifyProcessor(getSupplier((ctx, items) -> {
        CompletableFuture<Traverser<String>> f = new CompletableFuture<>();
        spawn(() -> f.complete(traverseIterable(items).flatMap(item -> traverseItems(item + "-1", item + "-2"))));
        return f;
    })).hazelcastInstance(instance()).input(asList("a", "b", new Watermark(10))).outputChecker((expected, actual) -> actual.equals(asList("a-1", "a-2", "b-1", "b-2", wm(10)))).disableProgressAssertion().expectOutput(singletonList("<see code>"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Traverser(com.hazelcast.jet.Traverser) Watermark(com.hazelcast.jet.core.Watermark) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with Watermark

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

the class SessionWindowPTest method when_batchProcessing_then_flushEverything.

@Test
public void when_batchProcessing_then_flushEverything() {
    // Given
    List<Object> inbox = new ArrayList<>(eventsWithKey("a"));
    // This watermark will cause the first session to be emitted, but not the second.
    // The second session will be emitted in complete()
    inbox.add(new Watermark(25));
    verifyProcessor(supplier).input(inbox).expectOutput(asList(new KeyedWindowResult<>(1, 22, "a", 3L, false), new Watermark(25), new KeyedWindowResult<>(30, 50, "a", 3L, false)));
}
Also used : ArrayList(java.util.ArrayList) Watermark(com.hazelcast.jet.core.Watermark) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with Watermark

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

the class SessionWindowPTest method assertCorrectness.

private void assertCorrectness(List<Object> events) {
    @SuppressWarnings("unchecked") List<Object> expectedOutput = events.stream().map(e -> ((Entry<String, Long>) e).getKey()).flatMap(SessionWindowPTest::expectedSessions).distinct().collect(toList());
    events.add(new Watermark(100));
    expectedOutput.add(new Watermark(100));
    try {
        verifyProcessor(supplier).outputChecker(SAME_ITEMS_ANY_ORDER).input(events).expectOutput(expectedOutput);
    } catch (AssertionError e) {
        System.err.println("Tested with events: " + events);
        throw e;
    }
}
Also used : Collections.shuffle(java.util.Collections.shuffle) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) Processor(com.hazelcast.jet.core.Processor) Random(java.util.Random) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestSupport.verifyProcessor(com.hazelcast.jet.core.test.TestSupport.verifyProcessor) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Watermark(com.hazelcast.jet.core.Watermark) Functions.entryKey(com.hazelcast.function.Functions.entryKey) Util.entry(com.hazelcast.jet.Util.entry) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ToLongFunction(java.util.function.ToLongFunction) Before(org.junit.Before) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Repeat(com.hazelcast.test.annotation.Repeat) SupplierEx(com.hazelcast.function.SupplierEx) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) SAME_ITEMS_ANY_ORDER(com.hazelcast.jet.core.test.TestSupport.SAME_ITEMS_ANY_ORDER) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Entry(java.util.Map.Entry) Watermark(com.hazelcast.jet.core.Watermark)

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