Search in sources :

Example 16 with Windowed

use of org.apache.kafka.streams.kstream.Windowed 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 17 with Windowed

use of org.apache.kafka.streams.kstream.Windowed 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)

Example 18 with Windowed

use of org.apache.kafka.streams.kstream.Windowed in project kafka by apache.

the class CachingWindowStoreTest method shouldForwardDirtyItemsWhenFlushCalled.

@Test
public void shouldForwardDirtyItemsWhenFlushCalled() throws Exception {
    final Windowed<String> windowedKey = new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE));
    cachingStore.put("1", "a");
    cachingStore.flush();
    assertEquals("a", cacheListener.forwarded.get(windowedKey).newValue);
    assertNull(cacheListener.forwarded.get(windowedKey).oldValue);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 19 with Windowed

use of org.apache.kafka.streams.kstream.Windowed in project kafka by apache.

the class CachingWindowStoreTest method shouldForwardOldValuesWhenEnabled.

@Test
public void shouldForwardOldValuesWhenEnabled() throws Exception {
    final Windowed<String> windowedKey = new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE));
    cachingStore.put("1", "a");
    cachingStore.flush();
    cachingStore.put("1", "b");
    cachingStore.flush();
    assertEquals("b", cacheListener.forwarded.get(windowedKey).newValue);
    assertEquals("a", cacheListener.forwarded.get(windowedKey).oldValue);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 20 with Windowed

use of org.apache.kafka.streams.kstream.Windowed in project kafka by apache.

the class CompositeReadOnlySessionStoreTest method shouldNotGetValueFromOtherStores.

@Test
public void shouldNotGetValueFromOtherStores() throws Exception {
    final Windowed<String> expectedKey = new Windowed<>("foo", new SessionWindow(0, 0));
    otherUnderlyingStore.put(new Windowed<>("foo", new SessionWindow(10, 10)), 10L);
    underlyingSessionStore.put(expectedKey, 1L);
    final KeyValueIterator<Windowed<String>, Long> result = sessionStore.fetch("foo");
    assertEquals(KeyValue.pair(expectedKey, 1L), result.next());
    assertFalse(result.hasNext());
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Aggregations

Windowed (org.apache.kafka.streams.kstream.Windowed)39 Test (org.junit.Test)32 KeyValue (org.apache.kafka.streams.KeyValue)18 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)18 HashMap (java.util.HashMap)6 KeyValueMapper (org.apache.kafka.streams.kstream.KeyValueMapper)6 KStreamTestDriver (org.apache.kafka.test.KStreamTestDriver)6 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)5 Bytes (org.apache.kafka.common.utils.Bytes)5 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)5 MockKeyValueMapper (org.apache.kafka.test.MockKeyValueMapper)5 Properties (java.util.Properties)4 Comparator (java.util.Comparator)3 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LongDeserializer (org.apache.kafka.common.serialization.LongDeserializer)2 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)2 KafkaStreams (org.apache.kafka.streams.KafkaStreams)2 Reducer (org.apache.kafka.streams.kstream.Reducer)2 ValueJoiner (org.apache.kafka.streams.kstream.ValueJoiner)2