Search in sources :

Example 1 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.

the class CachingSessionStoreTest method shouldFetchCorrectlyAcrossSegments.

@Test
public void shouldFetchCorrectlyAcrossSegments() throws Exception {
    final Windowed<String> a1 = new Windowed<>("a", new SessionWindow(0, 0));
    final Windowed<String> a2 = new Windowed<>("a", new SessionWindow(Segments.MIN_SEGMENT_INTERVAL, Segments.MIN_SEGMENT_INTERVAL));
    final Windowed<String> a3 = new Windowed<>("a", new SessionWindow(Segments.MIN_SEGMENT_INTERVAL * 2, Segments.MIN_SEGMENT_INTERVAL * 2));
    cachingStore.put(a1, 1L);
    cachingStore.put(a2, 2L);
    cachingStore.put(a3, 3L);
    cachingStore.flush();
    final KeyValueIterator<Windowed<String>, Long> results = cachingStore.findSessions("a", 0, Segments.MIN_SEGMENT_INTERVAL * 2);
    assertEquals(a1, results.next().key);
    assertEquals(a2, results.next().key);
    assertEquals(a3, 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)

Example 2 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.

the class CachingSessionStoreTest method shouldClearNamespaceCacheOnClose.

@Test
public void shouldClearNamespaceCacheOnClose() throws Exception {
    final Windowed<String> a1 = new Windowed<>("a", new SessionWindow(0, 0));
    cachingStore.put(a1, 1L);
    assertEquals(1, cache.size());
    cachingStore.close();
    assertEquals(0, cache.size());
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 3 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.

the class CachingSessionStoreTest method addSingleSession.

private void addSingleSession(final String sessionId, final List<KeyValue<Windowed<String>, Long>> allSessions) {
    final int timestamp = allSessions.size() * 10;
    final Windowed<String> key = new Windowed<>(sessionId, new SessionWindow(timestamp, timestamp));
    final Long value = 1L;
    cachingStore.put(key, value);
    allSessions.add(KeyValue.pair(key, value));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow)

Example 4 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.

the class CachingSessionStoreTest method shouldFetchAllSessionsWithSameRecordKey.

@Test
public void shouldFetchAllSessionsWithSameRecordKey() throws Exception {
    final List<KeyValue<Windowed<String>, Long>> expected = Arrays.asList(KeyValue.pair(new Windowed<>("a", new SessionWindow(0, 0)), 1L), KeyValue.pair(new Windowed<>("a", new SessionWindow(10, 10)), 2L), KeyValue.pair(new Windowed<>("a", new SessionWindow(100, 100)), 3L), KeyValue.pair(new Windowed<>("a", new SessionWindow(1000, 1000)), 4L));
    for (KeyValue<Windowed<String>, Long> kv : expected) {
        cachingStore.put(kv.key, kv.value);
    }
    // add one that shouldn't appear in the results
    cachingStore.put(new Windowed<>("aa", new SessionWindow(0, 0)), 5L);
    final List<KeyValue<Windowed<String>, Long>> results = toList(cachingStore.fetch("a"));
    assertEquals(expected, results);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) KeyValue(org.apache.kafka.streams.KeyValue) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 5 with SessionWindow

use of org.apache.kafka.streams.kstream.internals.SessionWindow in project kafka by apache.

the class CachingSessionStoreTest method shouldRemove.

@Test
public void shouldRemove() throws Exception {
    final Windowed<String> a = new Windowed<>("a", new SessionWindow(0, 0));
    final Windowed<String> b = new Windowed<>("b", new SessionWindow(0, 0));
    cachingStore.put(a, 2L);
    cachingStore.put(b, 2L);
    cachingStore.flush();
    cachingStore.remove(a);
    cachingStore.flush();
    final KeyValueIterator<Windowed<String>, Long> rangeIter = cachingStore.findSessions("a", 0, 0);
    assertFalse(rangeIter.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