use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method shouldFetchCorrectlyAcrossSegments.
@Test
public void shouldFetchCorrectlyAcrossSegments() throws Exception {
final Windowed<String> a1 = new Windowed<>("a", new SessionWindow(0, 0));
final Windowed<String> a2 = new Windowed<>("a", new SessionWindow(Segments.MIN_SEGMENT_INTERVAL, Segments.MIN_SEGMENT_INTERVAL));
final Windowed<String> a3 = new Windowed<>("a", new SessionWindow(Segments.MIN_SEGMENT_INTERVAL * 2, Segments.MIN_SEGMENT_INTERVAL * 2));
cachingStore.put(a1, 1L);
cachingStore.put(a2, 2L);
cachingStore.put(a3, 3L);
cachingStore.flush();
final KeyValueIterator<Windowed<String>, Long> results = cachingStore.findSessions("a", 0, Segments.MIN_SEGMENT_INTERVAL * 2);
assertEquals(a1, results.next().key);
assertEquals(a2, results.next().key);
assertEquals(a3, results.next().key);
assertFalse(results.hasNext());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method shouldClearNamespaceCacheOnClose.
@Test
public void shouldClearNamespaceCacheOnClose() throws Exception {
final Windowed<String> a1 = new Windowed<>("a", new SessionWindow(0, 0));
cachingStore.put(a1, 1L);
assertEquals(1, cache.size());
cachingStore.close();
assertEquals(0, cache.size());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method addSingleSession.
private void addSingleSession(final String sessionId, final List<KeyValue<Windowed<String>, Long>> allSessions) {
final int timestamp = allSessions.size() * 10;
final Windowed<String> key = new Windowed<>(sessionId, new SessionWindow(timestamp, timestamp));
final Long value = 1L;
cachingStore.put(key, value);
allSessions.add(KeyValue.pair(key, value));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method shouldFetchAllSessionsWithSameRecordKey.
@Test
public void shouldFetchAllSessionsWithSameRecordKey() throws Exception {
final List<KeyValue<Windowed<String>, Long>> expected = Arrays.asList(KeyValue.pair(new Windowed<>("a", new SessionWindow(0, 0)), 1L), KeyValue.pair(new Windowed<>("a", new SessionWindow(10, 10)), 2L), KeyValue.pair(new Windowed<>("a", new SessionWindow(100, 100)), 3L), KeyValue.pair(new Windowed<>("a", new SessionWindow(1000, 1000)), 4L));
for (KeyValue<Windowed<String>, Long> kv : expected) {
cachingStore.put(kv.key, kv.value);
}
// add one that shouldn't appear in the results
cachingStore.put(new Windowed<>("aa", new SessionWindow(0, 0)), 5L);
final List<KeyValue<Windowed<String>, Long>> results = toList(cachingStore.fetch("a"));
assertEquals(expected, results);
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingSessionStoreTest method shouldRemove.
@Test
public void shouldRemove() throws Exception {
final Windowed<String> a = new Windowed<>("a", new SessionWindow(0, 0));
final Windowed<String> b = new Windowed<>("b", new SessionWindow(0, 0));
cachingStore.put(a, 2L);
cachingStore.put(b, 2L);
cachingStore.flush();
cachingStore.remove(a);
cachingStore.flush();
final KeyValueIterator<Windowed<String>, Long> rangeIter = cachingStore.findSessions("a", 0, 0);
assertFalse(rangeIter.hasNext());
}
Aggregations