use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSegmentedBytesStoreTest method shouldFindValuesWithinRange.
@Test
public void shouldFindValuesWithinRange() throws Exception {
final String key = "a";
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(1000L, 1000L))), serializeValue(10L));
final KeyValueIterator<Bytes, byte[]> results = bytesStore.fetch(Bytes.wrap(key.getBytes()), 1L, 1999L);
assertEquals(Collections.singletonList(KeyValue.pair(new Windowed<>(key, new SessionWindow(1000L, 1000L)), 10L)), toList(results));
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSegmentedBytesStoreTest method shouldRemove.
@Test
public void shouldRemove() throws Exception {
bytesStore.put(serializeKey(new Windowed<>("a", new SessionWindow(0, 1000))), serializeValue(30L));
bytesStore.put(serializeKey(new Windowed<>("a", new SessionWindow(1500, 2500))), serializeValue(50L));
bytesStore.remove(serializeKey(new Windowed<>("a", new SessionWindow(0, 1000))));
final KeyValueIterator<Bytes, byte[]> value = bytesStore.fetch(Bytes.wrap("a".getBytes()), 0, 1000L);
assertFalse(value.hasNext());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSessionStoreSupplierTest method shouldCreateLoggingEnabledStoreWhenStoreLogged.
@Test
public void shouldCreateLoggingEnabledStoreWhenStoreLogged() throws Exception {
store = createStore(true, false);
final List<ProducerRecord> logged = new ArrayList<>();
final NoOpRecordCollector collector = new NoOpRecordCollector() {
@Override
public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
logged.add(new ProducerRecord<K, V>(topic, partition, timestamp, key, value));
}
};
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), collector, cache);
context.setTime(1);
store.init(context, store);
store.put(new Windowed<>("a", new SessionWindow(0, 10)), "b");
assertFalse(logged.isEmpty());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSessionStoreSupplierTest method shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled.
@Test
public void shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled() throws Exception {
store = createStore(false, false);
final List<ProducerRecord> logged = new ArrayList<>();
final NoOpRecordCollector collector = new NoOpRecordCollector() {
@Override
public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
logged.add(new ProducerRecord<K, V>(topic, partition, timestamp, key, value));
}
};
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), collector, cache);
context.setTime(1);
store.init(context, store);
store.put(new Windowed<>("a", new SessionWindow(0, 10)), "b");
assertTrue(logged.isEmpty());
}
use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.
the class RocksDBSessionStoreTest method shouldFindSessionsToMerge.
@Test
public void shouldFindSessionsToMerge() throws Exception {
final Windowed<String> session1 = new Windowed<>("a", new SessionWindow(0, 100));
final Windowed<String> session2 = new Windowed<>("a", new SessionWindow(101, 200));
final Windowed<String> session3 = new Windowed<>("a", new SessionWindow(201, 300));
final Windowed<String> session4 = new Windowed<>("a", new SessionWindow(301, 400));
final Windowed<String> session5 = new Windowed<>("a", new SessionWindow(401, 500));
sessionStore.put(session1, 1L);
sessionStore.put(session2, 2L);
sessionStore.put(session3, 3L);
sessionStore.put(session4, 4L);
sessionStore.put(session5, 5L);
final KeyValueIterator<Windowed<String>, Long> results = sessionStore.findSessions("a", 150, 300);
assertEquals(session2, results.next().key);
assertEquals(session3, results.next().key);
assertFalse(results.hasNext());
}
Aggregations