use of org.apache.kafka.streams.kstream.internals.UnlimitedWindow in project apache-kafka-on-k8s by banzaicloud.
the class UnlimitedWindowsTest method shouldIncludeRecordsThatHappenedAfterWindowStart.
@Test
public void shouldIncludeRecordsThatHappenedAfterWindowStart() {
UnlimitedWindows w = UnlimitedWindows.of().startOn(anyStartTime);
long timestamp = w.startMs + 1;
Map<Long, UnlimitedWindow> matchedWindows = w.windowsFor(timestamp);
assertEquals(1, matchedWindows.size());
assertEquals(new UnlimitedWindow(anyStartTime), matchedWindows.get(anyStartTime));
}
use of org.apache.kafka.streams.kstream.internals.UnlimitedWindow in project apache-kafka-on-k8s by banzaicloud.
the class UnlimitedWindowsTest method shouldIncludeRecordsThatHappenedOnWindowStart.
@Test
public void shouldIncludeRecordsThatHappenedOnWindowStart() {
UnlimitedWindows w = UnlimitedWindows.of().startOn(anyStartTime);
Map<Long, UnlimitedWindow> matchedWindows = w.windowsFor(w.startMs);
assertEquals(1, matchedWindows.size());
assertEquals(new UnlimitedWindow(anyStartTime), matchedWindows.get(anyStartTime));
}
use of org.apache.kafka.streams.kstream.internals.UnlimitedWindow in project kafka by apache.
the class UnlimitedWindowsTest method shouldIncludeRecordsThatHappenedAfterWindowStart.
@Test
public void shouldIncludeRecordsThatHappenedAfterWindowStart() {
final UnlimitedWindows w = UnlimitedWindows.of().startOn(ofEpochMilli(ANY_START_TIME));
final long timestamp = w.startMs + 1;
final Map<Long, UnlimitedWindow> matchedWindows = w.windowsFor(timestamp);
assertEquals(1, matchedWindows.size());
assertEquals(new UnlimitedWindow(ANY_START_TIME), matchedWindows.get(ANY_START_TIME));
}
use of org.apache.kafka.streams.kstream.internals.UnlimitedWindow in project kafka by apache.
the class KStreamAggregationIntegrationTest method shouldCountUnlimitedWindows.
@Test
public void shouldCountUnlimitedWindows() throws Exception {
final long startTime = mockTime.milliseconds() - TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS) + 1;
final long incrementTime = Duration.ofDays(1).toMillis();
final long t1 = mockTime.milliseconds() - TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS);
final List<KeyValue<String, String>> t1Messages = Arrays.asList(new KeyValue<>("bob", "start"), new KeyValue<>("penny", "start"), new KeyValue<>("jo", "pause"), new KeyValue<>("emily", "pause"));
final Properties producerConfig = TestUtils.producerConfig(CLUSTER.bootstrapServers(), StringSerializer.class, StringSerializer.class, new Properties());
IntegrationTestUtils.produceKeyValuesSynchronouslyWithTimestamp(userSessionsStream, t1Messages, producerConfig, t1);
final long t2 = t1 + incrementTime;
IntegrationTestUtils.produceKeyValuesSynchronouslyWithTimestamp(userSessionsStream, Collections.singletonList(new KeyValue<>("emily", "resume")), producerConfig, t2);
final long t3 = t2 + incrementTime;
IntegrationTestUtils.produceKeyValuesSynchronouslyWithTimestamp(userSessionsStream, Arrays.asList(new KeyValue<>("bob", "pause"), new KeyValue<>("penny", "stop")), producerConfig, t3);
final long t4 = t3 + incrementTime;
IntegrationTestUtils.produceKeyValuesSynchronouslyWithTimestamp(userSessionsStream, Arrays.asList(// bobs session continues
new KeyValue<>("bob", "resume"), // jo's starts new session
new KeyValue<>("jo", "resume")), producerConfig, t4);
final Map<Windowed<String>, KeyValue<Long, Long>> results = new HashMap<>();
final CountDownLatch latch = new CountDownLatch(5);
builder.stream(userSessionsStream, Consumed.with(Serdes.String(), Serdes.String())).groupByKey(Grouped.with(Serdes.String(), Serdes.String())).windowedBy(UnlimitedWindows.of().startOn(ofEpochMilli(startTime))).count().toStream().transform(() -> new Transformer<Windowed<String>, Long, KeyValue<Object, Object>>() {
private ProcessorContext context;
@Override
public void init(final ProcessorContext context) {
this.context = context;
}
@Override
public KeyValue<Object, Object> transform(final Windowed<String> key, final Long value) {
results.put(key, KeyValue.pair(value, context.timestamp()));
latch.countDown();
return null;
}
@Override
public void close() {
}
});
startStreams();
assertTrue(latch.await(30, TimeUnit.SECONDS));
assertThat(results.get(new Windowed<>("bob", new UnlimitedWindow(startTime))), equalTo(KeyValue.pair(2L, t4)));
assertThat(results.get(new Windowed<>("penny", new UnlimitedWindow(startTime))), equalTo(KeyValue.pair(1L, t3)));
assertThat(results.get(new Windowed<>("jo", new UnlimitedWindow(startTime))), equalTo(KeyValue.pair(1L, t4)));
assertThat(results.get(new Windowed<>("emily", new UnlimitedWindow(startTime))), equalTo(KeyValue.pair(1L, t2)));
}
use of org.apache.kafka.streams.kstream.internals.UnlimitedWindow in project kafka by apache.
the class UnlimitedWindowsTest method shouldIncludeRecordsThatHappenedOnWindowStart.
@Test
public void shouldIncludeRecordsThatHappenedOnWindowStart() {
final UnlimitedWindows w = UnlimitedWindows.of().startOn(ofEpochMilli(ANY_START_TIME));
final Map<Long, UnlimitedWindow> matchedWindows = w.windowsFor(w.startMs);
assertEquals(1, matchedWindows.size());
assertEquals(new UnlimitedWindow(ANY_START_TIME), matchedWindows.get(ANY_START_TIME));
}
Aggregations