KAFKA-16921 [1/N] Migrate all junit 4 code to junit 5 for connect module (#16253)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Ken Huang 2024-06-13 17:11:37 +09:00 committed by GitHub
parent 596b945072
commit ea60666513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 60 additions and 70 deletions

View File

@ -427,9 +427,6 @@ subprojects {
} }
} }
// Remove the relevant project name once it's converted to JUnit 5
def shouldUseJUnit5 = !(["runtime"].contains(it.project.name))
def testLoggingEvents = ["passed", "skipped", "failed"] def testLoggingEvents = ["passed", "skipped", "failed"]
def testShowStandardStreams = false def testShowStandardStreams = false
def testExceptionFormat = 'full' def testExceptionFormat = 'full'
@ -522,8 +519,7 @@ subprojects {
exclude testsToExclude exclude testsToExclude
if (shouldUseJUnit5) useJUnitPlatform()
useJUnitPlatform()
retry { retry {
maxRetries = userMaxTestRetries maxRetries = userMaxTestRetries
@ -550,23 +546,18 @@ subprojects {
exclude testsToExclude exclude testsToExclude
if (shouldUseJUnit5) { if (project.name == 'streams') {
if (project.name == 'streams') { useJUnitPlatform {
useJUnitPlatform { includeTags "integration"
includeTags "integration" includeTags "org.apache.kafka.test.IntegrationTest"
includeTags "org.apache.kafka.test.IntegrationTest" // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests.
// Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete.
// junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. includeEngines "junit-vintage", "junit-jupiter"
includeEngines "junit-vintage", "junit-jupiter"
}
} else {
useJUnitPlatform {
includeTags "integration"
}
} }
} else { } else {
useJUnit { useJUnitPlatform {
includeCategories 'org.apache.kafka.test.IntegrationTest' includeTags "integration"
includeTags 'org.apache.kafka.test.IntegrationTest'
} }
} }
@ -593,23 +584,18 @@ subprojects {
exclude testsToExclude exclude testsToExclude
if (shouldUseJUnit5) { if (project.name == 'streams') {
if (project.name == 'streams') { useJUnitPlatform {
useJUnitPlatform { excludeTags "integration"
excludeTags "integration" excludeTags "org.apache.kafka.test.IntegrationTest"
excludeTags "org.apache.kafka.test.IntegrationTest" // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests.
// Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete.
// junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. includeEngines "junit-vintage", "junit-jupiter"
includeEngines "junit-vintage", "junit-jupiter"
}
} else {
useJUnitPlatform {
excludeTags "integration"
}
} }
} else { } else {
useJUnit { useJUnitPlatform {
excludeCategories 'org.apache.kafka.test.IntegrationTest' excludeTags "integration"
excludeTags 'org.apache.kafka.test.IntegrationTest'
} }
} }
@ -3229,10 +3215,13 @@ project(':connect:runtime') {
testImplementation project(':storage') testImplementation project(':storage')
testImplementation project(':connect:test-plugins') testImplementation project(':connect:test-plugins')
testImplementation project(':group-coordinator') testImplementation project(':group-coordinator')
testImplementation libs.junitJupiterApi testImplementation libs.junitJupiter
testImplementation libs.junitVintageEngine testImplementation libs.junitVintageEngine
testImplementation libs.mockitoJunitJupiter
testImplementation libs.mockitoCore testImplementation libs.mockitoCore
testImplementation libs.hamcrest
testImplementation libs.mockitoJunitJupiter
testImplementation libs.httpclient testImplementation libs.httpclient
testRuntimeOnly libs.slf4jlog4j testRuntimeOnly libs.slf4jlog4j

View File

@ -19,8 +19,8 @@ package org.apache.kafka.connect.cli;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest; import org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest;
import org.apache.kafka.test.TestUtils; import org.apache.kafka.test.TestUtils;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -30,8 +30,8 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static org.apache.kafka.connect.runtime.ConnectorConfig.NAME_CONFIG; import static org.apache.kafka.connect.runtime.ConnectorConfig.NAME_CONFIG;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
public class ConnectStandaloneTest { public class ConnectStandaloneTest {
@ -46,7 +46,7 @@ public class ConnectStandaloneTest {
private final ConnectStandalone connectStandalone = new ConnectStandalone(); private final ConnectStandalone connectStandalone = new ConnectStandalone();
private File connectorConfigurationFile; private File connectorConfigurationFile;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
connectorConfigurationFile = TestUtils.tempFile(); connectorConfigurationFile = TestUtils.tempFile();
} }

View File

@ -20,11 +20,12 @@ package org.apache.kafka.connect.connector.policy;
import org.apache.kafka.common.config.ConfigValue; import org.apache.kafka.common.config.ConfigValue;
import org.apache.kafka.connect.health.ConnectorType; import org.apache.kafka.connect.health.ConnectorType;
import org.apache.kafka.connect.runtime.SampleSourceConnector; import org.apache.kafka.connect.runtime.SampleSourceConnector;
import org.junit.Assert;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class BaseConnectorClientConfigOverridePolicyTest { public abstract class BaseConnectorClientConfigOverridePolicyTest {
protected abstract ConnectorClientConfigOverridePolicy policyToTest(); protected abstract ConnectorClientConfigOverridePolicy policyToTest();
@ -50,10 +51,10 @@ public abstract class BaseConnectorClientConfigOverridePolicyTest {
} }
protected void assertNoError(List<ConfigValue> configValues) { protected void assertNoError(List<ConfigValue> configValues) {
Assert.assertTrue(configValues.stream().allMatch(configValue -> configValue.errorMessages().isEmpty())); assertTrue(configValues.stream().allMatch(configValue -> configValue.errorMessages().isEmpty()));
} }
protected void assertError(List<ConfigValue> configValues) { protected void assertError(List<ConfigValue> configValues) {
Assert.assertTrue(configValues.stream().anyMatch(configValue -> !configValue.errorMessages().isEmpty())); assertTrue(configValues.stream().anyMatch(configValue -> !configValue.errorMessages().isEmpty()));
} }
} }

View File

@ -19,7 +19,7 @@ package org.apache.kafka.connect.connector.policy;
import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.config.SaslConfigs; import org.apache.kafka.common.config.SaslConfigs;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -19,7 +19,7 @@ package org.apache.kafka.connect.connector.policy;
import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.config.SaslConfigs; import org.apache.kafka.common.config.SaslConfigs;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -17,12 +17,12 @@
package org.apache.kafka.connect.converters; package org.apache.kafka.connect.converters;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
@ -30,8 +30,8 @@ import java.util.Collections;
import org.apache.kafka.common.utils.AppInfoParser; import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.errors.DataException; import org.apache.kafka.connect.errors.DataException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BooleanConverterTest { public class BooleanConverterTest {
private static final String TOPIC = "topic"; private static final String TOPIC = "topic";
@ -39,7 +39,7 @@ public class BooleanConverterTest {
private static final byte[] FALSE = new byte[] {0x00}; private static final byte[] FALSE = new byte[] {0x00};
private final BooleanConverter converter = new BooleanConverter(); private final BooleanConverter converter = new BooleanConverter();
@Before @BeforeEach
public void setUp() { public void setUp() {
converter.configure(Collections.emptyMap(), false); converter.configure(Collections.emptyMap(), false);
} }

View File

@ -21,17 +21,17 @@ import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.SchemaAndValue; import org.apache.kafka.connect.data.SchemaAndValue;
import org.apache.kafka.connect.errors.DataException; import org.apache.kafka.connect.errors.DataException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
public class ByteArrayConverterTest { public class ByteArrayConverterTest {
private static final String TOPIC = "topic"; private static final String TOPIC = "topic";
@ -39,7 +39,7 @@ public class ByteArrayConverterTest {
private final ByteArrayConverter converter = new ByteArrayConverter(); private final ByteArrayConverter converter = new ByteArrayConverter();
@Before @BeforeEach
public void setUp() { public void setUp() {
converter.configure(Collections.emptyMap(), false); converter.configure(Collections.emptyMap(), false);
} }

View File

@ -21,13 +21,13 @@ import org.apache.kafka.common.utils.AppInfoParser;
import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.SchemaAndValue; import org.apache.kafka.connect.data.SchemaAndValue;
import org.apache.kafka.connect.errors.DataException; import org.apache.kafka.connect.errors.DataException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
public abstract class NumberConverterTest<T extends Number> { public abstract class NumberConverterTest<T extends Number> {
private static final String TOPIC = "topic"; private static final String TOPIC = "topic";
@ -46,7 +46,7 @@ public abstract class NumberConverterTest<T extends Number> {
protected abstract Schema schema(); protected abstract Schema schema();
@Before @BeforeEach
public void setup() { public void setup() {
converter = createConverter(); converter = createConverter();
serializer = createSerializer(); serializer = createSerializer();