use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSessionStoreTest method shouldPutAndFindSessionsInRange.
@Test
public void shouldPutAndFindSessionsInRange() throws Exception {
final String key = "a";
final Windowed<String> a1 = new Windowed<>(key, new SessionWindow(10, 10L));
final Windowed<String> a2 = new Windowed<>(key, new SessionWindow(500L, 1000L));
sessionStore.put(a1, 1L);
sessionStore.put(a2, 2L);
sessionStore.put(new Windowed<>(key, new SessionWindow(1500L, 2000L)), 1L);
sessionStore.put(new Windowed<>(key, new SessionWindow(2500L, 3000L)), 2L);
final List<KeyValue<Windowed<String>, Long>> expected = Arrays.asList(KeyValue.pair(a1, 1L), KeyValue.pair(a2, 2L));
final KeyValueIterator<Windowed<String>, Long> values = sessionStore.findSessions(key, 0, 1000L);
assertEquals(expected, toList(values));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchema method extractWindow.
public static Window extractWindow(final byte[] binaryKey) {
final ByteBuffer buffer = ByteBuffer.wrap(binaryKey);
final long start = buffer.getLong(binaryKey.length - TIMESTAMP_SIZE);
final long end = buffer.getLong(binaryKey.length - 2 * TIMESTAMP_SIZE);
return new SessionWindow(start, end);
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchemaTest method testUpperBoundWithLargeTimestamps.
@Test
public void testUpperBoundWithLargeTimestamps() {
Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), Long.MAX_VALUE);
assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
assertThat(upper, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchemaTest method testUpperBoundWithKeyBytesLargerThanFirstTimestampByte.
@Test
public void testUpperBoundWithKeyBytesLargerThanFirstTimestampByte() {
Bytes upper = sessionKeySchema.upperRange(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F, (byte) 0x9F }), Long.MAX_VALUE);
assertThat("shorter key with max timestamp should be in range", upper.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) >= 0);
assertThat(upper, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, (byte) 0x8F, (byte) 0x9F }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchemaTest method testLowerBoundWithZeroTimestamp.
@Test
public void testLowerBoundWithZeroTimestamp() {
Bytes lower = sessionKeySchema.lowerRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), 0);
assertThat(lower, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), new SessionWindow(0, 0))))));
}
Aggregations