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

Matthias J. Sax commented on KAFKA-6460:
----------------------------------------

Internally, the DSL always uses the class `Stores` to create state store. Thus, 
if one write code like
{quote}{{stream.groupByKey().aggregate(...)}}
{quote}
and want to test the aggregator by inspecting the store, one want to inject a 
mocked store. However, to do this, the code must be re-written to
{quote}{{stream.groupByKey().aggregate(..., 
Materialized.as(MockStoreFactory.mockedKeyValueStore(...));}}{quote}
This implies that production code and test code is not the same. For proper 
testing, it should be possible to test the original code directly without 
rewriting the code.

The current `TopologyTestDriver` also works that way – it takes an unmodified 
`Topology` that can either be handed to `KafkaStream` to actually run it, or to 
the driver to test it. It's not necessary to rewrite the code that assembles 
the `Topology` in order to test it. For mocked stores, it should work the same 
way. Does it make sense?

> 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