mirror of https://github.com/apache/kafka.git
KAFKA-12200: Migrate connect:file module to JUnit 5 (#9917)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Ismael Juma <ismael@juma.me.uk>
This commit is contained in:
parent
87df3b9e7d
commit
962b69b5b3
|
@ -242,7 +242,7 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the relevant project name once it's converted to JUnit 5
|
// Remove the relevant project name once it's converted to JUnit 5
|
||||||
def shouldUseJUnit5 = !(["api", "connect", "core", "file", "generator", "runtime", "examples",
|
def shouldUseJUnit5 = !(["api", "connect", "core", "generator", "runtime", "examples",
|
||||||
"streams-scala", "streams"].contains(it.project.name) || it.project.name.startsWith("upgrade-system-tests-"))
|
"streams-scala", "streams"].contains(it.project.name) || it.project.name.startsWith("upgrade-system-tests-"))
|
||||||
|
|
||||||
def testLoggingEvents = ["passed", "skipped", "failed"]
|
def testLoggingEvents = ["passed", "skipped", "failed"]
|
||||||
|
@ -2075,10 +2075,7 @@ project(':connect:file') {
|
||||||
compile libs.slf4jApi
|
compile libs.slf4jApi
|
||||||
|
|
||||||
testCompile libs.easymock
|
testCompile libs.easymock
|
||||||
testCompile libs.junitJupiterApi
|
testCompile libs.junitJupiter
|
||||||
testCompile libs.junitVintageEngine
|
|
||||||
testCompile libs.powermockJunit4
|
|
||||||
testCompile libs.powermockEasymock
|
|
||||||
|
|
||||||
testRuntime libs.slf4jlog4j
|
testRuntime libs.slf4jlog4j
|
||||||
testCompile project(':clients').sourceSets.test.output
|
testCompile project(':clients').sourceSets.test.output
|
||||||
|
|
|
@ -20,16 +20,16 @@ import org.apache.kafka.common.config.ConfigValue;
|
||||||
import org.apache.kafka.connect.connector.ConnectorContext;
|
import org.apache.kafka.connect.connector.ConnectorContext;
|
||||||
import org.apache.kafka.connect.sink.SinkConnector;
|
import org.apache.kafka.connect.sink.SinkConnector;
|
||||||
import org.easymock.EasyMockSupport;
|
import org.easymock.EasyMockSupport;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
public class FileStreamSinkConnectorTest extends EasyMockSupport {
|
public class FileStreamSinkConnectorTest extends EasyMockSupport {
|
||||||
|
|
||||||
private static final String MULTIPLE_TOPICS = "test1,test2";
|
private static final String MULTIPLE_TOPICS = "test1,test2";
|
||||||
|
@ -39,7 +39,7 @@ public class FileStreamSinkConnectorTest extends EasyMockSupport {
|
||||||
private ConnectorContext ctx;
|
private ConnectorContext ctx;
|
||||||
private Map<String, String> sinkProperties;
|
private Map<String, String> sinkProperties;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
connector = new FileStreamSinkConnector();
|
connector = new FileStreamSinkConnector();
|
||||||
ctx = createMock(ConnectorContext.class);
|
ctx = createMock(ConnectorContext.class);
|
||||||
|
@ -55,7 +55,7 @@ public class FileStreamSinkConnectorTest extends EasyMockSupport {
|
||||||
replayAll();
|
replayAll();
|
||||||
List<ConfigValue> configValues = connector.config().validate(sinkProperties);
|
List<ConfigValue> configValues = connector.config().validate(sinkProperties);
|
||||||
for (ConfigValue val : configValues) {
|
for (ConfigValue val : configValues) {
|
||||||
assertEquals("Config property errors: " + val.errorMessages(), 0, val.errorMessages().size());
|
assertEquals(0, val.errorMessages().size(), "Config property errors: " + val.errorMessages());
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,24 +20,21 @@ import org.apache.kafka.clients.consumer.OffsetAndMetadata;
|
||||||
import org.apache.kafka.common.TopicPartition;
|
import org.apache.kafka.common.TopicPartition;
|
||||||
import org.apache.kafka.connect.data.Schema;
|
import org.apache.kafka.connect.data.Schema;
|
||||||
import org.apache.kafka.connect.sink.SinkRecord;
|
import org.apache.kafka.connect.sink.SinkRecord;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class FileStreamSinkTaskTest {
|
public class FileStreamSinkTaskTest {
|
||||||
|
|
||||||
|
@ -45,17 +42,16 @@ public class FileStreamSinkTaskTest {
|
||||||
private ByteArrayOutputStream os;
|
private ByteArrayOutputStream os;
|
||||||
private PrintStream printStream;
|
private PrintStream printStream;
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public TemporaryFolder topDir = new TemporaryFolder();
|
public Path topDir;
|
||||||
private String outputFile;
|
private String outputFile;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
os = new ByteArrayOutputStream();
|
os = new ByteArrayOutputStream();
|
||||||
printStream = new PrintStream(os);
|
printStream = new PrintStream(os);
|
||||||
task = new FileStreamSinkTask(printStream);
|
task = new FileStreamSinkTask(printStream);
|
||||||
File outputDir = topDir.newFolder("file-stream-sink-" + UUID.randomUUID().toString());
|
outputFile = topDir.resolve("connect.output").toAbsolutePath().toString();
|
||||||
outputFile = outputDir.getCanonicalPath() + "/connect.output";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -21,17 +21,17 @@ import org.apache.kafka.common.config.ConfigValue;
|
||||||
import org.apache.kafka.connect.connector.ConnectorContext;
|
import org.apache.kafka.connect.connector.ConnectorContext;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.easymock.EasyMockSupport;
|
import org.easymock.EasyMockSupport;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThrows;
|
|
||||||
|
|
||||||
public class FileStreamSourceConnectorTest extends EasyMockSupport {
|
public class FileStreamSourceConnectorTest extends EasyMockSupport {
|
||||||
|
|
||||||
private static final String SINGLE_TOPIC = "test";
|
private static final String SINGLE_TOPIC = "test";
|
||||||
|
@ -42,7 +42,7 @@ public class FileStreamSourceConnectorTest extends EasyMockSupport {
|
||||||
private ConnectorContext ctx;
|
private ConnectorContext ctx;
|
||||||
private Map<String, String> sourceProperties;
|
private Map<String, String> sourceProperties;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
connector = new FileStreamSourceConnector();
|
connector = new FileStreamSourceConnector();
|
||||||
ctx = createMock(ConnectorContext.class);
|
ctx = createMock(ConnectorContext.class);
|
||||||
|
@ -58,7 +58,7 @@ public class FileStreamSourceConnectorTest extends EasyMockSupport {
|
||||||
replayAll();
|
replayAll();
|
||||||
List<ConfigValue> configValues = connector.config().validate(sourceProperties);
|
List<ConfigValue> configValues = connector.config().validate(sourceProperties);
|
||||||
for (ConfigValue val : configValues) {
|
for (ConfigValue val : configValues) {
|
||||||
assertEquals("Config property errors: " + val.errorMessages(), 0, val.errorMessages().size());
|
assertEquals(0, val.errorMessages().size(), "Config property errors: " + val.errorMessages());
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ import org.apache.kafka.connect.source.SourceTaskContext;
|
||||||
import org.apache.kafka.connect.storage.OffsetStorageReader;
|
import org.apache.kafka.connect.storage.OffsetStorageReader;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.easymock.EasyMockSupport;
|
import org.easymock.EasyMockSupport;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -36,8 +36,8 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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 FileStreamSourceTaskTest extends EasyMockSupport {
|
public class FileStreamSourceTaskTest extends EasyMockSupport {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class FileStreamSourceTaskTest extends EasyMockSupport {
|
||||||
|
|
||||||
private boolean verifyMocks = false;
|
private boolean verifyMocks = false;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
tempFile = File.createTempFile("file-stream-source-task-test", null);
|
tempFile = File.createTempFile("file-stream-source-task-test", null);
|
||||||
config = new HashMap<>();
|
config = new HashMap<>();
|
||||||
|
@ -64,7 +64,7 @@ public class FileStreamSourceTaskTest extends EasyMockSupport {
|
||||||
task.initialize(context);
|
task.initialize(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void teardown() {
|
public void teardown() {
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue