chia7712 commented on code in PR #16351:
URL: https://github.com/apache/kafka/pull/16351#discussion_r1642956855
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskThreadedTest.java:
##########
@@ -643,7 +647,11 @@ public Object answer(InvocationOnMock invocation) {
}
}
}).when(sinkTask).preCommit(anyMap());
-
+ // if the only command has error, consumer don't commit, so we don't
need to mock commitAsync.
Review Comment:
Could we have two methods?
```java
private void expectPreCommit(ExpectOffsetCommitCommand... commands) {
doAnswer(new Answer<Object>() {
int index = 0;
@Override
public Object answer(InvocationOnMock invocation) {
ExpectOffsetCommitCommand commitCommand = commands[index++];
// All assigned partitions will have offsets committed, but
we've only processed messages/updated offsets for one
final Map<TopicPartition, OffsetAndMetadata> offsetsToCommit
= offsetsToCommitFn.apply(commitCommand.expectedMessages);
if (commitCommand.error != null) {
throw commitCommand.error;
} else {
return offsetsToCommit;
}
}
}).when(sinkTask).preCommit(anyMap());
}
private void expectOffsetCommit(ExpectOffsetCommitCommand... commands) {
expectPreCommit(commands);
...
}
```
with that changes, each test case can call specific "expect"
##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSourceTaskTest.java:
##########
@@ -190,19 +187,10 @@ public class WorkerSourceTaskTest {
new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA,
KEY, RECORD_SCHEMA, RECORD)
);
- private final boolean enableTopicCreation;
-
- @ParameterizedTest.Parameters
- public static Collection<Boolean> parameters() {
- return Arrays.asList(false, true);
- }
+ private boolean enableTopicCreation;
Review Comment:
we should remove this, and each test case should call `expectTopicCreation`
when `enableTopicCreation=true`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]