-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Conversation
@mimaison I believe you might be best suited to review this pull request :) |
There was a problem hiding this 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.
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Thank you for the review @C0urante! I will have a look and aim to provide answers (+ new commits) in the next couple of days. |
There was a problem hiding this 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.
connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStore.java
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
@clolov are you planning on revisiting this one? |
Hello, yes I am, it is the next one on my list :) |
There was a problem hiding this 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.
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStore.java
Show resolved
Hide resolved
connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStore.java
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Outdated
Show resolved
Hide resolved
connect/runtime/src/test/java/org/apache/kafka/connect/storage/KafkaOffsetBackingStoreTest.java
Show resolved
Hide resolved
Thank you for the new comments @C0urante, I will aim to address them today! |
There was a problem hiding this 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.
The single test failure is unrelated; merging... |
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. |
…ge.KafkaOffsetBackingStoreTest (apache#12418) Reviewers: Chris Egerton <chrise@aiven.io>
Partially addressing https://issues.apache.org/jira/browse/KAFKA-13414. Other test files will be updated in other pull requests.