use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class AbstractSessionBytesStoreTest method shouldPutAndBackwardFindSessionsInRange.
@Test
public void shouldPutAndBackwardFindSessionsInRange() {
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 LinkedList<KeyValue<Windowed<String>, Long>> expected = new LinkedList<>();
expected.add(KeyValue.pair(a1, 1L));
expected.add(KeyValue.pair(a2, 2L));
try (final KeyValueIterator<Windowed<String>, Long> values = sessionStore.backwardFindSessions(key, 0, 1000L)) {
assertEquals(toList(expected.descendingIterator()), toList(values));
}
final List<KeyValue<Windowed<String>, Long>> expected2 = Collections.singletonList(KeyValue.pair(a2, 2L));
try (final KeyValueIterator<Windowed<String>, Long> values2 = sessionStore.backwardFindSessions(key, 400L, 600L)) {
assertEquals(expected2, toList(values2));
}
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class SessionKeySchemaTest method testLowerBoundMatchesTrailingZeros.
@Test
public void testLowerBoundMatchesTrailingZeros() {
final 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(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(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 kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method before.
@Before
public void before() {
if (schema instanceof SessionKeySchema) {
windows[0] = new SessionWindow(10L, 10L);
windows[1] = new SessionWindow(500L, 1000L);
windows[2] = new SessionWindow(1_000L, 1_500L);
windows[3] = new SessionWindow(30_000L, 60_000L);
// All four of the previous windows will go into segment 1.
// The nextSegmentWindow is computed be a high enough time that when it gets written
// to the segment store, it will advance stream time past the first segment's retention time and
// expire it.
nextSegmentWindow = new SessionWindow(segmentInterval + retention, segmentInterval + retention);
}
if (schema instanceof WindowKeySchema) {
windows[0] = timeWindowForSize(10L, windowSizeForTimeWindow);
windows[1] = timeWindowForSize(500L, windowSizeForTimeWindow);
windows[2] = timeWindowForSize(1_000L, windowSizeForTimeWindow);
windows[3] = timeWindowForSize(60_000L, windowSizeForTimeWindow);
// All four of the previous windows will go into segment 1.
// The nextSegmentWindow is computed be a high enough time that when it gets written
// to the segment store, it will advance stream time past the first segment's retention time and
// expire it.
nextSegmentWindow = timeWindowForSize(segmentInterval + retention, windowSizeForTimeWindow);
}
bytesStore = getBytesStore();
stateDir = TestUtils.tempDirectory();
context = new InternalMockProcessorContext<>(stateDir, Serdes.String(), Serdes.Long(), new MockRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
bytesStore.init((StateStoreContext) context, bytesStore);
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingInMemorySessionStoreTest method shouldThrowIfTryingToPutIntoClosedCachingStore.
@Test
public void shouldThrowIfTryingToPutIntoClosedCachingStore() {
cachingStore.close();
assertThrows(InvalidStateStoreException.class, () -> cachingStore.put(new Windowed<>(keyA, new SessionWindow(0, 0)), "1".getBytes()));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class CachingInMemorySessionStoreTest method shouldFetchAllSessionsWithSameRecordKey.
@Test
public void shouldFetchAllSessionsWithSameRecordKey() {
final List<KeyValue<Windowed<Bytes>, byte[]>> expected = asList(KeyValue.pair(new Windowed<>(keyA, new SessionWindow(0, 0)), "1".getBytes()), KeyValue.pair(new Windowed<>(keyA, new SessionWindow(10, 10)), "2".getBytes()), KeyValue.pair(new Windowed<>(keyA, new SessionWindow(100, 100)), "3".getBytes()), KeyValue.pair(new Windowed<>(keyA, new SessionWindow(1000, 1000)), "4".getBytes()));
for (final KeyValue<Windowed<Bytes>, byte[]> kv : expected) {
cachingStore.put(kv.key, kv.value);
}
// add one that shouldn't appear in the results
cachingStore.put(new Windowed<>(keyAA, new SessionWindow(0, 0)), "5".getBytes());
final List<KeyValue<Windowed<Bytes>, byte[]>> results = toList(cachingStore.fetch(keyA));
verifyKeyValueList(expected, results);
}
Aggregations