use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSessionStoreTest method shouldFindValuesWithinMergingSessionWindowRange.
@Test
public void shouldFindValuesWithinMergingSessionWindowRange() throws Exception {
final String key = "a";
sessionStore.put(new Windowed<>(key, new SessionWindow(0L, 0L)), 1L);
sessionStore.put(new Windowed<>(key, new SessionWindow(1000L, 1000L)), 2L);
final KeyValueIterator<Windowed<String>, Long> results = sessionStore.findSessions(key, -1, 1000L);
final List<KeyValue<Windowed<String>, Long>> expected = Arrays.asList(KeyValue.pair(new Windowed<>(key, new SessionWindow(0L, 0L)), 1L), KeyValue.pair(new Windowed<>(key, new SessionWindow(1000L, 1000L)), 2L));
assertEquals(expected, toList(results));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method shouldPutFetchFromCache.
@Test
public void shouldPutFetchFromCache() throws Exception {
cachingStore.put(new Windowed<>("a", new SessionWindow(0, 0)), 1L);
cachingStore.put(new Windowed<>("aa", new SessionWindow(0, 0)), 1L);
cachingStore.put(new Windowed<>("b", new SessionWindow(0, 0)), 1L);
final KeyValueIterator<Windowed<String>, Long> a = cachingStore.findSessions("a", 0, 0);
final KeyValueIterator<Windowed<String>, Long> b = cachingStore.findSessions("b", 0, 0);
assertEquals(KeyValue.pair(new Windowed<>("a", new SessionWindow(0, 0)), 1L), a.next());
assertEquals(KeyValue.pair(new Windowed<>("b", new SessionWindow(0, 0)), 1L), b.next());
assertFalse(a.hasNext());
assertFalse(b.hasNext());
assertEquals(3, cache.size());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchemaTest method before.
@Before
public void before() {
sessionKeySchema.init("topic");
final List<KeyValue<Bytes, Integer>> keys = Arrays.asList(KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0, 0 }), new SessionWindow(0, 0)))), 1), KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0 }), new SessionWindow(0, 0)))), 2), KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0, 0, 0 }), new SessionWindow(0, 0)))), 3), KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0 }), new SessionWindow(10, 20)))), 4), KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0, 0 }), new SessionWindow(10, 20)))), 5), KeyValue.pair(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0, 0, 0 }), new SessionWindow(10, 20)))), 6));
iterator = new DelegatingPeekingKeyValueIterator<>("foo", new KeyValueIteratorStub<>(keys.iterator()));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class SessionKeySchemaTest method testLowerBoundMatchesTrailingZeros.
@Test
public void testLowerBoundMatchesTrailingZeros() {
Bytes lower = sessionKeySchema.lowerRange(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), Long.MAX_VALUE);
assertThat("appending zeros to key should still be in range", lower.compareTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), new SessionWindow(Long.MAX_VALUE, Long.MAX_VALUE))))) < 0);
assertThat(lower, equalTo(Bytes.wrap(SessionKeySchema.toBinary(new Windowed<>(Bytes.wrap(new byte[] { 0xA, 0xB, 0xC }), new SessionWindow(0, 0))))));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class RocksDBSegmentedBytesStoreTest method shouldLoadSegementsWithOldStyleDateFormattedName.
@Test
public void shouldLoadSegementsWithOldStyleDateFormattedName() {
final Segments segments = new Segments(storeName, retention, numSegments);
final String key = "a";
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(30000L, 60000L))), serializeValue(100L));
bytesStore.close();
final String firstSegmentName = segments.segmentName(0);
final String[] nameParts = firstSegmentName.split("\\.");
final Long segmentId = Long.parseLong(nameParts[1]);
final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
formatter.setTimeZone(new SimpleTimeZone(0, "UTC"));
final String formatted = formatter.format(new Date(segmentId * segmentInterval(retention, numSegments)));
final File parent = new File(stateDir, storeName);
final File oldStyleName = new File(parent, nameParts[0] + "-" + formatted);
assertTrue(new File(parent, firstSegmentName).renameTo(oldStyleName));
bytesStore = new RocksDBSegmentedBytesStore(storeName, retention, numSegments, schema);
bytesStore.init(context, bytesStore);
final List<KeyValue<Windowed<String>, Long>> results = toList(bytesStore.fetch(Bytes.wrap(key.getBytes()), 0L, 60000L));
assertThat(results, equalTo(Arrays.asList(KeyValue.pair(new Windowed<>(key, new SessionWindow(0L, 0L)), 50L), KeyValue.pair(new Windowed<>(key, new SessionWindow(30000L, 60000L)), 100L))));
}
Aggregations