KAFKA-16921: Migrate test of connect module to Junit5 (Runtime direct)#16351
KAFKA-16921: Migrate test of connect module to Junit5 (Runtime direct)#16351chia7712 merged 26 commits intoapache:trunkfrom
Conversation
# Conflicts: # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/AbstractHerderTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/ConnectMetricsTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/ConnectorConfigTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/ErrorHandlingTaskTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/ExactlyOnceWorkerSourceTaskTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/InternalSinkRecordTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/LoggersTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/RestartPlanTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/RestartRequestTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/SourceConnectorConfigTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/SourceTaskOffsetCommitterTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/SubmittedRecordsTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/TransformationConfigTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/TransformationStageTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConfigTransformerTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerConnectorTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerMetricsGroupTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskThreadedTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSourceTaskTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerTaskTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerTestUtils.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/IncrementalCooperativeAssignorTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/WorkerCoordinatorTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginScannerTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/PluginsTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/SynchronizationTest.java # connect/runtime/src/test/java/org/apache/kafka/connect/runtime/isolation/TestPlugins.java
chia7712
left a comment
There was a problem hiding this comment.
@gongxuanzhang thanks for this patch. MethodSource is not readable, so we should take a look at both ValueSource and EnumSource first.
| @Test | ||
| public void testRemoveMetrics() { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
There was a problem hiding this comment.
Could you please use @ValueSource(booleans = {true, false}) instead? that is more readable to me
| @Test | ||
| public void testStartPaused() throws Exception { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
| @Test | ||
| public void testPause() throws Exception { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
| @Test | ||
| public void testFailureInPreProducerCheck() throws Exception { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
|
|
||
| @Test | ||
| public void testFailureInProducerInitialization() throws Exception { | ||
| @ParameterizedTest |
| @Test | ||
| public void testTransitionStartedToStarted() { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
There was a problem hiding this comment.
Could you please use @EnumSource(value = ConnectorType.class, names = {"SOURCE", "SINK"}) instead? it is more readable
| @Test | ||
| public void testFailureInPoll() throws Exception { | ||
| @ParameterizedTest | ||
| @MethodSource("parameters") |
|
@chia7712 I update it |
chia7712
left a comment
There was a problem hiding this comment.
@gongxuanzhang thanks for updated PR
| private boolean enableTopicCreation; | ||
|
|
||
| @Parameterized.Parameters | ||
| public static Collection<Boolean> parameters() { |
| public static Collection<Boolean> parameters() { | ||
| return Arrays.asList(false, true); | ||
|
|
||
| public static Stream<Boolean> parameters() { |
| private ConnectorOffsetBackingStore offsetStore; | ||
|
|
||
| @Parameterized.Parameters | ||
| public static Collection<ConnectorType> parameters() { |
|
plz take a look @chia7712 |
|
@gongxuanzhang please fix those failed tests |
|
I have fixed all the test cases that failed due to the changes. |
chia7712
left a comment
There was a problem hiding this comment.
@gongxuanzhang thanks for updated PR
| } | ||
| }).when(sinkTask).preCommit(anyMap()); | ||
|
|
||
| // if the only command has error, consumer don't commit, so we don't need to mock commitAsync. |
There was a problem hiding this comment.
Could we have two methods?
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"
| public static Collection<Boolean> parameters() { | ||
| return Arrays.asList(false, true); | ||
| } | ||
| private boolean enableTopicCreation; |
There was a problem hiding this comment.
we should remove this, and each test case should call expectTopicCreation when enableTopicCreation=true
|
I update it. plz take a look @chia7712 |
…irect) (apache#16351) Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This PR is part of a task submodule, with the purpose of migrating from JUnit 4 to JUnit 5.
see
In this PR,AbstractWorkerSourceTaskTest test case has error.maybe other modules are involved.