Search in sources :

Example 11 with WindowResult

use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast by hazelcast.

the class SourceBuilderTest method test_faultTolerance_restartTwice.

@Test
public void test_faultTolerance_restartTwice() {
    StreamSource<Integer> source = integerSequenceSource(true);
    long windowSize = 100;
    IList<WindowResult<Long>> result = hz().getList("result-" + UuidUtil.newUnsecureUuidString());
    Pipeline p = Pipeline.create();
    p.readFrom(source).withNativeTimestamps(0).window(tumbling(windowSize)).aggregate(AggregateOperations.counting()).peek().writeTo(Sinks.list(result));
    Job job = hz().getJet().newJob(p, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE));
    assertTrueEventually(() -> assertFalse("result list is still empty", result.isEmpty()));
    // restart the job
    job.restart();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // wait until more results are added
    int oldSize = result.size();
    assertTrueEventually(() -> assertTrue("no more results added to the list", result.size() > oldSize));
    // restart the job for the second time
    job.restart();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // wait until more results are added
    int sizeAfterSecondRestart = result.size();
    assertTrueEventually(() -> assertTrue("no more results added to the list", result.size() > sizeAfterSecondRestart));
    cancelAndJoin(job);
    // results should contain a monotonic sequence of results, each with count=windowSize
    Iterator<WindowResult<Long>> iterator = result.iterator();
    for (int i = 0; i < result.size(); i++) {
        WindowResult<Long> next = iterator.next();
        assertEquals(windowSize, (long) next.result());
        assertEquals(i * windowSize, next.start());
    }
}
Also used : WindowResult(com.hazelcast.jet.datamodel.WindowResult) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test)

Example 12 with WindowResult

use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast by hazelcast.

the class SourceBuilderTest method test_nonFaultTolerantSource_processingGuaranteeNone.

@Test
public void test_nonFaultTolerantSource_processingGuaranteeNone() {
    StreamSource<Integer> source = integerSequenceSource(false);
    long windowSize = 100;
    IList<WindowResult<Long>> result = hz().getList("result-" + UuidUtil.newUnsecureUuidString());
    Pipeline p = Pipeline.create();
    p.readFrom(source).withNativeTimestamps(0).window(tumbling(windowSize)).aggregate(AggregateOperations.counting()).peek().writeTo(Sinks.list(result));
    Job job = hz().getJet().newJob(p);
    assertTrueEventually(() -> assertFalse("result list is still empty", result.isEmpty()));
    // restart the job
    job.restart();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // wait until more results are added
    int oldSize = result.size();
    assertTrueEventually(() -> assertTrue("no more results added to the list", result.size() > oldSize));
    cancelAndJoin(job);
    Iterator<WindowResult<Long>> iterator = result.iterator();
    int startAfterRestartIndex = 0;
    for (int i = 0; i < result.size(); i++) {
        WindowResult<Long> next = iterator.next();
        long resultStart = next.start();
        assertEquals(windowSize, (long) next.result());
        if (i != 0 && resultStart == 0) {
            startAfterRestartIndex = i;
            break;
        }
        assertEquals(i * windowSize, resultStart);
    }
    for (int i = 1; i < result.size() - startAfterRestartIndex; i++) {
        WindowResult<Long> next = iterator.next();
        assertEquals(i * windowSize, next.start());
        assertEquals(windowSize, (long) next.result());
    }
}
Also used : WindowResult(com.hazelcast.jet.datamodel.WindowResult) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 13 with WindowResult

use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast-jet by hazelcast.

the class WindowAggregateTransform_IntegrationTest method testSession.

@Test
public void testSession() {
    IMap<Long, String> map = instance.getMap("source");
    map.put(0L, "foo");
    map.put(3L, "bar");
    map.put(4L, "baz");
    map.put(10L, "flush-item");
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.session(2)).aggregate(toSet(), (winStart, winEnd, result) -> new WindowResult<>(winStart, winEnd, "", result)).drainTo(Sinks.list("sink"));
    instance.newJob(p);
    assertTrueEventually(() -> assertEquals(listToString(asList(new WindowResult<>(0, 2, "", set(entry(0L, "foo"))), new WindowResult<>(3, 6, "", set(entry(3L, "bar"), entry(4L, "baz"))))), listToString(instance.getHazelcastInstance().getList("sink"))), 5);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) GroupProperty(com.hazelcast.spi.properties.GroupProperty) WindowAggregateBuilder(com.hazelcast.jet.pipeline.WindowAggregateBuilder) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) TestUtil.set(com.hazelcast.jet.core.TestUtil.set) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) SlidingWindowDef(com.hazelcast.jet.pipeline.SlidingWindowDef) Util.entry(com.hazelcast.jet.Util.entry) Arrays.asList(java.util.Arrays.asList) Before(org.junit.Before) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) AggregateOperations.toTwoBags(com.hazelcast.jet.aggregate.AggregateOperations.toTwoBags) AggregateOperations.toSet(com.hazelcast.jet.aggregate.AggregateOperations.toSet) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) ParallelTest(com.hazelcast.test.annotation.ParallelTest) Category(org.junit.experimental.categories.Category) StageWithWindow(com.hazelcast.jet.pipeline.StageWithWindow) TimestampedItem(com.hazelcast.jet.datamodel.TimestampedItem) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) TwoBags(com.hazelcast.jet.datamodel.TwoBags) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) WindowResult(com.hazelcast.jet.datamodel.WindowResult) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

WindowResult (com.hazelcast.jet.datamodel.WindowResult)13 Test (org.junit.Test)12 Job (com.hazelcast.jet.Job)9 Assert.assertEquals (org.junit.Assert.assertEquals)7 JobConfig (com.hazelcast.jet.config.JobConfig)6 WindowDefinition.tumbling (com.hazelcast.jet.pipeline.WindowDefinition.tumbling)5 IList (com.hazelcast.collection.IList)4 UuidUtil (com.hazelcast.internal.util.UuidUtil)4 AggregateOperations (com.hazelcast.jet.aggregate.AggregateOperations)4 EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 ArrayList (java.util.ArrayList)4 Category (org.junit.experimental.categories.Category)4 FunctionEx (com.hazelcast.function.FunctionEx)3 ToLongFunctionEx (com.hazelcast.function.ToLongFunctionEx)3 JobRepository (com.hazelcast.jet.impl.JobRepository)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 FileReader (java.io.FileReader)3