use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class RocksDBSegmentedBytesStoreTest method shouldBeAbleToWriteToReInitializedStore.
@Test
public void shouldBeAbleToWriteToReInitializedStore() {
final String key = "a";
// need to create a segment so we can attempt to write to it again.
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
bytesStore.close();
bytesStore.init(context, bytesStore);
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class RocksDBSessionStoreTest method shouldFindValuesWithinMergingSessionWindowRange.
@Test
public void shouldFindValuesWithinMergingSessionWindowRange() {
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 apache-kafka-on-k8s by banzaicloud.
the class CachingSessionStoreTest method shouldNotForwardChangedValuesDuringFlushWhenSendOldValuesDisabled.
@Test
public void shouldNotForwardChangedValuesDuringFlushWhenSendOldValuesDisabled() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(0, 0));
final Windowed<String> aDeserialized = new Windowed<>("a", new SessionWindow(0, 0));
final List<KeyValue<Windowed<String>, Change<String>>> flushed = new ArrayList<>();
cachingStore.setFlushListener(new CacheFlushListener<Windowed<String>, String>() {
@Override
public void apply(final Windowed<String> key, final String newValue, final String oldValue) {
flushed.add(KeyValue.pair(key, new Change<>(newValue, oldValue)));
}
}, false);
cachingStore.put(a, "1".getBytes());
cachingStore.flush();
cachingStore.put(a, "2".getBytes());
cachingStore.flush();
assertEquals(flushed, Arrays.asList(KeyValue.pair(aDeserialized, new Change<>("1", null)), KeyValue.pair(aDeserialized, new Change<>("2", null))));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class CachingSessionStoreTest method shouldForwardChangedValuesDuringFlushWhenSendOldValuesDisabledNewRecordIsNull.
@Test
public void shouldForwardChangedValuesDuringFlushWhenSendOldValuesDisabledNewRecordIsNull() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(0, 0));
final Windowed<String> aDeserialized = new Windowed<>("a", new SessionWindow(0, 0));
final List<KeyValue<Windowed<String>, Change<String>>> flushed = new ArrayList<>();
cachingStore.setFlushListener(new CacheFlushListener<Windowed<String>, String>() {
@Override
public void apply(final Windowed<String> key, final String newValue, final String oldValue) {
flushed.add(KeyValue.pair(key, new Change<>(newValue, oldValue)));
}
}, false);
cachingStore.put(a, "1".getBytes());
cachingStore.flush();
cachingStore.put(a, "2".getBytes());
cachingStore.flush();
cachingStore.remove(a);
cachingStore.flush();
assertEquals(flushed, Arrays.asList(KeyValue.pair(aDeserialized, new Change<>("1", null)), KeyValue.pair(aDeserialized, new Change<>("2", null)), KeyValue.pair(aDeserialized, new Change<>(null, "2"))));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project apache-kafka-on-k8s by banzaicloud.
the class CachingSessionStoreTest method shouldFetchAllSessionsWithSameRecordKey.
@Test
public void shouldFetchAllSessionsWithSameRecordKey() {
final List<KeyValue<Windowed<Bytes>, byte[]>> expected = Arrays.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 (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