Search in sources :

Example 6 with SessionWindow

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));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 7 with SessionWindow

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());
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 8 with SessionWindow

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());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 9 with SessionWindow

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());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 10 with SessionWindow

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());
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Aggregations

SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)117 Test (org.junit.Test)107 Windowed (org.apache.kafka.streams.kstream.Windowed)101 Bytes (org.apache.kafka.common.utils.Bytes)50 KeyValue (org.apache.kafka.streams.KeyValue)46 ArrayList (java.util.ArrayList)10 StreamsTestUtils.verifyWindowedKeyValue (org.apache.kafka.test.StreamsTestUtils.verifyWindowedKeyValue)8 LinkedList (java.util.LinkedList)6 Properties (java.util.Properties)6 ReadOnlySessionStoreStub (org.apache.kafka.test.ReadOnlySessionStoreStub)6 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)4 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)4 KeyValueTimestamp (org.apache.kafka.streams.KeyValueTimestamp)4 IntegrationTest (org.apache.kafka.test.IntegrationTest)4 KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2