[ 
https://issues.apache.org/jira/browse/KAFKA-6460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16769862#comment-16769862
 ] 

Yishun Guan commented on KAFKA-6460:
------------------------------------

Sounds good to me [~mjsax] and [~guozhang], the design scope and all the use 
cases are a little bit out of reach to me already. So if I am continuing with 
this story, a KIP should be the way to go, so I can gather more opinions and 
suggestions.

 

>From what I am seeing, what we want is to implement mock stores. So we will be 
>implementing a `MockStoreFactory` that generates 'MockxxxStoreBuilder' that 
>generates 'MockxxxStoreSupplier', so we are implementing all these layers? 
>Which ones should be EasyMock? 'MockxxxStoreSupplier' should be tracking it's 
>function calls, what kind of detail levels do we want? So it be similar to 
>KeyValueStoreTestDriver's structure?

These will be mainly used with the `TopologyTestDriver` (the other usage is to 
replace the vanilla store test drivers like KeyValueStoreTestDriver), so use 
the following as an example:

 
{code:java}
@Test
public void shouldDriveGlobalStore() {
 final String storeName = "my-store";
 final String global = "global";
 final String topic = "topic";

 
topology.addGlobalStore(Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore(storeName),
 Serdes.String(), Serdes.String()).withLoggingDisabled(),
 global, STRING_DESERIALIZER, STRING_DESERIALIZER, topic, "processor", 
define(new StatefulProcessor(storeName)));

 driver = new TopologyTestDriver(topology, props);
 final KeyValueStore<String, String> globalStore = 
driver.getKeyValueStore(storeName);
 driver.pipeInput(recordFactory.create(topic, "key1", "value1"));
 driver.pipeInput(recordFactory.create(topic, "key2", "value2"));
 assertEquals("value1", globalStore.get("key1"));
 assertEquals("value2", globalStore.get("key2"));
}{code}
>From what Guozhang is saying, even though `Topology` takes an 
>'inMemoryKeyValueStore', we need to have something under the hood of 
>`TopologyTestDriver`, that will iterate through the stores in 'Topology' and 
>replace them with a 'MockStoreFactory.mockedKeyValueStore(...', is that true?

I agree, more could be discussed through a KIP, I will prepare one soon.

> Add mocks for state stores used in Streams unit testing
> -------------------------------------------------------
>
>                 Key: KAFKA-6460
>                 URL: https://issues.apache.org/jira/browse/KAFKA-6460
>             Project: Kafka
>          Issue Type: Improvement
>          Components: streams, unit tests
>            Reporter: Guozhang Wang
>            Assignee: Yishun Guan
>            Priority: Major
>              Labels: newbie++
>
> 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. This involves implementing the two 
> interfaces {{StoreSupplier}} and {{StoreBuilder}} that can return a object 
> created from, say, EasyMock, and the object can then be set up with the 
> expected calls.
> In addition, we should also add a mock record collector which can be returned 
> from the mock processor context so that with logging enabled store, users can 
> also validate if the changes have been forwarded to the changelog as well.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to