Search in sources :

Example 71 with KeyValueTimestamp

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

Aggregations

KeyValueTimestamp (org.apache.kafka.streams.KeyValueTimestamp)71 Test (org.junit.Test)65 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)46 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)44 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)36 Properties (java.util.Properties)26 Windowed (org.apache.kafka.streams.kstream.Windowed)22 Serdes (org.apache.kafka.common.serialization.Serdes)21 IntegrationTest (org.apache.kafka.test.IntegrationTest)20 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)19 KeyValue (org.apache.kafka.streams.KeyValue)19 Consumed (org.apache.kafka.streams.kstream.Consumed)17 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)16 MockApiProcessorSupplier (org.apache.kafka.test.MockApiProcessorSupplier)16 Bytes (org.apache.kafka.common.utils.Bytes)15 KStream (org.apache.kafka.streams.kstream.KStream)14 Duration (java.time.Duration)13 KafkaStreams (org.apache.kafka.streams.KafkaStreams)13 TestInputTopic (org.apache.kafka.streams.TestInputTopic)13 Utils.mkProperties (org.apache.kafka.common.utils.Utils.mkProperties)12