From 870b315d4b766a671cd5e478e5b9776beb00ff59 Mon Sep 17 00:00:00 2001 From: Hyunseok Seo Date: Fri, 14 Jun 2024 09:48:38 +0900 Subject: [PATCH] GH-42030: [Java] Update Unit Tests for Adapter Module (#42038) ### Rationale for this change Update package from JUnit 4(`org.junit`) to JUnit 5(`org.junit.jupiter`). ### What changes are included in this PR? - `avro` and `jdbc` module - [x] Replacing `org.junit` with `org.junit.jupiter.api`. - [x] Updating `Assertions.assertXXX` to `assertXXX` using static imports. - [x] Updating annotations such as `@ Before`, `@ After`. - `@ Before` -> `@ BeforeEach` - `@ After` -> `@ AfterEach` - `@ Test` -> `@ Test` with `org.junit.jupiter` - `@ ClassRule` -> `@ TempDir` and `@ BeforeAll` - [x] Updating `Parameterized` test - [x] Doing self review for avro - [x] Dealing with `java.io.IOException: Failed to delete temp directory` on Windows with JDK 11 - [x] Exploring a more effective structure for `ParameterizedTest` in JDBC tests. - [x] Doing self review for jdbc - `orc` module - [x] Reviewing the build method - [x] Updating annotations such as `@ BeforeAll`, `@ Rule`, `@ TemporaryFolder` - [x] Doing self review ### Are these changes tested? Yes, existing tests have passed. ### Are there any user-facing changes? No. * GitHub Issue: #42030 Authored-by: Hyunseok Seo Signed-off-by: David Li --- .../adapter/avro/AvroLogicalTypesTest.java | 2 +- .../arrow/adapter/avro/AvroSkipFieldTest.java | 4 +- .../arrow/adapter/avro/AvroTestBase.java | 37 ++++----- .../adapter/avro/AvroToArrowIteratorTest.java | 52 ++++++++---- .../arrow/adapter/avro/AvroToArrowTest.java | 4 +- .../adapter/avro/TestWriteReadAvroRecord.java | 34 ++++---- .../adapter/jdbc/AbstractJdbcToArrowTest.java | 16 ++-- .../arrow/adapter/jdbc/JdbcFieldInfoTest.java | 4 +- .../jdbc/JdbcToArrowCommentMetadataTest.java | 10 +-- .../adapter/jdbc/JdbcToArrowConfigTest.java | 55 +++++++++---- .../adapter/jdbc/JdbcToArrowTestHelper.java | 8 +- .../adapter/jdbc/ResultSetUtilityTest.java | 20 ++--- .../adapter/jdbc/UnreliableMetaDataTest.java | 81 +++++++++---------- .../jdbc/consumer/AbstractConsumerTest.java | 8 +- .../jdbc/consumer/BinaryConsumerTest.java | 8 +- .../adapter/jdbc/h2/JdbcAliasToArrowTest.java | 12 +-- .../adapter/jdbc/h2/JdbcToArrowArrayTest.java | 16 ++-- .../jdbc/h2/JdbcToArrowCharSetTest.java | 51 +++++------- .../jdbc/h2/JdbcToArrowDataTypesTest.java | 41 +++++----- .../jdbc/h2/JdbcToArrowMapDataTypeTest.java | 20 +++-- .../adapter/jdbc/h2/JdbcToArrowNullTest.java | 40 ++++----- .../h2/JdbcToArrowOptionalColumnsTest.java | 35 ++++---- .../adapter/jdbc/h2/JdbcToArrowTest.java | 53 ++++++------ .../jdbc/h2/JdbcToArrowTimeZoneTest.java | 41 +++++----- .../h2/JdbcToArrowVectorIteratorTest.java | 64 ++++++++------- .../arrow/adapter/orc/OrcReaderTest.java | 19 +++-- 26 files changed, 373 insertions(+), 362 deletions(-) diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java index d8eefc715f611..b114f2b00c9fa 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java @@ -32,7 +32,7 @@ import org.apache.avro.Conversions; import org.apache.avro.Schema; import org.apache.avro.generic.GenericFixed; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AvroLogicalTypesTest extends AvroTestBase { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java index 3335ee5a8f6dc..3120c26638c6d 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java @@ -16,7 +16,7 @@ */ package org.apache.arrow.adapter.avro; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -31,7 +31,7 @@ import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AvroSkipFieldTest extends AvroTestBase { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java index 534c2cc18c572..44c4186c52d9e 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java @@ -16,9 +16,9 @@ */ package org.apache.arrow.adapter.avro; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileInputStream; @@ -43,17 +43,16 @@ import org.apache.avro.io.DatumWriter; import org.apache.avro.io.DecoderFactory; import org.apache.avro.io.EncoderFactory; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; public class AvroTestBase { - @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); + @TempDir public File TMP; protected AvroToArrowConfig config; - @Before + @BeforeEach public void init() { BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); config = new AvroToArrowConfigBuilder(allocator).build(); @@ -82,19 +81,21 @@ public static Schema getSchema(String schemaName) throws Exception { } protected VectorSchemaRoot writeAndRead(Schema schema, List data) throws Exception { - File dataFile = TMP.newFile(); + File dataFile = new File(TMP, "test.avro"); - BinaryEncoder encoder = - new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); - DatumWriter writer = new GenericDatumWriter(schema); - BinaryDecoder decoder = - new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); + try (FileOutputStream fos = new FileOutputStream(dataFile); + FileInputStream fis = new FileInputStream(dataFile)) { - for (Object value : data) { - writer.write(value, encoder); - } + BinaryEncoder encoder = new EncoderFactory().directBinaryEncoder(fos, null); + DatumWriter writer = new GenericDatumWriter<>(schema); + BinaryDecoder decoder = new DecoderFactory().directBinaryDecoder(fis, null); + + for (Object value : data) { + writer.write(value, encoder); + } - return AvroToArrow.avroToArrow(schema, decoder, config); + return AvroToArrow.avroToArrow(schema, decoder, config); + } } protected void checkArrayResult(List> expected, ListVector vector) { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java index 7e73b2d6c7038..f8022a9385134 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java @@ -16,7 +16,7 @@ */ package org.apache.arrow.adapter.avro; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.EOFException; import java.io.File; @@ -44,29 +44,31 @@ import org.apache.avro.io.DecoderFactory; import org.apache.avro.io.EncoderFactory; import org.apache.avro.util.Utf8; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AvroToArrowIteratorTest extends AvroTestBase { - @Override + @BeforeEach public void init() { final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); this.config = new AvroToArrowConfigBuilder(allocator).setTargetBatchSize(3).build(); } - private AvroToArrowVectorIterator convert(Schema schema, List data) throws Exception { - File dataFile = TMP.newFile(); + private void writeDataToFile(Schema schema, List data, File dataFile) throws Exception { + try (FileOutputStream fos = new FileOutputStream(dataFile)) { + BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder(fos, null); + DatumWriter writer = new GenericDatumWriter<>(schema); - BinaryEncoder encoder = - new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); - DatumWriter writer = new GenericDatumWriter(schema); - BinaryDecoder decoder = - new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); - - for (Object value : data) { - writer.write(value, encoder); + for (Object value : data) { + writer.write(value, encoder); + } + encoder.flush(); } + } + private AvroToArrowVectorIterator convert(Schema schema, FileInputStream fis) throws Exception { + BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(fis, null); return AvroToArrow.avroToArrowIterator(schema, decoder, config); } @@ -75,9 +77,13 @@ public void testStringType() throws Exception { Schema schema = getSchema("test_primitive_string.avsc"); List data = Arrays.asList("v1", "v2", "v3", "v4", "v5"); + File dataFile = new File(TMP, "test.avro"); + writeDataToFile(schema, data, dataFile); + List roots = new ArrayList<>(); List vectors = new ArrayList<>(); - try (AvroToArrowVectorIterator iterator = convert(schema, data)) { + try (FileInputStream fis = new FileInputStream(dataFile); + AvroToArrowVectorIterator iterator = convert(schema, fis)) { while (iterator.hasNext()) { VectorSchemaRoot root = iterator.next(); FieldVector vector = root.getFieldVectors().get(0); @@ -103,9 +109,13 @@ public void testNullableStringType() throws Exception { data.add(record); } + File dataFile = new File(TMP, "test.avro"); + writeDataToFile(schema, data, dataFile); + List roots = new ArrayList<>(); List vectors = new ArrayList<>(); - try (AvroToArrowVectorIterator iterator = convert(schema, data); ) { + try (FileInputStream fis = new FileInputStream(dataFile); + AvroToArrowVectorIterator iterator = convert(schema, fis)) { while (iterator.hasNext()) { VectorSchemaRoot root = iterator.next(); FieldVector vector = root.getFieldVectors().get(0); @@ -129,8 +139,12 @@ public void testRecordType() throws Exception { data.add(record); } + File dataFile = new File(TMP, "test.avro"); + writeDataToFile(schema, data, dataFile); + List roots = new ArrayList<>(); - try (AvroToArrowVectorIterator iterator = convert(schema, data)) { + try (FileInputStream fis = new FileInputStream(dataFile); + AvroToArrowVectorIterator iterator = convert(schema, fis)) { while (iterator.hasNext()) { roots.add(iterator.next()); } @@ -150,9 +164,13 @@ public void testArrayType() throws Exception { Arrays.asList("1vvv", "2bbb"), Arrays.asList("1fff", "2")); + File dataFile = new File(TMP, "test.avro"); + writeDataToFile(schema, data, dataFile); + List roots = new ArrayList<>(); List vectors = new ArrayList<>(); - try (AvroToArrowVectorIterator iterator = convert(schema, data)) { + try (FileInputStream fis = new FileInputStream(dataFile); + AvroToArrowVectorIterator iterator = convert(schema, fis)) { while (iterator.hasNext()) { VectorSchemaRoot root = iterator.next(); roots.add(root); diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java index 59317c3be033f..899ea40301322 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java @@ -16,7 +16,7 @@ */ package org.apache.arrow.adapter.avro; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -34,7 +34,7 @@ import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AvroToArrowTest extends AvroTestBase { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java index a721a1e4cc6a8..c318214f5c0a7 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java @@ -16,7 +16,7 @@ */ package org.apache.arrow.adapter.avro; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.util.ArrayList; @@ -30,18 +30,16 @@ import org.apache.avro.generic.GenericRecord; import org.apache.avro.io.DatumReader; import org.apache.avro.io.DatumWriter; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class TestWriteReadAvroRecord { - @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); + @TempDir public static File TMP; @Test public void testWriteAndRead() throws Exception { - - File dataFile = TMP.newFile(); + File dataFile = new File(TMP, "test.avro"); Schema schema = AvroTestBase.getSchema("test.avsc"); // write data to disk @@ -55,20 +53,22 @@ public void testWriteAndRead() throws Exception { user2.put("favorite_color", "red"); DatumWriter datumWriter = new GenericDatumWriter(schema); - DataFileWriter dataFileWriter = new DataFileWriter(datumWriter); - dataFileWriter.create(schema, dataFile); - dataFileWriter.append(user1); - dataFileWriter.append(user2); - dataFileWriter.close(); + try (DataFileWriter dataFileWriter = + new DataFileWriter(datumWriter)) { + dataFileWriter.create(schema, dataFile); + dataFileWriter.append(user1); + dataFileWriter.append(user2); + } // read data from disk DatumReader datumReader = new GenericDatumReader(schema); - DataFileReader dataFileReader = - new DataFileReader(dataFile, datumReader); List result = new ArrayList<>(); - while (dataFileReader.hasNext()) { - GenericRecord user = dataFileReader.next(); - result.add(user); + try (DataFileReader dataFileReader = + new DataFileReader(dataFile, datumReader)) { + while (dataFileReader.hasNext()) { + GenericRecord user = dataFileReader.next(); + result.add(user); + } } assertEquals(2, result.size()); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java index 1ad4492b35d18..a37a8ca2f5990 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java @@ -37,9 +37,7 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.util.ValueVectorUtility; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; /** Class to abstract out some common test functionality for testing JDBC to Arrow. */ public abstract class AbstractJdbcToArrowTest { @@ -94,8 +92,9 @@ protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes" * @throws SQLException on error * @throws ClassNotFoundException on error */ - @Before - public void setUp() throws SQLException, ClassNotFoundException { + protected void initializeDatabase(Table table) throws SQLException, ClassNotFoundException { + this.table = table; + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); String url = "jdbc:h2:mem:JdbcToArrowTest"; String driver = "org.h2.Driver"; @@ -114,7 +113,7 @@ public void setUp() throws SQLException, ClassNotFoundException { * * @throws SQLException on error */ - @After + @AfterEach public void destroy() throws SQLException { if (conn != null) { conn.close(); @@ -146,11 +145,12 @@ public static Object[][] prepareTestData( /** * Abstract method to implement test Functionality to test JdbcToArrow methods. * + * @param table Table object * @throws SQLException on error * @throws IOException on error */ - @Test - public abstract void testJdbcToArrowValues() throws SQLException, IOException; + public abstract void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException; /** * Abstract method to implement logic to assert test various datatype values. diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java index cd6a78eae2b1a..152b88c45a865 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java @@ -16,10 +16,10 @@ */ package org.apache.arrow.adapter.jdbc; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.Types; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JdbcFieldInfoTest { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowCommentMetadataTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowCommentMetadataTest.java index a3ff8d9772d0b..e7e324c7847f4 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowCommentMetadataTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowCommentMetadataTest.java @@ -37,9 +37,9 @@ import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class JdbcToArrowCommentMetadataTest { @@ -53,7 +53,7 @@ public class JdbcToArrowCommentMetadataTest { * @throws SQLException on error * @throws ClassNotFoundException on error */ - @Before + @BeforeEach public void setUp() throws SQLException, ClassNotFoundException { String url = "jdbc:h2:mem:JdbcToArrowTest?characterEncoding=UTF-8;INIT=runscript from 'classpath:/h2/comment.sql'"; @@ -62,7 +62,7 @@ public void setUp() throws SQLException, ClassNotFoundException { conn = DriverManager.getConnection(url); } - @After + @AfterEach public void tearDown() throws SQLException { if (conn != null) { conn.close(); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java index 85d6d89d036ff..70c753cf2f8ba 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java @@ -16,11 +16,12 @@ */ package org.apache.arrow.adapter.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Types; import java.util.Calendar; @@ -29,7 +30,7 @@ import java.util.TimeZone; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JdbcToArrowConfigTest { @@ -37,14 +38,22 @@ public class JdbcToArrowConfigTest { private static final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT); - @Test(expected = NullPointerException.class) + @Test public void testConfigNullArguments() { - new JdbcToArrowConfig(null, null); + assertThrows( + NullPointerException.class, + () -> { + new JdbcToArrowConfig(null, null); + }); } - @Test(expected = NullPointerException.class) + @Test public void testBuilderNullArguments() { - new JdbcToArrowConfigBuilder(null, null); + assertThrows( + NullPointerException.class, + () -> { + new JdbcToArrowConfigBuilder(null, null); + }); } @Test @@ -60,20 +69,32 @@ public void testBuilderNullCalendar() { assertNull(config.getCalendar()); } - @Test(expected = NullPointerException.class) + @Test public void testConfigNullAllocator() { - new JdbcToArrowConfig(null, calendar); + assertThrows( + NullPointerException.class, + () -> { + new JdbcToArrowConfig(null, calendar); + }); } - @Test(expected = NullPointerException.class) + @Test public void testBuilderNullAllocator() { - new JdbcToArrowConfigBuilder(null, calendar); + assertThrows( + NullPointerException.class, + () -> { + new JdbcToArrowConfigBuilder(null, calendar); + }); } - @Test(expected = NullPointerException.class) + @Test public void testSetNullAllocator() { - JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar); - builder.setAllocator(null); + assertThrows( + NullPointerException.class, + () -> { + JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar); + builder.setAllocator(null); + }); } @Test diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java index 375463d6fd5d4..74b1ca34d73c6 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java @@ -16,10 +16,10 @@ */ package org.apache.arrow.adapter.jdbc; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java index 8af2c06f4de54..c7dc9b2791ce0 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java @@ -16,11 +16,11 @@ */ package org.apache.arrow.adapter.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.ResultSet; import java.sql.SQLException; @@ -28,7 +28,7 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VectorSchemaRoot; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Tests of the ResultSetUtility. */ public class ResultSetUtilityTest { @@ -44,14 +44,14 @@ public void testZeroRowResultSet() throws Exception { .build(); ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config); - assertTrue("Iterator on zero row ResultSet should haveNext() before use", iter.hasNext()); + assertTrue(iter.hasNext(), "Iterator on zero row ResultSet should haveNext() before use"); VectorSchemaRoot root = iter.next(); - assertNotNull("VectorSchemaRoot from first next() result should never be null", root); + assertNotNull(root, "VectorSchemaRoot from first next() result should never be null"); assertEquals( - "VectorSchemaRoot from empty ResultSet should have zero rows", 0, root.getRowCount()); + 0, root.getRowCount(), "VectorSchemaRoot from empty ResultSet should have zero rows"); assertFalse( - "hasNext() should return false on empty ResultSets after initial next() call", - iter.hasNext()); + iter.hasNext(), + "hasNext() should return false on empty ResultSets after initial next() call"); } } } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java index 93ba028e39629..4993a8b1aeec5 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java @@ -16,10 +16,10 @@ */ package org.apache.arrow.adapter.jdbc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.math.RoundingMode; @@ -29,10 +29,10 @@ import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Stream; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.IntVector; @@ -40,50 +40,45 @@ import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** Test options for dealing with unreliable ResultSetMetaData from JDBC drivers. */ -@RunWith(Parameterized.class) public class UnreliableMetaDataTest { - private final boolean reuseVectorSchemaRoot; private BufferAllocator allocator; - public UnreliableMetaDataTest(boolean reuseVectorSchemaRoot) { - this.reuseVectorSchemaRoot = reuseVectorSchemaRoot; - } - - @Before + @BeforeEach public void beforeEach() { allocator = new RootAllocator(); } - @After + @AfterEach public void afterEach() { allocator.close(); } - @Parameterized.Parameters(name = "reuseVectorSchemaRoot = {0}") - public static Collection getTestData() { - return Arrays.asList(new Object[][] {{false}, {true}}); + public static Stream getTestData() { + return Arrays.stream(new Object[][] {{false}, {true}}).map(Arguments::of); } - @Test - public void testUnreliableMetaDataPrecisionAndScale() throws Exception { + @ParameterizedTest + @MethodSource("getTestData") + public void testUnreliableMetaDataPrecisionAndScale(boolean reuseVectorSchemaRoot) + throws Exception { ResultSet rs = buildIncorrectPrecisionAndScaleMetaDataResultSet(); ResultSetMetaData rsmd = rs.getMetaData(); - assertEquals("Column type should be Types.DECIMAL", Types.DECIMAL, rsmd.getColumnType(1)); - assertEquals("Column scale should be zero", 0, rsmd.getScale(1)); - assertEquals("Column precision should be zero", 0, rsmd.getPrecision(1)); + assertEquals(Types.DECIMAL, rsmd.getColumnType(1), "Column type should be Types.DECIMAL"); + assertEquals(0, rsmd.getScale(1), "Column scale should be zero"); + assertEquals(0, rsmd.getPrecision(1), "Column precision should be zero"); rs.next(); BigDecimal bd1 = rs.getBigDecimal(1); - assertEquals("Value should be 1000000000000000.01", new BigDecimal("1000000000000000.01"), bd1); - assertEquals("Value scale should be 2", 2, bd1.scale()); - assertEquals("Value precision should be 18", 18, bd1.precision()); - assertFalse("No more rows!", rs.next()); + assertEquals(new BigDecimal("1000000000000000.01"), bd1, "Value should be 1000000000000000.01"); + assertEquals(2, bd1.scale(), "Value scale should be 2"); + assertEquals(18, bd1.precision(), "Value precision should be 18"); + assertFalse(rs.next(), "No more rows!"); // reset the ResultSet: rs.beforeFirst(); @@ -118,24 +113,25 @@ public void testUnreliableMetaDataPrecisionAndScale() throws Exception { } } - @Test - public void testInconsistentPrecisionAndScale() throws Exception { + @ParameterizedTest + @MethodSource("getTestData") + public void testInconsistentPrecisionAndScale(boolean reuseVectorSchemaRoot) throws Exception { ResultSet rs = buildVaryingPrecisionAndScaleResultSet(); ResultSetMetaData rsmd = rs.getMetaData(); - assertEquals("Column type should be Types.DECIMAL", Types.DECIMAL, rsmd.getColumnType(1)); - assertEquals("Column scale should be zero", 0, rsmd.getScale(1)); - assertEquals("Column precision should be zero", 0, rsmd.getPrecision(1)); + assertEquals(Types.DECIMAL, rsmd.getColumnType(1), "Column type should be Types.DECIMAL"); + assertEquals(0, rsmd.getScale(1), "Column scale should be zero"); + assertEquals(0, rsmd.getPrecision(1), "Column precision should be zero"); rs.next(); BigDecimal bd1 = rs.getBigDecimal(1); - assertEquals("Value should be 1000000000000000.01", new BigDecimal("1000000000000000.01"), bd1); - assertEquals("Value scale should be 2", 2, bd1.scale()); - assertEquals("Value precision should be 18", 18, bd1.precision()); + assertEquals(new BigDecimal("1000000000000000.01"), bd1, "Value should be 1000000000000000.01"); + assertEquals(2, bd1.scale(), "Value scale should be 2"); + assertEquals(18, bd1.precision(), "Value precision should be 18"); rs.next(); BigDecimal bd2 = rs.getBigDecimal(1); assertEquals( - "Value should be 1000000000300.0000001", new BigDecimal("1000000000300.0000001"), bd2); - assertEquals("Value scale should be 7", 7, bd2.scale()); - assertEquals("Value precision should be 20", 20, bd2.precision()); + new BigDecimal("1000000000300.0000001"), bd2, "Value should be 1000000000300.0000001"); + assertEquals(7, bd2.scale(), "Value scale should be 7"); + assertEquals(20, bd2.precision(), "Value precision should be 20"); rs.beforeFirst(); JdbcFieldInfo explicitMappingField = new JdbcFieldInfo(Types.DECIMAL, 20, 7); Map explicitMapping = new HashMap<>(); @@ -170,8 +166,9 @@ public void testInconsistentPrecisionAndScale() throws Exception { } } - @Test - public void testIncorrectNullability() throws Exception { + @ParameterizedTest + @MethodSource("getTestData") + public void testIncorrectNullability(boolean reuseVectorSchemaRoot) throws Exception { // ARROW-17005: ResultSetMetaData may indicate a field is non-nullable even when there are nulls ResultSetUtility.MockResultSetMetaData.MockColumnMetaData columnMetaData = ResultSetUtility.MockResultSetMetaData.MockColumnMetaData.builder() diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java index 6a25c58fbde7e..157bf5bdec24b 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java @@ -18,19 +18,19 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public abstract class AbstractConsumerTest { protected BufferAllocator allocator; - @Before + @BeforeEach public void setUp() { allocator = new RootAllocator(Long.MAX_VALUE); } - @After + @AfterEach public void tearDown() { allocator.close(); } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java index 255770ecdbf6d..b1e253794d0d4 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java @@ -16,15 +16,15 @@ */ package org.apache.arrow.adapter.jdbc.consumer; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; import org.apache.arrow.vector.BaseValueVector; import org.apache.arrow.vector.VarBinaryVector; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BinaryConsumerTest extends AbstractConsumerTest { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java index e22686e890580..e6ca3ad34c7d9 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java @@ -17,7 +17,7 @@ package org.apache.arrow.adapter.jdbc.h2; import static org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest.sqlToArrow; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.Connection; import java.sql.DriverManager; @@ -31,9 +31,9 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class JdbcAliasToArrowTest { private Connection conn = null; @@ -46,7 +46,7 @@ public class JdbcAliasToArrowTest { private static final String COLUMN_A = "A"; private static final String COLUMN_B = "B"; - @Before + @BeforeEach public void setUp() throws Exception { String url = "jdbc:h2:mem:JdbcAliasToArrowTest"; String driver = "org.h2.Driver"; @@ -110,7 +110,7 @@ public void testJdbcAliasToArrow() throws Exception { } } - @After + @AfterEach public void tearDown() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate(DROP_STATEMENT); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java index 895dab52ca534..23a91fe0e567a 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java @@ -17,9 +17,9 @@ package org.apache.arrow.adapter.jdbc.h2; import static org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest.sqlToArrow; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.nio.charset.StandardCharsets; import java.sql.Array; @@ -44,9 +44,9 @@ import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.ListVector; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class JdbcToArrowArrayTest { private Connection conn = null; @@ -66,7 +66,7 @@ public class JdbcToArrowArrayTest { private static final String FLOAT_ARRAY_FIELD_NAME = "FLOAT_ARRAY"; private static final String STRING_ARRAY_FIELD_NAME = "STRING_ARRAY"; - @Before + @BeforeEach public void setUp() throws Exception { String url = "jdbc:h2:mem:JdbcToArrowTest"; String driver = "org.h2.Driver"; @@ -294,7 +294,7 @@ private void assertStringVectorEquals( } } - @After + @AfterEach public void tearDown() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate(DROP_STATEMENT); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java index 14de2d6dc8f3c..726e1905c4242 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java @@ -27,7 +27,7 @@ import java.sql.Statement; import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -38,17 +38,14 @@ import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with * UTF-8 Charset, including the multi-byte CJK characters for H2 database. */ -@RunWith(Parameterized.class) public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest { private static final String[] testFiles = { @@ -58,24 +55,10 @@ public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest { "h2/test1_charset_kr_h2.yml" }; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table oject - */ - public JdbcToArrowCharSetTest(Table table) { + @Override + public void initializeDatabase(Table table) throws SQLException, ClassNotFoundException { this.table = table; - } - /** - * This method creates Connection object and DB table and also populate data into table for test. - * - * @throws SQLException on error - * @throws ClassNotFoundException on error - */ - @Before - @Override - public void setUp() throws SQLException, ClassNotFoundException { String url = "jdbc:h2:mem:JdbcToArrowTest?characterEncoding=UTF-8"; String driver = "org.h2.Driver"; Class.forName(driver); @@ -96,19 +79,22 @@ public void setUp() throws SQLException, ClassNotFoundException { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameters - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.asList(prepareTestData(testFiles, JdbcToArrowCharSetTest.class)); + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowCharSetTest.class)) + .map(Arguments::of); } /** * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with UTF-8 * Charset, including the multi-byte CJK characters. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets( sqlToArrow( conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), @@ -146,8 +132,11 @@ public void testJdbcToArrowValues() throws SQLException, IOException { false); } - @Test - public void testJdbcSchemaMetadata() throws SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcSchemaMetadata(Table table) throws SQLException, ClassNotFoundException { + this.initializeDatabase(table); + JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build(); ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData(); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java index d7c4be03b3542..5537e1acba2bc 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java @@ -38,7 +38,7 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -63,16 +63,14 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with * various data types for H2 database using multiple test data files. */ -@RunWith(Parameterized.class) public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest { private static final String BIGINT = "big_int"; @@ -117,15 +115,6 @@ public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest { "h2/test1_null_h2.yml" }; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - */ - public JdbcToArrowDataTypesTest(Table table) { - this.table = table; - } - /** * Get the test data as a collection of Table objects for each test iteration. * @@ -134,16 +123,19 @@ public JdbcToArrowDataTypesTest(Table table) { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameters - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.asList(prepareTestData(testFiles, JdbcToArrowDataTypesTest.class)); + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowMapDataTypeTest.class)) + .map(Arguments::of); } /** Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets( sqlToArrow( conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), @@ -183,8 +175,11 @@ public void testJdbcToArrowValues() throws SQLException, IOException { false); } - @Test - public void testJdbcSchemaMetadata() throws SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcSchemaMetadata(Table table) throws SQLException, ClassNotFoundException { + this.initializeDatabase(table); + JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java index 8bb3812637acb..337220a42fbce 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java @@ -23,24 +23,32 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Calendar; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; +import org.apache.arrow.adapter.jdbc.Table; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.MapVector; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** Test MapConsumer with OTHER jdbc type. */ public class JdbcToArrowMapDataTypeTest extends AbstractJdbcToArrowTest { - public JdbcToArrowMapDataTypeTest() throws IOException { - this.table = getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class); + public static Stream getTestData() throws IOException { + return Stream.of( + Arguments.of(getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class))); } /** Test Method to test JdbcToArrow Functionality for Map form Types.OTHER column */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); testDataSets( diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java index 51394764e385c..205b7e16f2f09 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java @@ -49,7 +49,7 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -74,16 +74,14 @@ import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with * null values for H2 database. */ -@RunWith(Parameterized.class) public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest { private static final String NULL = "null"; @@ -96,15 +94,6 @@ public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest { "h2/test1_all_datatypes_selected_null_rows_h2.yml" }; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - */ - public JdbcToArrowNullTest(Table table) { - this.table = table; - } - /** * Get the test data as a collection of Table objects for each test iteration. * @@ -113,19 +102,21 @@ public JdbcToArrowNullTest(Table table) { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameters - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.asList(prepareTestData(testFiles, JdbcToArrowNullTest.class)); + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowNullTest.class)).map(Arguments::of); } /** * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with null * values. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets( sqlToArrow( conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), @@ -169,8 +160,11 @@ public void testJdbcToArrowValues() throws SQLException, IOException { true); } - @Test - public void testJdbcSchemaMetadata() throws SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcSchemaMetadata(Table table) throws SQLException, ClassNotFoundException { + this.initializeDatabase(table); + JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java index 47713d9099da6..f3fbf02910230 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java @@ -17,38 +17,28 @@ package org.apache.arrow.adapter.jdbc.h2; import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.sql.SQLException; import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper; import org.apache.arrow.adapter.jdbc.Table; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VectorSchemaRoot; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality for * (non-)optional columns, in particular with regard to the ensuing VectorSchemaRoot's schema. */ -@RunWith(Parameterized.class) public class JdbcToArrowOptionalColumnsTest extends AbstractJdbcToArrowTest { private static final String[] testFiles = {"h2/test1_null_and_notnull.yml"}; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - */ - public JdbcToArrowOptionalColumnsTest(Table table) { - this.table = table; - } - /** * Get the test data as a collection of Table objects for each test iteration. * @@ -57,19 +47,22 @@ public JdbcToArrowOptionalColumnsTest(Table table) { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameterized.Parameters - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.asList(prepareTestData(testFiles, JdbcToArrowOptionalColumnsTest.class)); + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowOptionalColumnsTest.class)) + .map(Arguments::of); } /** * Test Method to test JdbcToArrow Functionality for dealing with nullable and non-nullable * columns. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false); } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java index d290b9bf08960..7966f62e175e3 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java @@ -17,7 +17,7 @@ package org.apache.arrow.adapter.jdbc.h2; import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.sql.ResultSet; @@ -25,8 +25,6 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.ArrowVectorIterator; @@ -57,30 +55,18 @@ import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with * various data types for H2 database using single test data file. */ -@RunWith(Parameterized.class) public class JdbcToArrowTest extends AbstractJdbcToArrowTest { private static final String[] testFiles = {"h2/test1_all_datatypes_h2.yml"}; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - * @param reuseVectorSchemaRoot A flag indicating if we should reuse vector schema roots. - */ - public JdbcToArrowTest(Table table, boolean reuseVectorSchemaRoot) { - this.table = table; - this.reuseVectorSchemaRoot = reuseVectorSchemaRoot; - } - /** * Get the test data as a collection of Table objects for each test iteration. * @@ -89,21 +75,22 @@ public JdbcToArrowTest(Table table, boolean reuseVectorSchemaRoot) { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameterized.Parameters(name = "table = {0}, reuse batch = {1}") - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { return Arrays.stream(prepareTestData(testFiles, JdbcToArrowTest.class)) - .flatMap(row -> Stream.of(new Object[] {row[0], true}, new Object[] {row[0], false})) - .collect(Collectors.toList()); + .flatMap(row -> Stream.of(Arguments.of(row[0], true), Arguments.of(row[0], false))); } /** * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with only one * test data file. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets( sqlToArrow( conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), @@ -146,8 +133,12 @@ public void testJdbcToArrowValues() throws SQLException, IOException { true); } - @Test - public void testJdbcSchemaMetadata() throws SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcSchemaMetadata(Table table, boolean reuseVectorSchemaRoot) + throws SQLException, ClassNotFoundException { + this.initializeDatabase(table); + Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); JdbcToArrowConfig config = @@ -266,8 +257,12 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { } } - @Test - public void runLargeNumberOfRows() throws IOException, SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void runLargeNumberOfRows(Table table, boolean reuseVectorSchemaRoot) + throws IOException, SQLException, ClassNotFoundException { + this.initializeDatabase(table); + BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); int x = 0; final int targetRows = 600000; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java index c4930c3ab6017..0f60c89d1c03c 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java @@ -25,8 +25,8 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; import java.util.TimeZone; +import java.util.stream.Stream; import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -39,16 +39,14 @@ import org.apache.arrow.vector.TimeStampVector; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.Schema; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with * TimeZone based Date, Time and Timestamp datatypes for H2 database. */ -@RunWith(Parameterized.class) public class JdbcToArrowTimeZoneTest extends AbstractJdbcToArrowTest { private static final String EST_DATE = "est_date"; @@ -73,15 +71,6 @@ public class JdbcToArrowTimeZoneTest extends AbstractJdbcToArrowTest { "h2/test1_pst_timestamp_h2.yml" }; - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - */ - public JdbcToArrowTimeZoneTest(Table table) { - this.table = table; - } - /** * Get the test data as a collection of Table objects for each test iteration. * @@ -90,19 +79,22 @@ public JdbcToArrowTimeZoneTest(Table table) { * @throws ClassNotFoundException on error * @throws IOException on error */ - @Parameters - public static Collection getTestData() + public static Stream getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.asList(prepareTestData(testFiles, JdbcToArrowTimeZoneTest.class)); + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowTimeZoneTest.class)) + .map(Arguments::of); } /** * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with TimeZone * based Date, Time and Timestamp datatype. */ - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + testDataSets( sqlToArrow( conn, @@ -140,8 +132,11 @@ public void testJdbcToArrowValues() throws SQLException, IOException { false); } - @Test - public void testJdbcSchemaMetadata() throws SQLException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcSchemaMetadata(Table table) throws SQLException, ClassNotFoundException { + this.initializeDatabase(table); + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())); JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true).build(); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java index caa1c1d971adb..40fd39ac0c555 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java @@ -25,11 +25,11 @@ import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getIntValues; import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getListValues; import static org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper.getLongValues; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -69,26 +69,17 @@ import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.types.FloatingPointPrecision; import org.apache.arrow.vector.types.pojo.ArrowType; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class JdbcToArrowVectorIteratorTest extends JdbcToArrowTest { - /** - * Constructor which populates the table object for each test iteration. - * - * @param table Table object - * @param reuseVectorSchemaRoot A flag indicating if we should reuse vector schema roots. - */ - public JdbcToArrowVectorIteratorTest(Table table, boolean reuseVectorSchemaRoot) { - super(table, reuseVectorSchemaRoot); - } + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValues(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); - @Test - @Override - public void testJdbcToArrowValues() throws SQLException, IOException { JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) .setTargetBatchSize(3) @@ -102,8 +93,12 @@ public void testJdbcToArrowValues() throws SQLException, IOException { validate(iterator); } - @Test - public void testVectorSchemaRootReuse() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testVectorSchemaRootReuse(Table table, boolean reuseVectorSchemaRoot) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + Integer[][] intValues = { {101, 102, 103}, {104, null, null}, @@ -175,8 +170,11 @@ public void testVectorSchemaRootReuse() throws SQLException, IOException { assertTrue(batchCount > 1); } - @Test - public void testJdbcToArrowValuesNoLimit() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowValuesNoLimit(Table table) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) @@ -191,8 +189,12 @@ public void testJdbcToArrowValuesNoLimit() throws SQLException, IOException { validate(iterator); } - @Test - public void testTimeStampConsumer() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testTimeStampConsumer(Table table, boolean reuseVectorSchemaRoot) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + final String sql = "select timestamp_field11 from table1"; // first experiment, with calendar and time zone. @@ -535,8 +537,12 @@ private FieldVector getQueryResult(JdbcToArrowConfig config) throws SQLException return result; } - @Test - public void testJdbcToArrowCustomTypeConversion() throws SQLException, IOException { + @ParameterizedTest + @MethodSource("getTestData") + public void testJdbcToArrowCustomTypeConversion(Table table, boolean reuseVectorSchemaRoot) + throws SQLException, IOException, ClassNotFoundException { + this.initializeDatabase(table); + JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) .setTargetBatchSize(JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) diff --git a/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java b/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java index 17098806be72a..f8eb91a1cc758 100644 --- a/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java +++ b/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java @@ -16,9 +16,9 @@ */ package org.apache.arrow.adapter.orc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.File; import java.nio.charset.StandardCharsets; @@ -37,19 +37,18 @@ import org.apache.orc.OrcFile; import org.apache.orc.TypeDescription; import org.apache.orc.Writer; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class OrcReaderTest { - @Rule public TemporaryFolder testFolder = new TemporaryFolder(); + @TempDir public File testFolder; private static final int MAX_ALLOCATION = 8 * 1024; private static RootAllocator allocator; - @BeforeClass + @BeforeAll public static void beforeClass() { allocator = new RootAllocator(MAX_ALLOCATION); } @@ -57,7 +56,7 @@ public static void beforeClass() { @Test public void testOrcJniReader() throws Exception { TypeDescription schema = TypeDescription.fromString("struct"); - File testFile = new File(testFolder.getRoot(), "test-orc"); + File testFile = new File(testFolder, "test-orc"); Writer writer = OrcFile.createWriter(