Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state"Under Discussion"

...

This is for adding mocks for state stores used in Streams unit testing. We'd like to use mocks for different types of state stores: KV, window, session - that can be used to record the number of expected put / get calls used in the DSL operator unit testing. These will provide conveniency provide convenience for developers when they are writing unit test for kafka Kafka stream and other related modules.

...

These will be internal classes, so no public API/interface.

Proposed Changes

Describe the new thing you want to do in appropriate detail. This may be fairly extensive and have large subsections of its own. Or it may be a few sentences. Use judgement based on the scope of the change.

I will use the KeyValueStore as an example. Window and Session will have a similar structure.

We will provide a MockStoreFactory to generate Mock store builders:

...

Code Block
package org.apache.kafka.streams.internals;

public class MockStoreFactory<K, V> {

    final String storeName;
    final Serde<K> keySerde;
    final Serde<V> valueSerde;
    final Time time;
    final Boolean persistent;

    public MockStoreFactory (final String storeName,
                             final Serde<K> keySerde,
                             final Serde<V> valueSerde,
                             final Time time,
                             final Boolean persistent) {

        this.storeName = storeName;
        this.keySerde = keySerde;
        this.valueSerde = valueSerde;
        this.time = time;
        this.persistent = persistent;
    }

    public MockKeyValueStoreBuilder createKeyValueStoreBuilder(){
        return new MockKeyValueStoreBuilder<K,V>(storeName, keySerde, valueSerde, time, persistent);
    }
}

I will use the KeyValueStoreBuilder as an example. Window and Session will have a similar structure.

Each Store builder will have a build method:

...

Then in the Store, we will be build a wrapper around a InMemoryStore, and capture all the get/put calls (excluding Iterators)

...

2) Track all calls in a total order.

  • Now I haven't get got a feature request to track calls within a total order, so now we track the order separately. If there is a need, we can definitely adjust it.

...

  • Now the MockStateStoreFactory only provides build() functionality, but not access(i.e. getStore(String storeName)) to StoreBuilders and Stores. Developer Developers have to access these Stores separately. If there is a request to allow access from the factory, we can adjust that.

...