use of org.apache.kafka.streams.KeyValueTimestamp in project kafka by apache.
the class CachingInMemorySessionStoreTest method shouldForwardChangedValuesDuringFlush.
@Test
public void shouldForwardChangedValuesDuringFlush() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(2, 4));
final Windowed<Bytes> b = new Windowed<>(keyA, new SessionWindow(1, 2));
final Windowed<String> aDeserialized = new Windowed<>("a", new SessionWindow(2, 4));
final Windowed<String> bDeserialized = new Windowed<>("a", new SessionWindow(1, 2));
final CacheFlushListenerStub<Windowed<String>, String> flushListener = new CacheFlushListenerStub<>(new SessionWindowedDeserializer<>(new StringDeserializer()), new StringDeserializer());
cachingStore.setFlushListener(flushListener, true);
cachingStore.put(b, "1".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(bDeserialized, new Change<>("1", null), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "1".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>("1", null), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "2".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>("2", "1"), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.remove(a);
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>(null, "2"), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "1".getBytes());
cachingStore.put(a, "2".getBytes());
cachingStore.remove(a);
cachingStore.flush();
assertEquals(Collections.emptyList(), flushListener.forwarded);
flushListener.forwarded.clear();
}
Aggregations