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

bibin sebastian commented on KAFKA-8977:
----------------------------------------

[~cadonna] Having going through all the usages of existing MockStreamsMetrics, 
what I generally see is that MockStreamsMetrics is used during initialisation 
steps of the test (For example to create ThreadCache and session store). The 
tests are not always directly accessing/invoking the methods of StreamsMetrics. 
Almost all the times access is indirect (As mentioned in the previos above 
observation as well). So I am not really seeing any great the value in creating 
a mock on StreamsMetricsImpl via PowerMock/EasyMock and replacing 
MockStreamsMetrics. 

Actually at first, I started with creating the mock using PowerMock/EasyMock. 
First of all it forced me to look at the initialisation steps and mock most of 
the methods for the initialisation steps. On top of these, since these tests 
are indirectly using StreamsMetricsImpl, I have to create separate expectation 
on mocks just to make the test pass. 
Had it been StreamsMetricsImpl being directly referred in the test methods, it 
would have been easy to mock the relevant methods but that is not the case in 
almost all the cases. 

All these findings makes me feel that replacing MockStreamsMetrics with 
StreamsMetricsImpl is the easiest and cleanest option at the moment. In some 
simple cases, I have used niceMock().

Updated the PR above. Can you please take a look?

> Remove MockStreamsMetrics Since it is not a Mock
> ------------------------------------------------
>
>                 Key: KAFKA-8977
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8977
>             Project: Kafka
>          Issue Type: Improvement
>          Components: streams
>            Reporter: Bruno Cadonna
>            Assignee: bibin sebastian
>            Priority: Minor
>              Labels: newbie
>
> The class {{MockStreamsMetrics}} is used throughout unit tests as a mock but 
> it is not really a mock since it only hides two parameters of the 
> {{StreamsMetricsImpl}} constructor. Either a real mock or the real 
> {{StreamsMetricsImpl}} should be used in the tests.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to