You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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"

Discussion thread: here 

JIRA: KAFKA-6460

Motivation

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 for developers when they are writing unit test for kafka stream and other related modules.

Public Interfaces

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.

We will provide a MockStoreFactory to generate Mock store builders:


package org.apache.kafka.streams.internals;

public class MockStoreFactory<K, V extends StoreBuilder> {

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

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

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

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

	public MockWindowStoreBuilder createWindowStoreBuilder(){
        return new MockWindowStoreBuilder<>(storeName, keySerde, valueSerde, time);
    }

	public MockSessionStoreBuilder createSessionStoreBuilder(){
        return new MockSessionStoreBuilder<>(storeName, keySerde, valueSerde, time);
    }
}

Each Store builder will have a build method:

package org.apache.kafka.streams.internals;

public class MockKeyValueStoreBuilder<K, V>  extends AbstractStoreBuilder<K, V, StateStore> {

    public MockKeyValueStoreBuilder(final String storeName,
                                    final Serde<K> keySerde,
                                    final Serde<V> valueSerde,
                                    final Time time) {
        super(storeName, keySerde, valueSerde, time);
    }

    @Override
    public KeyValueStore build() {
        return new InMemoryKeyValueStore(name);
    }
}


Compatibility, Deprecation, and Migration Plan

  • What impact (if any) will there be on existing users?
  • If we are changing behavior how will we phase out the older behavior?
  • If we need special migration tools, describe them here.
  • When will we remove the existing behavior?

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.

  • No labels