Skip to content

KAFKA-16921: Migrate test of connect module to Junit5 (Runtime direct)#16351

Merged
chia7712 merged 26 commits intoapache:trunkfrom
gongxuanzhang:junit5-runtime
Jun 18, 2024
Merged

KAFKA-16921: Migrate test of connect module to Junit5 (Runtime direct)#16351
chia7712 merged 26 commits intoapache:trunkfrom
gongxuanzhang:junit5-runtime

Conversation

@gongxuanzhang
Copy link
Copy Markdown
Contributor

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.

gongxuanzhang and others added 9 commits June 14, 2024 17:52
# 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
Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please use @ValueSource(booleans = {true, false}) instead? that is more readable to me

@Test
public void testStartPaused() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@Test
public void testPause() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@Test
public void testFailureInPreProducerCheck() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto


@Test
public void testFailureInProducerInitialization() throws Exception {
@ParameterizedTest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@Test
public void testTransitionStartedToStarted() {
@ParameterizedTest
@MethodSource("parameters")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@gongxuanzhang
Copy link
Copy Markdown
Contributor Author

@chia7712 I update it

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@gongxuanzhang thanks for updated PR

private boolean enableTopicCreation;

@Parameterized.Parameters
public static Collection<Boolean> parameters() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is unused now, right?

public static Collection<Boolean> parameters() {
return Arrays.asList(false, true);

public static Stream<Boolean> parameters() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

private ConnectorOffsetBackingStore offsetStore;

@Parameterized.Parameters
public static Collection<ConnectorType> parameters() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@gongxuanzhang
Copy link
Copy Markdown
Contributor Author

plz take a look @chia7712

@chia7712
Copy link
Copy Markdown
Member

@gongxuanzhang please fix those failed tests

@gongxuanzhang
Copy link
Copy Markdown
Contributor Author

I have fixed all the test cases that failed due to the changes.
@chia7712

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should remove this, and each test case should call expectTopicCreation when enableTopicCreation=true

@gongxuanzhang
Copy link
Copy Markdown
Contributor Author

I update it. plz take a look @chia7712

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

@chia7712 chia7712 merged commit 3a3f9ce into apache:trunk Jun 18, 2024
TaiJuWu pushed a commit to TaiJuWu/kafka that referenced this pull request Jul 4, 2024
…irect) (apache#16351)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants