Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-13414: Replace PowerMock/EasyMock with Mockito in connect.storage.KafkaOffsetBackingStoreTest #12418

Merged
merged 2 commits into from
Nov 15, 2022

Conversation

clolov
Copy link
Contributor

@clolov clolov commented Jul 18, 2022

Partially addressing https://issues.apache.org/jira/browse/KAFKA-13414. Other test files will be updated in other pull requests.

@clolov
Copy link
Contributor Author

clolov commented Jul 18, 2022

@mimaison I believe you might be best suited to review this pull request :)

@C0urante C0urante self-requested a review July 30, 2022 21:34
Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @clolov, this is looking pretty good! I have a few comments; a couple are fairly high-level so if you have any questions and/or want to clarify anything before working on the next round, let me know.

Comment on lines 221 to 222
doAnswer(invocation -> {
// Second get() should get the produced data and return the new values
capturedConsumedCallback.getValue().onCompletion(null,
new ConsumerRecord<>(TOPIC, 0, 0, 0L, TimestampType.CREATE_TIME, 0, 0, TP0_KEY.array(), TP0_VALUE.array(),
new RecordHeaders(), Optional.empty()));
new ConsumerRecord<>(TOPIC, 0, 0, 0L, TimestampType.CREATE_TIME, 0, 0, TP0_KEY.array(), TP0_VALUE.array(),
new RecordHeaders(), Optional.empty()));
capturedConsumedCallback.getValue().onCompletion(null,
new ConsumerRecord<>(TOPIC, 1, 0, 0L, TimestampType.CREATE_TIME, 0, 0, TP1_KEY.array(), TP1_VALUE.array(),
new RecordHeaders(), Optional.empty()));
secondGetReadToEndCallback.getValue().onCompletion(null, null);
new ConsumerRecord<>(TOPIC, 1, 0, 0L, TimestampType.CREATE_TIME, 0, 0, TP1_KEY.array(), TP1_VALUE.array(),
new RecordHeaders(), Optional.empty()));
storeLogCallbackArgumentCaptor.getValue().onCompletion(null, null);
return null;
});

// Third get() should pick up data produced by someone else and return those values
final Capture<Callback<Void>> thirdGetReadToEndCallback = EasyMock.newCapture();
storeLog.readToEnd(EasyMock.capture(thirdGetReadToEndCallback));
PowerMock.expectLastCall().andAnswer(() -> {
}).doAnswer(invocation -> {
// Third get() should pick up data produced by someone else and return those values
capturedConsumedCallback.getValue().onCompletion(null,
new ConsumerRecord<>(TOPIC, 0, 1, 0L, TimestampType.CREATE_TIME, 0, 0, TP0_KEY.array(), TP0_VALUE_NEW.array(),
new RecordHeaders(), Optional.empty()));
new ConsumerRecord<>(TOPIC, 0, 1, 0L, TimestampType.CREATE_TIME, 0, 0, TP0_KEY.array(), TP0_VALUE_NEW.array(),
new RecordHeaders(), Optional.empty()));
capturedConsumedCallback.getValue().onCompletion(null,
new ConsumerRecord<>(TOPIC, 1, 1, 0L, TimestampType.CREATE_TIME, 0, 0, TP1_KEY.array(), TP1_VALUE_NEW.array(),
new RecordHeaders(), Optional.empty()));
thirdGetReadToEndCallback.getValue().onCompletion(null, null);
new ConsumerRecord<>(TOPIC, 1, 1, 0L, TimestampType.CREATE_TIME, 0, 0, TP1_KEY.array(), TP1_VALUE_NEW.array(),
new RecordHeaders(), Optional.empty()));
storeLogCallbackArgumentCaptor.getValue().onCompletion(null, null);
return null;
});
}).when(storeLog).readToEnd(storeLogCallbackArgumentCaptor.capture());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to set up the expectations for all three calls to KafkaOffsetBackingStore::get at once. We can set up the expectation for each right before we invoke the method.

This has a few advantages:

  • Cleanliness (the chained doAnswer method invocations are a little unintuitive)
  • Readability (placing expectation-setting code closer to execution code makes it easier to see how the two are related)

In general, I think we should try to follow Mockito idioms more closely with these tests by establishing expectations as late as possible in tests, instead of having a monolithic expectation-setting section at the beginning of each test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I have addressed this in the upcoming commit.

@clolov
Copy link
Contributor Author

clolov commented Aug 3, 2022

Thank you for the review @C0urante! I will have a look and aim to provide answers (+ new commits) in the next couple of days.

Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @clolov, this is looking pretty good! Apologies for the delay; I should be more responsive now.

@C0urante
Copy link
Contributor

C0urante commented Nov 7, 2022

@clolov are you planning on revisiting this one?

@clolov
Copy link
Contributor Author

clolov commented Nov 7, 2022

Hello, yes I am, it is the next one on my list :)

Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @clolov! Looking great; once this is rebased and the remaining comments are addressed it'll probably be ready to merge.

@clolov
Copy link
Contributor Author

clolov commented Nov 15, 2022

Thank you for the new comments @C0urante, I will aim to address them today!

Copy link
Contributor

@C0urante C0urante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @clolov! Will merge pending CI build.

@C0urante
Copy link
Contributor

The single test failure is unrelated; merging...

@C0urante C0urante merged commit 1894856 into apache:trunk Nov 15, 2022
@clolov
Copy link
Contributor Author

clolov commented Nov 16, 2022

Thank you for the quick turnaround on the review @C0urante! I will aim to open a couple more pull requests in the upcoming days for Connect with respect to the Mockito migration and tag you there.

guozhangwang pushed a commit to guozhangwang/kafka that referenced this pull request Jan 25, 2023
…ge.KafkaOffsetBackingStoreTest (apache#12418)

Reviewers: Chris Egerton <chrise@aiven.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants