KAFKA-14134: Replace EasyMock with Mockito for WorkerConnectorTest#12472
KAFKA-14134: Replace EasyMock with Mockito for WorkerConnectorTest#12472C0urante merged 3 commits intoapache:trunkfrom
Conversation
divijvaidya
left a comment
There was a problem hiding this comment.
Thank you for the review. I added a minor comment, otherwise looks good.
| connector.version(); | ||
| expectLastCall().andReturn(VERSION); | ||
|
|
||
| offsetStore.start(); |
There was a problem hiding this comment.
I am adding this comment here to help other reviewers in reviewing the changes in these lines.
It is ok to remove these void calls because Mockito automatically creates stubs for void method calls. As long as we are verifying that they are being invoked, we should be good.
C0urante
left a comment
There was a problem hiding this comment.
Thanks Yash. I haven't looked closely at every individual case yet, but I've left a few stylistic remarks. I'm hoping that if we can clean some of the logic here into succinct, reusable methods then it'll be easier to review and verify with certainty that we haven't mistranslated anything or accidentally lost guarantees. Every case I have examined looks good so far though 👍
…verify calls into separate methods; reduce number of SuppressWarning annotations
|
Thanks for the reviews @divijvaidya and @C0urante! I've incorporated your feedback, could you please take another look? |
|
Looks good from my side! |
C0urante
left a comment
There was a problem hiding this comment.
Looking pretty good! Just a few more comments.
| verifyAll(); | ||
| verifyCleanInitialize(); | ||
| verify(listener).onFailure(CONNECTOR, exception); | ||
| verify(listener).onShutdown(CONNECTOR); |
There was a problem hiding this comment.
Almost every call to verifyCleanShutdown is preceded by a check to verify that listener::onShutdown was invoked. Could we add this logic to verifyCleanShutdown? Thinking of something like this:
private void verifyCleanShutdown() {
verifyShutdown(true);
}
private void verifyShutdown(boolean clean) {
verify(ctx).close();
verify(offsetStorageReader).close();
verify(offsetStore).stop();
if (clean) {
verify(listener).onShutdown(CONNECTOR);
}
}There was a problem hiding this comment.
We can also follow a similar approach with startup logic. This would involve renaming verifyCleanInitialize to verifyStartup and adding a clean parameter to the method:
private void verifyCleanStartup() {
verifyStartup(true);
}
private void verifyStartup(boolean clean) {
verify(connector).version();
if (connector instanceof SourceConnector) {
verify(offsetStore).start();
verify(connector).initialize(any(SourceConnectorContext.class));
} else {
verify(connector).initialize(any(SinkConnectorContext.class));
}
if (clean) {
verify(connector).start(CONFIG);
verify(listener).onStartup(CONNECTOR);
}
}(clean isn't the most accurate term here since there are clean startups in the paused state that would involve passing false for that parameter; feel free to replace with something better)
There was a problem hiding this comment.
The one for shutdown makes sense but I think with startup there are three different cases -
i) No call to connector.start or listener.onStartup (failure in initialization OR started in the paused state)
ii) Calls to both connector.start and listener.onStartup (successful start)
iii) Call to only connector.start (connector started in the paused state and then resumed OR failure on startup)
I think it might be more readable to keep these verify calls in the test methods as is rather than trying to force fit them into (in)appropriately named methods, WDYT?
…(10 August 2022) Trivial conflict in gradle/dependencies.gradle due to the newer Netty version in confluentinc/kafka. * apache-github/trunk: MINOR: Upgrade gradle to 7.5.1 and bump other build/test dependencies (apache#12495) KAFKA-14140: Ensure an offline or in-controlled-shutdown replica is not eligible to join ISR in ZK mode (apache#12487) KAFKA-14114: Add Metadata Error Related Metrics MINOR: BrokerMetadataSnapshotter must avoid exceeding batch size (apache#12486) MINOR: Upgrade mockito test dependencies (apache#12460) KAFKA-14144:; Compare AlterPartition LeaderAndIsr before fencing partition epoch (apache#12489) KAFKA-14134: Replace EasyMock with Mockito for WorkerConnectorTest (apache#12472) MINOR: Update scala version in bin scripts to 2.13.8 (apache#12477) KAFKA-14104; Add CRC validation when iterating over Metadata Log Records (apache#12457) MINOR: add :server-common test dependency to :storage (apache#12488) KAFKA-14107: Upgrade Jetty version for CVE fixes (apache#12440) KAFKA-14124: improve quorum controller fault handling (apache#12447)
* apache-github/trunk: (447 commits) KAFKA-13959: Controller should unfence Broker with busy metadata log (apache#12274) KAFKA-10199: Expose read only task from state updater (apache#12497) KAFKA-14154; Return NOT_CONTROLLER from AlterPartition if leader is ahead of controller (apache#12506) KAFKA-13986; Brokers should include node.id in fetches to metadata quorum (apache#12498) KAFKA-14163; Retry compilation after zinc compile cache error (apache#12507) Remove duplicate common.message.* from clients:test jar file (apache#12407) KAFKA-13060: Replace EasyMock and PowerMock with Mockito in WorkerGroupMemberTest.java (apache#12484) Fix the rate window size calculation for edge cases (apache#12184) MINOR: Upgrade gradle to 7.5.1 and bump other build/test dependencies (apache#12495) KAFKA-14140: Ensure an offline or in-controlled-shutdown replica is not eligible to join ISR in ZK mode (apache#12487) KAFKA-14114: Add Metadata Error Related Metrics MINOR: BrokerMetadataSnapshotter must avoid exceeding batch size (apache#12486) MINOR: Upgrade mockito test dependencies (apache#12460) KAFKA-14144:; Compare AlterPartition LeaderAndIsr before fencing partition epoch (apache#12489) KAFKA-14134: Replace EasyMock with Mockito for WorkerConnectorTest (apache#12472) MINOR: Update scala version in bin scripts to 2.13.8 (apache#12477) KAFKA-14104; Add CRC validation when iterating over Metadata Log Records (apache#12457) MINOR: add :server-common test dependency to :storage (apache#12488) KAFKA-14107: Upgrade Jetty version for CVE fixes (apache#12440) KAFKA-14124: improve quorum controller fault handling (apache#12447) ...
https://issues.apache.org/jira/browse/KAFKA-14134
From https://issues.apache.org/jira/browse/KAFKA-7438: