use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast-jet by hazelcast.
the class WindowGroupTransform_IntegrationTest method testSession_groupingFirst.
@Test
public void testSession_groupingFirst() {
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<Long, String>mapJournal("source", JournalInitialPosition.START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0)).window(WindowDefinition.session(2)).aggregate(toSet(), WindowResult::new).drainTo(Sinks.list("sink"));
testSession(p);
}
use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast-jet by hazelcast.
the class SessionWindowPTest method when_batchProcessing_then_flushEverything.
@Test
public void when_batchProcessing_then_flushEverything() {
List<Object> inbox = new ArrayList<>();
// Given
inbox.addAll(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 WindowResult(1, 22, "a", 3), new Watermark(25), new WindowResult(30, 50, "a", 3)));
}
use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast by hazelcast.
the class SourceBuilderTest method stream_socketSource_withTimestamps_andLateness.
@Test
public void stream_socketSource_withTimestamps_andLateness() throws IOException {
// Given
try (ServerSocket serverSocket = new ServerSocket(0)) {
startServer(serverSocket);
// When
int localPort = serverSocket.getLocalPort();
FunctionEx<String, Long> timestampFn = line -> Long.valueOf(line.substring(LINE_PREFIX.length()));
int lateness = 10;
long lastExpectedTs = itemCount - lateness;
StreamSource<String> socketSource = SourceBuilder.timestampedStream("socket-source-with-timestamps", ctx -> socketReader(localPort)).<String>fillBufferFn((in, buf) -> {
String line = in.readLine();
if (line != null) {
long ts = timestampFn.apply(line);
buf.add(line, ts);
if (ts >= lastExpectedTs) {
System.out.println(line);
}
}
}).destroyFn(BufferedReader::close).build();
// Then
Pipeline p = Pipeline.create();
p.readFrom(socketSource).withNativeTimestamps(lateness).window(tumbling(1)).aggregate(AggregateOperations.counting()).writeTo(sinkList());
hz().getJet().newJob(p);
List<WindowResult<Long>> expected = LongStream.range(1, itemCount - lateness).mapToObj(i -> new WindowResult<>(i - 1, i, 1L)).collect(toList());
assertTrueEventually(() -> assertEquals(expected, new ArrayList<>(sinkList)), 10);
}
}
use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast by hazelcast.
the class SourceBuilderTest method stream_distributed_socketSource_withTimestamps.
@Test
public void stream_distributed_socketSource_withTimestamps() throws IOException {
// Given
try (ServerSocket serverSocket = new ServerSocket(0)) {
startServer(serverSocket);
// When
int localPort = serverSocket.getLocalPort();
ToLongFunctionEx<String> timestampFn = line -> Long.valueOf(line.substring(LINE_PREFIX.length()));
BatchSource<String> socketSource = SourceBuilder.batch("socket-source-with-timestamps", ctx -> socketReader(localPort)).<String>fillBufferFn((in, buf) -> {
String line = in.readLine();
if (line != null) {
buf.add(line);
} else {
buf.close();
}
}).destroyFn(BufferedReader::close).distributed(PREFERRED_LOCAL_PARALLELISM).build();
// Then
Pipeline p = Pipeline.create();
p.readFrom(socketSource).addTimestamps(timestampFn, 1000).window(tumbling(1)).aggregate(AggregateOperations.counting()).writeTo(sinkList());
hz().getJet().newJob(p).join();
List<WindowResult<Long>> expected = LongStream.range(1, itemCount + 1).mapToObj(i -> new WindowResult<>(i - 1, i, (long) PREFERRED_LOCAL_PARALLELISM * MEMBER_COUNT)).collect(toList());
assertEquals(expected, new ArrayList<>(sinkList));
}
}
use of com.hazelcast.jet.datamodel.WindowResult in project hazelcast by hazelcast.
the class SourceBuilderTest method stream_socketSource_withTimestamps.
@Test
public void stream_socketSource_withTimestamps() throws IOException {
// Given
try (ServerSocket serverSocket = new ServerSocket(0)) {
startServer(serverSocket);
// When
int localPort = serverSocket.getLocalPort();
ToLongFunctionEx<String> timestampFn = line -> Long.valueOf(line.substring(LINE_PREFIX.length()));
BatchSource<String> socketSource = SourceBuilder.batch("socket-source-with-timestamps", ctx -> socketReader(localPort)).<String>fillBufferFn((in, buf) -> {
String line = in.readLine();
if (line != null) {
buf.add(line);
} else {
buf.close();
}
}).destroyFn(BufferedReader::close).build();
// Then
Pipeline p = Pipeline.create();
p.readFrom(socketSource).addTimestamps(timestampFn, 0).window(tumbling(1)).aggregate(AggregateOperations.counting()).writeTo(sinkList());
hz().getJet().newJob(p).join();
List<WindowResult<Long>> expected = LongStream.range(1, itemCount + 1).mapToObj(i -> new WindowResult<>(i - 1, i, 1L)).collect(toList());
assertEquals(expected, new ArrayList<>(sinkList));
}
}
Aggregations