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());
}
}
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());
}
}
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);
}
Aggregations