Search in sources :

Example 1 with DEFAULT_IDLE_TIMEOUT

use of com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT in project hazelcast by hazelcast.

the class StreamSourceTest method test.

private void test(long idleTimeout) {
    StreamSource<Object> source = SourceBuilder.stream("src", Context::globalProcessorIndex).distributed(1).fillBufferFn((index, buf) -> {
        // idle, there should be no output.
        if (index == 0) {
            buf.add("item");
            Thread.sleep(10);
        }
    }).build();
    if (idleTimeout != DEFAULT_IDLE_TIMEOUT) {
        source = source.setPartitionIdleTimeout(idleTimeout);
    }
    Pipeline p = Pipeline.create();
    p.readFrom(source).withTimestamps(o -> System.currentTimeMillis(), 0).window(WindowDefinition.tumbling(100)).aggregate(counting()).writeTo(sink);
    Job job = allHazelcastInstances()[0].getJet().newJob(p);
    if (idleTimeout > 10_000) {
        assertTrueAllTheTime(() -> assertEquals("unexpected sink size", 0, sinkList.size()), 5);
    } else if (idleTimeout < 1000) {
        assertTrueEventually(() -> assertTrue("sink empty", sinkList.size() > 0));
    } else {
        fail("test not designed for idleTimeout=" + idleTimeout);
    }
    cancelAndJoin(job);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) QuickTest(com.hazelcast.test.annotation.QuickTest) DEFAULT_IDLE_TIMEOUT(com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT) Context(com.hazelcast.jet.core.Processor.Context) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) Category(org.junit.experimental.categories.Category) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) Job(com.hazelcast.jet.Job)

Aggregations

Job (com.hazelcast.jet.Job)1 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)1 DEFAULT_IDLE_TIMEOUT (com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT)1 Context (com.hazelcast.jet.core.Processor.Context)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1