use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingInMemorySessionStoreTest method shouldFetchRangeCorrectlyAcrossSegments.
@Test
public void shouldFetchRangeCorrectlyAcrossSegments() {
final Windowed<Bytes> a1 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 0, SEGMENT_INTERVAL * 0));
final Windowed<Bytes> aa1 = new Windowed<>(keyAA, new SessionWindow(SEGMENT_INTERVAL * 0, SEGMENT_INTERVAL * 0));
final Windowed<Bytes> a2 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 1, SEGMENT_INTERVAL * 1));
final Windowed<Bytes> a3 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 2, SEGMENT_INTERVAL * 2));
final Windowed<Bytes> aa3 = new Windowed<>(keyAA, new SessionWindow(SEGMENT_INTERVAL * 2, SEGMENT_INTERVAL * 2));
cachingStore.put(a1, "1".getBytes());
cachingStore.put(aa1, "1".getBytes());
cachingStore.put(a2, "2".getBytes());
cachingStore.put(a3, "3".getBytes());
cachingStore.put(aa3, "3".getBytes());
final KeyValueIterator<Windowed<Bytes>, byte[]> rangeResults = cachingStore.findSessions(keyA, keyAA, 0, SEGMENT_INTERVAL * 2);
final List<Windowed<Bytes>> keys = new ArrayList<>();
while (rangeResults.hasNext()) {
keys.add(rangeResults.next().key);
}
rangeResults.close();
assertEquals(asList(a1, aa1, a2, a3, aa3), keys);
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingPersistentSessionStoreTest method shouldClearNamespaceCacheOnClose.
@Test
public void shouldClearNamespaceCacheOnClose() {
final Windowed<Bytes> a1 = new Windowed<>(keyA, new SessionWindow(0, 0));
cachingStore.put(a1, "1".getBytes());
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 CachingPersistentSessionStoreTest method addSingleSession.
private void addSingleSession(final String sessionId, final List<KeyValue<Windowed<Bytes>, byte[]>> allSessions) {
final int timestamp = allSessions.size() * 10;
final Windowed<Bytes> key = new Windowed<>(Bytes.wrap(sessionId.getBytes()), new SessionWindow(timestamp, timestamp));
final byte[] value = "1".getBytes();
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 CachingPersistentSessionStoreTest method shouldRemove.
@Test
public void shouldRemove() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(0, 0));
final Windowed<Bytes> b = new Windowed<>(keyB, new SessionWindow(0, 0));
cachingStore.put(a, "2".getBytes());
cachingStore.put(b, "2".getBytes());
cachingStore.remove(a);
try (final KeyValueIterator<Windowed<Bytes>, byte[]> rangeIter = cachingStore.findSessions(keyA, 0, 0)) {
assertFalse(rangeIter.hasNext());
}
assertNull(cachingStore.fetchSession(keyA, 0, 0));
assertThat(cachingStore.fetchSession(keyB, 0, 0), equalTo("2".getBytes()));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingPersistentSessionStoreTest method shouldBackwardFetchRangeCorrectlyAcrossSegments.
@Test
public void shouldBackwardFetchRangeCorrectlyAcrossSegments() {
final Windowed<Bytes> a1 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 0, SEGMENT_INTERVAL * 0));
final Windowed<Bytes> aa1 = new Windowed<>(keyAA, new SessionWindow(SEGMENT_INTERVAL * 0, SEGMENT_INTERVAL * 0));
final Windowed<Bytes> a2 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 1, SEGMENT_INTERVAL * 1));
final Windowed<Bytes> a3 = new Windowed<>(keyA, new SessionWindow(SEGMENT_INTERVAL * 2, SEGMENT_INTERVAL * 2));
final Windowed<Bytes> aa3 = new Windowed<>(keyAA, new SessionWindow(SEGMENT_INTERVAL * 2, SEGMENT_INTERVAL * 2));
cachingStore.put(a1, "1".getBytes());
cachingStore.put(aa1, "1".getBytes());
cachingStore.put(a2, "2".getBytes());
cachingStore.put(a3, "3".getBytes());
cachingStore.put(aa3, "3".getBytes());
final KeyValueIterator<Windowed<Bytes>, byte[]> rangeResults = cachingStore.backwardFindSessions(keyA, keyAA, 0, SEGMENT_INTERVAL * 2);
final List<Windowed<Bytes>> keys = new ArrayList<>();
while (rangeResults.hasNext()) {
keys.add(rangeResults.next().key);
}
rangeResults.close();
assertEquals(asList(aa3, a3, a2, aa1, a1), keys);
}
Aggregations