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);
}
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());
}
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);
}
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);
}
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());
}
Aggregations