diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/CustomHeaderTest.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/CustomHeaderTest.java index 96e18900e82ed..d36e4e6b6d258 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/CustomHeaderTest.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/CustomHeaderTest.java @@ -14,14 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.flight.client; import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.flight.Action; import org.apache.arrow.flight.CallHeaders; import org.apache.arrow.flight.CallInfo; @@ -49,22 +48,18 @@ import org.junit.Before; import org.junit.Test; -import com.google.common.collect.ImmutableMap; - -/** - * Tests to ensure custom headers are passed along to the server for each command. - */ +/** Tests to ensure custom headers are passed along to the server for each command. */ public class CustomHeaderTest { FlightServer server; FlightClient client; BufferAllocator allocator; TestCustomHeaderMiddleware.Factory headersMiddleware; HeaderCallOption headers; - Map testHeaders = ImmutableMap.of( + Map testHeaders = + ImmutableMap.of( "foo", "bar", "bar", "foo", - "answer", "42" - ); + "answer", "42"); @Before public void setUp() throws Exception { @@ -75,11 +70,13 @@ public void setUp() throws Exception { callHeaders.insert(entry.getKey(), entry.getValue()); } headers = new HeaderCallOption(callHeaders); - server = FlightServer.builder(allocator, - Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, /*port*/ 0), - new NoOpFlightProducer()) - .middleware(FlightServerMiddleware.Key.of("customHeader"), headersMiddleware) - .build(); + server = + FlightServer.builder( + allocator, + Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, /*port*/ 0), + new NoOpFlightProducer()) + .middleware(FlightServerMiddleware.Key.of("customHeader"), headersMiddleware) + .build(); server.start(); client = FlightClient.builder(allocator, server.getLocation()).build(); } @@ -94,7 +91,8 @@ public void tearDown() throws Exception { public void testHandshake() { try { client.handshake(headers); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.HANDSHAKE); } @@ -103,7 +101,8 @@ public void testHandshake() { public void testGetSchema() { try { client.getSchema(FlightDescriptor.command(new byte[0]), headers); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.GET_SCHEMA); } @@ -112,7 +111,8 @@ public void testGetSchema() { public void testGetFlightInfo() { try { client.getInfo(FlightDescriptor.command(new byte[0]), headers); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.GET_FLIGHT_INFO); } @@ -121,7 +121,8 @@ public void testGetFlightInfo() { public void testListActions() { try { client.listActions(headers).iterator().next(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.LIST_ACTIONS); } @@ -129,8 +130,9 @@ public void testListActions() { @Test public void testListFlights() { try { - client.listFlights(new Criteria(new byte[]{1}), headers).iterator().next(); - } catch (Exception ignored) { } + client.listFlights(new Criteria(new byte[] {1}), headers).iterator().next(); + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.LIST_FLIGHTS); } @@ -139,7 +141,8 @@ public void testListFlights() { public void testDoAction() { try { client.doAction(new Action("test"), headers).next(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.DO_ACTION); } @@ -147,11 +150,11 @@ public void testDoAction() { @Test public void testStartPut() { try { - final ClientStreamListener listener = client.startPut(FlightDescriptor.command(new byte[0]), - new SyncPutListener(), - headers); + final ClientStreamListener listener = + client.startPut(FlightDescriptor.command(new byte[0]), new SyncPutListener(), headers); listener.getResult(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.DO_PUT); } @@ -160,19 +163,19 @@ public void testStartPut() { public void testGetStream() { try (final FlightStream stream = client.getStream(new Ticket(new byte[0]), headers)) { stream.next(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.DO_GET); } @Test public void testDoExchange() { - try (final FlightClient.ExchangeReaderWriter stream = client.doExchange( - FlightDescriptor.command(new byte[0]), - headers) - ) { + try (final FlightClient.ExchangeReaderWriter stream = + client.doExchange(FlightDescriptor.command(new byte[0]), headers)) { stream.getReader().next(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } assertHeadersMatch(FlightMethod.DO_EXCHANGE); } @@ -183,39 +186,30 @@ private void assertHeadersMatch(FlightMethod method) { } } - /** - * A middleware used to test if customHeaders are being sent to the server properly. - */ + /** A middleware used to test if customHeaders are being sent to the server properly. */ static class TestCustomHeaderMiddleware implements FlightServerMiddleware { - public TestCustomHeaderMiddleware() { - } + public TestCustomHeaderMiddleware() {} @Override - public void onBeforeSendingHeaders(CallHeaders callHeaders) { - - } + public void onBeforeSendingHeaders(CallHeaders callHeaders) {} @Override - public void onCallCompleted(CallStatus callStatus) { - - } + public void onCallCompleted(CallStatus callStatus) {} @Override - public void onCallErrored(Throwable throwable) { - - } + public void onCallErrored(Throwable throwable) {} /** - * A factory for the middleware that keeps track of the received headers and provides a way - * to check those values for a given Flight Method. + * A factory for the middleware that keeps track of the received headers and provides a way to + * check those values for a given Flight Method. */ static class Factory implements FlightServerMiddleware.Factory { private final Map receivedCallHeaders = new HashMap<>(); @Override - public TestCustomHeaderMiddleware onCallStarted(CallInfo callInfo, CallHeaders callHeaders, - RequestContext requestContext) { + public TestCustomHeaderMiddleware onCallStarted( + CallInfo callInfo, CallHeaders callHeaders, RequestContext requestContext) { receivedCallHeaders.put(callInfo.method(), callHeaders); return new TestCustomHeaderMiddleware(); @@ -229,5 +223,5 @@ public String getCustomHeader(FlightMethod method, String key) { return headers.get(key); } } - } + } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java index b5116e057991a..3f51a3f92e7f0 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static com.google.protobuf.ByteString.copyFrom; @@ -36,6 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.protobuf.Message; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -48,7 +50,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.Consumer; - import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.driver.jdbc.utils.ResultSetTestUtils; import org.apache.arrow.driver.jdbc.utils.ThrowableAssertionUtils; @@ -86,25 +87,22 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.protobuf.Message; - -/** - * Class containing the tests from the {@link ArrowDatabaseMetadata}. - */ +/** Class containing the tests from the {@link ArrowDatabaseMetadata}. */ @SuppressWarnings("DoubleBraceInitialization") public class ArrowDatabaseMetadataTest { public static final boolean EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS = false; private static final MockFlightSqlProducer FLIGHT_SQL_PRODUCER = new MockFlightSqlProducer(); private static final MockFlightSqlProducer FLIGHT_SQL_PRODUCER_EMPTY_SQLINFO = new MockFlightSqlProducer(); + @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(FLIGHT_SQL_PRODUCER); + public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(FLIGHT_SQL_PRODUCER); + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_EMPTY_SQLINFO_TEST_RULE = FlightServerTestRule.createStandardTestRule(FLIGHT_SQL_PRODUCER_EMPTY_SQLINFO); + private static final int ROW_COUNT = 10; private static final List> EXPECTED_GET_CATALOGS_RESULTS = range(0, ROW_COUNT) @@ -120,61 +118,85 @@ public class ArrowDatabaseMetadataTest { .collect(toList()); private static final List> EXPECTED_GET_TABLES_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i), - format("db_schema_name #%d", i), - format("table_name #%d", i), - format("table_type #%d", i), - // TODO Add these fields to FlightSQL, as it's currently not possible to fetch them. - null, null, null, null, null, null}) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i), + format("db_schema_name #%d", i), + format("table_name #%d", i), + format("table_type #%d", i), + // TODO Add these fields to FlightSQL, as it's currently not possible to fetch + // them. + null, + null, + null, + null, + null, + null + }) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_GET_SCHEMAS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("db_schema_name #%d", i), - format("catalog_name #%d", i)}) + .mapToObj( + i -> new Object[] {format("db_schema_name #%d", i), format("catalog_name #%d", i)}) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("pk_catalog_name #%d", i), - format("pk_db_schema_name #%d", i), - format("pk_table_name #%d", i), - format("pk_column_name #%d", i), - format("fk_catalog_name #%d", i), - format("fk_db_schema_name #%d", i), - format("fk_table_name #%d", i), - format("fk_column_name #%d", i), - i, - format("fk_key_name #%d", i), - format("pk_key_name #%d", i), - (byte) i, - (byte) i, - // TODO Add this field to FlightSQL, as it's currently not possible to fetch it. - null}) + .mapToObj( + i -> + new Object[] { + format("pk_catalog_name #%d", i), + format("pk_db_schema_name #%d", i), + format("pk_table_name #%d", i), + format("pk_column_name #%d", i), + format("fk_catalog_name #%d", i), + format("fk_db_schema_name #%d", i), + format("fk_table_name #%d", i), + format("fk_column_name #%d", i), + i, + format("fk_key_name #%d", i), + format("pk_key_name #%d", i), + (byte) i, + (byte) i, + // TODO Add this field to FlightSQL, as it's currently not possible to fetch it. + null + }) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_CROSS_REFERENCE_RESULTS = EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS; private static final List> EXPECTED_PRIMARY_KEYS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i), - format("db_schema_name #%d", i), - format("table_name #%d", i), - format("column_name #%d", i), - i, - format("key_name #%d", i)}) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i), + format("db_schema_name #%d", i), + format("table_name #%d", i), + format("column_name #%d", i), + i, + format("key_name #%d", i) + }) .map(Arrays::asList) .collect(toList()); - private static final List FIELDS_GET_IMPORTED_EXPORTED_KEYS = ImmutableList.of( - "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", - "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM", - "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ", - "FK_NAME", "PK_NAME", "UPDATE_RULE", "DELETE_RULE", - "DEFERRABILITY"); + private static final List FIELDS_GET_IMPORTED_EXPORTED_KEYS = + ImmutableList.of( + "PKTABLE_CAT", + "PKTABLE_SCHEM", + "PKTABLE_NAME", + "PKCOLUMN_NAME", + "FKTABLE_CAT", + "FKTABLE_SCHEM", + "FKTABLE_NAME", + "FKCOLUMN_NAME", + "KEY_SEQ", + "FK_NAME", + "PK_NAME", + "UPDATE_RULE", + "DELETE_RULE", + "DEFERRABILITY"); private static final List FIELDS_GET_CROSS_REFERENCE = FIELDS_GET_IMPORTED_EXPORTED_KEYS; private static final String TARGET_TABLE = "TARGET_TABLE"; private static final String TARGET_FOREIGN_TABLE = "FOREIGN_TABLE"; @@ -236,8 +258,8 @@ public class ArrowDatabaseMetadataTest { private static final boolean EXPECTED_SUBQUERIES_IN_EXISTS = false; private static final boolean EXPECTED_SUBQUERIES_IN_INS = false; private static final boolean EXPECTED_SUBQUERIES_IN_QUANTIFIEDS = false; - private static final SqlSupportedSubqueries[] EXPECTED_SUPPORTED_SUBQUERIES = new SqlSupportedSubqueries[] - {SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS}; + private static final SqlSupportedSubqueries[] EXPECTED_SUPPORTED_SUBQUERIES = + new SqlSupportedSubqueries[] {SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS}; private static final boolean EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED = true; private static final boolean EXPECTED_SUPPORTS_UNION = true; private static final boolean EXPECTED_SUPPORTS_UNION_ALL = true; @@ -284,30 +306,41 @@ public class ArrowDatabaseMetadataTest { List expectedGetColumnsColumnSize = Arrays.asList(5, 29, 10); List expectedGetColumnsDecimalDigits = Arrays.asList(2, 9, 0); List expectedGetColumnsIsNullable = Arrays.asList("YES", "YES", "NO"); - EXPECTED_GET_COLUMNS_RESULTS = range(0, ROW_COUNT * 3) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i / 3), - format("db_schema_name #%d", i / 3), - format("table_name%d", i / 3), - format("column_%d", (i % 3) + 1), - expectedGetColumnsDataTypes.get(i % 3), - expectedGetColumnsTypeName.get(i % 3), - expectedGetColumnsColumnSize.get(i % 3), - null, - expectedGetColumnsDecimalDigits.get(i % 3), - expectedGetColumnsRadix.get(i % 3), - !Objects.equals(expectedGetColumnsIsNullable.get(i % 3), "NO") ? 1 : 0, - null, null, null, null, null, - (i % 3) + 1, - expectedGetColumnsIsNullable.get(i % 3), - null, null, null, null, - "", ""}) - .map(Arrays::asList) - .collect(toList()); + EXPECTED_GET_COLUMNS_RESULTS = + range(0, ROW_COUNT * 3) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i / 3), + format("db_schema_name #%d", i / 3), + format("table_name%d", i / 3), + format("column_%d", (i % 3) + 1), + expectedGetColumnsDataTypes.get(i % 3), + expectedGetColumnsTypeName.get(i % 3), + expectedGetColumnsColumnSize.get(i % 3), + null, + expectedGetColumnsDecimalDigits.get(i % 3), + expectedGetColumnsRadix.get(i % 3), + !Objects.equals(expectedGetColumnsIsNullable.get(i % 3), "NO") ? 1 : 0, + null, + null, + null, + null, + null, + (i % 3) + 1, + expectedGetColumnsIsNullable.get(i % 3), + null, + null, + null, + null, + "", + "" + }) + .map(Arrays::asList) + .collect(toList()); } - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); public final ResultSetTestUtils resultSetTestUtils = new ResultSetTestUtils(collector); @BeforeClass @@ -315,140 +348,149 @@ public static void setUpBeforeClass() throws SQLException { connection = FLIGHT_SERVER_TEST_RULE.getConnection(false); final Message commandGetCatalogs = CommandGetCatalogs.getDefaultInstance(); - final Consumer commandGetCatalogsResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_CATALOGS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - range(0, ROW_COUNT).forEach( - i -> catalogName.setSafe(i, new Text(format("catalog #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetCatalogsResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_CATALOGS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + range(0, ROW_COUNT) + .forEach(i -> catalogName.setSafe(i, new Text(format("catalog #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetCatalogs, commandGetCatalogsResultProducer); final Message commandGetTableTypes = CommandGetTableTypes.getDefaultInstance(); - final Consumer commandGetTableTypesResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, - allocator)) { - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - range(0, ROW_COUNT).forEach( - i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetTableTypesResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, allocator)) { + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + range(0, ROW_COUNT) + .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTableTypes, commandGetTableTypesResultProducer); final Message commandGetTables = CommandGetTables.getDefaultInstance(); - final Consumer commandGetTablesResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create( - Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) - .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetTablesResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) + .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTables, commandGetTablesResultProducer); - final Message commandGetTablesWithSchema = CommandGetTables.newBuilder() - .setIncludeSchema(true) - .build(); - final Consumer commandGetTablesWithSchemaResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA, - allocator)) { - final byte[] filledTableSchemaBytes = - copyFrom( - serializeSchema(new Schema(Arrays.asList( - Field.nullable("column_1", ArrowType.Decimal.createDecimal(5, 2, 128)), - Field.nullable("column_2", new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), - Field.notNullable("column_3", Types.MinorType.INT.getType()))))) - .toByteArray(); - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - final VarBinaryVector tableSchema = (VarBinaryVector) root.getVector("table_schema"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name%d", i)))) - .peek(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))) - .forEach(i -> tableSchema.setSafe(i, filledTableSchemaBytes)); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTablesWithSchema, - commandGetTablesWithSchemaResultProducer); + final Message commandGetTablesWithSchema = + CommandGetTables.newBuilder().setIncludeSchema(true).build(); + final Consumer commandGetTablesWithSchemaResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA, allocator)) { + final byte[] filledTableSchemaBytes = + copyFrom( + serializeSchema( + new Schema( + Arrays.asList( + Field.nullable( + "column_1", ArrowType.Decimal.createDecimal(5, 2, 128)), + Field.nullable( + "column_2", + new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), + Field.notNullable("column_3", Types.MinorType.INT.getType()))))) + .toByteArray(); + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + final VarBinaryVector tableSchema = (VarBinaryVector) root.getVector("table_schema"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name%d", i)))) + .peek(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))) + .forEach(i -> tableSchema.setSafe(i, filledTableSchemaBytes)); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetTablesWithSchema, commandGetTablesWithSchemaResultProducer); final Message commandGetDbSchemas = CommandGetDbSchemas.getDefaultInstance(); - final Consumer commandGetSchemasResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_SCHEMAS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .forEach(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetSchemasResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_SCHEMAS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .forEach(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetDbSchemas, commandGetSchemasResultProducer); final Message commandGetExportedKeys = CommandGetExportedKeys.newBuilder().setTable(TARGET_TABLE).build(); final Message commandGetImportedKeys = CommandGetImportedKeys.newBuilder().setTable(TARGET_TABLE).build(); - final Message commandGetCrossReference = CommandGetCrossReference.newBuilder() - .setPkTable(TARGET_TABLE) - .setFkTable(TARGET_FOREIGN_TABLE) - .build(); + final Message commandGetCrossReference = + CommandGetCrossReference.newBuilder() + .setPkTable(TARGET_TABLE) + .setFkTable(TARGET_FOREIGN_TABLE) + .build(); final Consumer commandGetExportedAndImportedKeysResultProducer = listener -> { try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create( - Schemas.GET_IMPORTED_KEYS_SCHEMA, - allocator)) { + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_IMPORTED_KEYS_SCHEMA, allocator)) { final VarCharVector pkCatalogName = (VarCharVector) root.getVector("pk_catalog_name"); final VarCharVector pkSchemaName = (VarCharVector) root.getVector("pk_db_schema_name"); final VarCharVector pkTableName = (VarCharVector) root.getVector("pk_table_name"); @@ -485,44 +527,46 @@ public static void setUpBeforeClass() throws SQLException { listener.completed(); } }; - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetExportedKeys, - commandGetExportedAndImportedKeysResultProducer); - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetImportedKeys, - commandGetExportedAndImportedKeysResultProducer); - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetCrossReference, - commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetExportedKeys, commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetImportedKeys, commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetCrossReference, commandGetExportedAndImportedKeysResultProducer); final Message commandGetPrimaryKeys = CommandGetPrimaryKeys.newBuilder().setTable(TARGET_TABLE).build(); - final Consumer commandGetPrimaryKeysResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_PRIMARY_KEYS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector columnName = (VarCharVector) root.getVector("column_name"); - final IntVector keySequence = (IntVector) root.getVector("key_sequence"); - final VarCharVector keyName = (VarCharVector) root.getVector("key_name"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) - .peek(i -> columnName.setSafe(i, new Text(format("column_name #%d", i)))) - .peek(i -> keySequence.setSafe(i, i)) - .forEach(i -> keyName.setSafe(i, new Text(format("key_name #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetPrimaryKeysResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_PRIMARY_KEYS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector columnName = (VarCharVector) root.getVector("column_name"); + final IntVector keySequence = (IntVector) root.getVector("key_sequence"); + final VarCharVector keyName = (VarCharVector) root.getVector("key_name"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) + .peek(i -> columnName.setSafe(i, new Text(format("column_name #%d", i)))) + .peek(i -> keySequence.setSafe(i, i)) + .forEach(i -> keyName.setSafe(i, new Text(format("key_name #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetPrimaryKeys, commandGetPrimaryKeysResultProducer); - FLIGHT_SQL_PRODUCER.getSqlInfoBuilder() + FLIGHT_SQL_PRODUCER + .getSqlInfoBuilder() .withSqlOuterJoinSupportLevel(FlightSql.SqlOuterJoinsSupportLevel.SQL_FULL_OUTER_JOINS) .withFlightSqlServerName(EXPECTED_DATABASE_PRODUCT_NAME) .withFlightSqlServerVersion(EXPECTED_DATABASE_PRODUCT_VERSION) @@ -537,8 +581,10 @@ public static void setUpBeforeClass() throws SQLException { .withSqlExtraNameCharacters(EXPECTED_EXTRA_NAME_CHARACTERS) .withSqlSupportsColumnAliasing(EXPECTED_SUPPORTS_COLUMN_ALIASING) .withSqlNullPlusNullIsNull(EXPECTED_NULL_PLUS_NULL_IS_NULL) - .withSqlSupportsConvert(ImmutableMap.of(SQL_CONVERT_BIT_VALUE, - Arrays.asList(SQL_CONVERT_INTEGER_VALUE, SQL_CONVERT_BIGINT_VALUE))) + .withSqlSupportsConvert( + ImmutableMap.of( + SQL_CONVERT_BIT_VALUE, + Arrays.asList(SQL_CONVERT_INTEGER_VALUE, SQL_CONVERT_BIGINT_VALUE))) .withSqlSupportsTableCorrelationNames(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES) .withSqlSupportsDifferentTableCorrelationNames( EXPECTED_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES) @@ -547,9 +593,11 @@ public static void setUpBeforeClass() throws SQLException { .withSqlSupportedGroupBy(FlightSql.SqlSupportedGroupBy.SQL_GROUP_BY_UNRELATED) .withSqlSupportsLikeEscapeClause(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE) .withSqlSupportsNonNullableColumns(EXPECTED_NON_NULLABLE_COLUMNS) - .withSqlSupportedGrammar(FlightSql.SupportedSqlGrammar.SQL_CORE_GRAMMAR, + .withSqlSupportedGrammar( + FlightSql.SupportedSqlGrammar.SQL_CORE_GRAMMAR, FlightSql.SupportedSqlGrammar.SQL_MINIMUM_GRAMMAR) - .withSqlAnsi92SupportedLevel(FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL, + .withSqlAnsi92SupportedLevel( + FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL, FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_INTERMEDIATE_SQL) .withSqlSupportsIntegrityEnhancementFacility( EXPECTED_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY) @@ -614,7 +662,6 @@ public static void tearDown() throws Exception { AutoCloseables.close(connection, FLIGHT_SQL_PRODUCER, FLIGHT_SQL_PRODUCER_EMPTY_SQLINFO); } - @Test public void testGetCatalogsCanBeAccessedByIndices() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { @@ -625,8 +672,8 @@ public void testGetCatalogsCanBeAccessedByIndices() throws SQLException { @Test public void testGetCatalogsCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { - resultSetTestUtils.testData(resultSet, singletonList("TABLE_CAT"), - EXPECTED_GET_CATALOGS_RESULTS); + resultSetTestUtils.testData( + resultSet, singletonList("TABLE_CAT"), EXPECTED_GET_CATALOGS_RESULTS); } } @@ -640,8 +687,8 @@ public void testTableTypesCanBeAccessedByIndices() throws SQLException { @Test public void testTableTypesCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getTableTypes()) { - resultSetTestUtils.testData(resultSet, singletonList("TABLE_TYPE"), - EXPECTED_GET_TABLE_TYPES_RESULTS); + resultSetTestUtils.testData( + resultSet, singletonList("TABLE_TYPE"), EXPECTED_GET_TABLE_TYPES_RESULTS); } } @@ -668,8 +715,7 @@ public void testGetTablesCanBeAccessedByNames() throws SQLException { "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION"), - EXPECTED_GET_TABLES_RESULTS - ); + EXPECTED_GET_TABLES_RESULTS); } } @@ -683,59 +729,67 @@ public void testGetSchemasCanBeAccessedByIndices() throws SQLException { @Test public void testGetSchemasCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getSchemas()) { - resultSetTestUtils.testData(resultSet, ImmutableList.of("TABLE_SCHEM", "TABLE_CATALOG"), + resultSetTestUtils.testData( + resultSet, + ImmutableList.of("TABLE_SCHEM", "TABLE_CATALOG"), EXPECTED_GET_SCHEMAS_RESULTS); } } @Test public void testGetExportedKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getExportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getExportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetExportedKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getExportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getExportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( - resultSet, FIELDS_GET_IMPORTED_EXPORTED_KEYS, + resultSet, + FIELDS_GET_IMPORTED_EXPORTED_KEYS, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetImportedKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getImportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getImportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetImportedKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getImportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getImportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( - resultSet, FIELDS_GET_IMPORTED_EXPORTED_KEYS, + resultSet, + FIELDS_GET_IMPORTED_EXPORTED_KEYS, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetCrossReferenceCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData().getCrossReference(null, null, - TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { + try (final ResultSet resultSet = + connection + .getMetaData() + .getCrossReference(null, null, TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_CROSS_REFERENCE_RESULTS); } } @Test public void testGetGetCrossReferenceCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData().getCrossReference(null, null, - TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { + try (final ResultSet resultSet = + connection + .getMetaData() + .getCrossReference(null, null, TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { resultSetTestUtils.testData( resultSet, FIELDS_GET_CROSS_REFERENCE, EXPECTED_CROSS_REFERENCE_RESULTS); } @@ -743,27 +797,21 @@ public void testGetGetCrossReferenceCanBeAccessedByNames() throws SQLException { @Test public void testPrimaryKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getPrimaryKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getPrimaryKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_PRIMARY_KEYS_RESULTS); } } @Test public void testPrimaryKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getPrimaryKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getPrimaryKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( resultSet, ImmutableList.of( - "TABLE_CAT", - "TABLE_SCHEM", - "TABLE_NAME", - "COLUMN_NAME", - "KEY_SEQ", - "PK_NAME"), - EXPECTED_PRIMARY_KEYS_RESULTS - ); + "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "KEY_SEQ", "PK_NAME"), + EXPECTED_PRIMARY_KEYS_RESULTS); } } @@ -776,14 +824,13 @@ public void testGetColumnsCanBeAccessedByIndices() throws SQLException { @Test public void testGetColumnsCanByIndicesFilteringColumnNames() throws SQLException { - try ( - final ResultSet resultSet = connection.getMetaData() - .getColumns(null, null, null, "column_1")) { - resultSetTestUtils.testData(resultSet, EXPECTED_GET_COLUMNS_RESULTS - .stream() - .filter(insideList -> Objects.equals(insideList.get(3), "column_1")) - .collect(toList()) - ); + try (final ResultSet resultSet = + connection.getMetaData().getColumns(null, null, null, "column_1")) { + resultSetTestUtils.testData( + resultSet, + EXPECTED_GET_COLUMNS_RESULTS.stream() + .filter(insideList -> Objects.equals(insideList.get(3), "column_1")) + .collect(toList())); } } @@ -791,8 +838,8 @@ public void testGetColumnsCanByIndicesFilteringColumnNames() throws SQLException public void testGetSqlInfo() throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); collector.checkThat(metaData.getDatabaseProductName(), is(EXPECTED_DATABASE_PRODUCT_NAME)); - collector.checkThat(metaData.getDatabaseProductVersion(), - is(EXPECTED_DATABASE_PRODUCT_VERSION)); + collector.checkThat( + metaData.getDatabaseProductVersion(), is(EXPECTED_DATABASE_PRODUCT_VERSION)); collector.checkThat(metaData.getIdentifierQuoteString(), is(EXPECTED_IDENTIFIER_QUOTE_STRING)); collector.checkThat(metaData.isReadOnly(), is(EXPECTED_IS_READ_ONLY)); collector.checkThat(metaData.getSQLKeywords(), is(EXPECTED_SQL_KEYWORDS)); @@ -805,29 +852,29 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.supportsConvert(), is(EXPECTED_SQL_SUPPORTS_CONVERT)); collector.checkThat(metaData.supportsConvert(BIT, INTEGER), is(EXPECTED_SQL_SUPPORTS_CONVERT)); collector.checkThat(metaData.supportsConvert(BIT, BIGINT), is(EXPECTED_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsConvert(BIGINT, INTEGER), - is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsConvert(JAVA_OBJECT, INTEGER), - is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsTableCorrelationNames(), - is(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES)); - collector.checkThat(metaData.supportsExpressionsInOrderBy(), - is(EXPECTED_EXPRESSIONS_IN_ORDER_BY)); - collector.checkThat(metaData.supportsOrderByUnrelated(), - is(EXPECTED_SUPPORTS_ORDER_BY_UNRELATED)); + collector.checkThat( + metaData.supportsConvert(BIGINT, INTEGER), is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); + collector.checkThat( + metaData.supportsConvert(JAVA_OBJECT, INTEGER), is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); + collector.checkThat( + metaData.supportsTableCorrelationNames(), is(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES)); + collector.checkThat( + metaData.supportsExpressionsInOrderBy(), is(EXPECTED_EXPRESSIONS_IN_ORDER_BY)); + collector.checkThat( + metaData.supportsOrderByUnrelated(), is(EXPECTED_SUPPORTS_ORDER_BY_UNRELATED)); collector.checkThat(metaData.supportsGroupBy(), is(EXPECTED_SUPPORTS_GROUP_BY)); - collector.checkThat(metaData.supportsGroupByUnrelated(), - is(EXPECTED_SUPPORTS_GROUP_BY_UNRELATED)); - collector.checkThat(metaData.supportsLikeEscapeClause(), - is(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE)); + collector.checkThat( + metaData.supportsGroupByUnrelated(), is(EXPECTED_SUPPORTS_GROUP_BY_UNRELATED)); + collector.checkThat( + metaData.supportsLikeEscapeClause(), is(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE)); collector.checkThat(metaData.supportsNonNullableColumns(), is(EXPECTED_NON_NULLABLE_COLUMNS)); collector.checkThat(metaData.supportsMinimumSQLGrammar(), is(EXPECTED_MINIMUM_SQL_GRAMMAR)); collector.checkThat(metaData.supportsCoreSQLGrammar(), is(EXPECTED_CORE_SQL_GRAMMAR)); collector.checkThat(metaData.supportsExtendedSQLGrammar(), is(EXPECTED_EXTEND_SQL_GRAMMAR)); - collector.checkThat(metaData.supportsANSI92EntryLevelSQL(), - is(EXPECTED_ANSI92_ENTRY_LEVEL_SQL)); - collector.checkThat(metaData.supportsANSI92IntermediateSQL(), - is(EXPECTED_ANSI92_INTERMEDIATE_SQL)); + collector.checkThat( + metaData.supportsANSI92EntryLevelSQL(), is(EXPECTED_ANSI92_ENTRY_LEVEL_SQL)); + collector.checkThat( + metaData.supportsANSI92IntermediateSQL(), is(EXPECTED_ANSI92_INTERMEDIATE_SQL)); collector.checkThat(metaData.supportsANSI92FullSQL(), is(EXPECTED_ANSI92_FULL_SQL)); collector.checkThat(metaData.supportsOuterJoins(), is(EXPECTED_SUPPORTS_OUTER_JOINS)); collector.checkThat(metaData.supportsFullOuterJoins(), is(EXPECTED_SUPPORTS_FULL_OUTER_JOINS)); @@ -836,32 +883,33 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.getProcedureTerm(), is(EXPECTED_PROCEDURE_TERM)); collector.checkThat(metaData.getCatalogTerm(), is(EXPECTED_CATALOG_TERM)); collector.checkThat(metaData.isCatalogAtStart(), is(EXPECTED_CATALOG_AT_START)); - collector.checkThat(metaData.supportsSchemasInProcedureCalls(), - is(EXPECTED_SCHEMAS_IN_PROCEDURE_CALLS)); - collector.checkThat(metaData.supportsSchemasInIndexDefinitions(), - is(EXPECTED_SCHEMAS_IN_INDEX_DEFINITIONS)); - collector.checkThat(metaData.supportsCatalogsInIndexDefinitions(), - is(EXPECTED_CATALOGS_IN_INDEX_DEFINITIONS)); + collector.checkThat( + metaData.supportsSchemasInProcedureCalls(), is(EXPECTED_SCHEMAS_IN_PROCEDURE_CALLS)); + collector.checkThat( + metaData.supportsSchemasInIndexDefinitions(), is(EXPECTED_SCHEMAS_IN_INDEX_DEFINITIONS)); + collector.checkThat( + metaData.supportsCatalogsInIndexDefinitions(), is(EXPECTED_CATALOGS_IN_INDEX_DEFINITIONS)); collector.checkThat(metaData.supportsPositionedDelete(), is(EXPECTED_POSITIONED_DELETE)); collector.checkThat(metaData.supportsPositionedUpdate(), is(EXPECTED_POSITIONED_UPDATE)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY), is(EXPECTED_TYPE_FORWARD_ONLY)); - collector.checkThat(metaData.supportsSelectForUpdate(), - is(EXPECTED_SELECT_FOR_UPDATE_SUPPORTED)); - collector.checkThat(metaData.supportsStoredProcedures(), - is(EXPECTED_STORED_PROCEDURES_SUPPORTED)); - collector.checkThat(metaData.supportsSubqueriesInComparisons(), - is(EXPECTED_SUBQUERIES_IN_COMPARISON)); + collector.checkThat( + metaData.supportsSelectForUpdate(), is(EXPECTED_SELECT_FOR_UPDATE_SUPPORTED)); + collector.checkThat( + metaData.supportsStoredProcedures(), is(EXPECTED_STORED_PROCEDURES_SUPPORTED)); + collector.checkThat( + metaData.supportsSubqueriesInComparisons(), is(EXPECTED_SUBQUERIES_IN_COMPARISON)); collector.checkThat(metaData.supportsSubqueriesInExists(), is(EXPECTED_SUBQUERIES_IN_EXISTS)); collector.checkThat(metaData.supportsSubqueriesInIns(), is(EXPECTED_SUBQUERIES_IN_INS)); - collector.checkThat(metaData.supportsSubqueriesInQuantifieds(), - is(EXPECTED_SUBQUERIES_IN_QUANTIFIEDS)); - collector.checkThat(metaData.supportsCorrelatedSubqueries(), - is(EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED)); + collector.checkThat( + metaData.supportsSubqueriesInQuantifieds(), is(EXPECTED_SUBQUERIES_IN_QUANTIFIEDS)); + collector.checkThat( + metaData.supportsCorrelatedSubqueries(), is(EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED)); collector.checkThat(metaData.supportsUnion(), is(EXPECTED_SUPPORTS_UNION)); collector.checkThat(metaData.supportsUnionAll(), is(EXPECTED_SUPPORTS_UNION_ALL)); - collector.checkThat(metaData.getMaxBinaryLiteralLength(), - is(EXPECTED_MAX_BINARY_LITERAL_LENGTH)); + collector.checkThat( + metaData.getMaxBinaryLiteralLength(), is(EXPECTED_MAX_BINARY_LITERAL_LENGTH)); collector.checkThat(metaData.getMaxCharLiteralLength(), is(EXPECTED_MAX_CHAR_LITERAL_LENGTH)); collector.checkThat(metaData.getMaxColumnsInGroupBy(), is(EXPECTED_MAX_COLUMNS_IN_GROUP_BY)); collector.checkThat(metaData.getMaxColumnsInIndex(), is(EXPECTED_MAX_COLUMNS_IN_INDEX)); @@ -871,35 +919,40 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.getMaxCursorNameLength(), is(EXPECTED_MAX_CURSOR_NAME_LENGTH)); collector.checkThat(metaData.getMaxIndexLength(), is(EXPECTED_MAX_INDEX_LENGTH)); collector.checkThat(metaData.getMaxSchemaNameLength(), is(EXPECTED_SCHEMA_NAME_LENGTH)); - collector.checkThat(metaData.getMaxProcedureNameLength(), - is(EXPECTED_MAX_PROCEDURE_NAME_LENGTH)); + collector.checkThat( + metaData.getMaxProcedureNameLength(), is(EXPECTED_MAX_PROCEDURE_NAME_LENGTH)); collector.checkThat(metaData.getMaxCatalogNameLength(), is(EXPECTED_MAX_CATALOG_NAME_LENGTH)); collector.checkThat(metaData.getMaxRowSize(), is(EXPECTED_MAX_ROW_SIZE)); - collector.checkThat(metaData.doesMaxRowSizeIncludeBlobs(), - is(EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS)); + collector.checkThat( + metaData.doesMaxRowSizeIncludeBlobs(), is(EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS)); collector.checkThat(metaData.getMaxStatementLength(), is(EXPECTED_MAX_STATEMENT_LENGTH)); collector.checkThat(metaData.getMaxStatements(), is(EXPECTED_MAX_STATEMENTS)); collector.checkThat(metaData.getMaxTableNameLength(), is(EXPECTED_MAX_TABLE_NAME_LENGTH)); collector.checkThat(metaData.getMaxTablesInSelect(), is(EXPECTED_MAX_TABLES_IN_SELECT)); collector.checkThat(metaData.getMaxUserNameLength(), is(EXPECTED_MAX_USERNAME_LENGTH)); - collector.checkThat(metaData.getDefaultTransactionIsolation(), - is(EXPECTED_DEFAULT_TRANSACTION_ISOLATION)); + collector.checkThat( + metaData.getDefaultTransactionIsolation(), is(EXPECTED_DEFAULT_TRANSACTION_ISOLATION)); collector.checkThat(metaData.supportsTransactions(), is(EXPECTED_TRANSACTIONS_SUPPORTED)); collector.checkThat(metaData.supportsBatchUpdates(), is(EXPECTED_BATCH_UPDATES_SUPPORTED)); collector.checkThat(metaData.supportsSavepoints(), is(EXPECTED_SAVEPOINTS_SUPPORTED)); - collector.checkThat(metaData.supportsNamedParameters(), - is(EXPECTED_NAMED_PARAMETERS_SUPPORTED)); + collector.checkThat( + metaData.supportsNamedParameters(), is(EXPECTED_NAMED_PARAMETERS_SUPPORTED)); collector.checkThat(metaData.locatorsUpdateCopy(), is(EXPECTED_LOCATORS_UPDATE_COPY)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE), is(EXPECTED_TYPE_SCROLL_INSENSITIVE)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE), is(EXPECTED_TYPE_SCROLL_SENSITIVE)); - collector.checkThat(metaData.supportsSchemasInPrivilegeDefinitions(), + collector.checkThat( + metaData.supportsSchemasInPrivilegeDefinitions(), is(EXPECTED_SCHEMAS_IN_PRIVILEGE_DEFINITIONS)); - collector.checkThat(metaData.supportsCatalogsInPrivilegeDefinitions(), + collector.checkThat( + metaData.supportsCatalogsInPrivilegeDefinitions(), is(EXPECTED_CATALOGS_IN_PRIVILEGE_DEFINITIONS)); - collector.checkThat(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE), + collector.checkThat( + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE), is(EXPECTED_TRANSACTION_NONE)); collector.checkThat( metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED), @@ -913,27 +966,35 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat( metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE), is(EXPECTED_TRANSACTION_SERIALIZABLE)); - collector.checkThat(metaData.dataDefinitionCausesTransactionCommit(), + collector.checkThat( + metaData.dataDefinitionCausesTransactionCommit(), is(EXPECTED_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT)); - collector.checkThat(metaData.dataDefinitionIgnoredInTransactions(), + collector.checkThat( + metaData.dataDefinitionIgnoredInTransactions(), is(EXPECTED_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED)); - collector.checkThat(metaData.supportsStoredFunctionsUsingCallSyntax(), + collector.checkThat( + metaData.supportsStoredFunctionsUsingCallSyntax(), is(EXPECTED_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED)); - collector.checkThat(metaData.supportsIntegrityEnhancementFacility(), + collector.checkThat( + metaData.supportsIntegrityEnhancementFacility(), is(EXPECTED_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY)); - collector.checkThat(metaData.supportsDifferentTableCorrelationNames(), + collector.checkThat( + metaData.supportsDifferentTableCorrelationNames(), is(EXPECTED_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES)); - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE + 1)); - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> metaData.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT)); } @Test public void testGetColumnsCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getColumns(null, null, null, null)) { - resultSetTestUtils.testData(resultSet, + resultSetTestUtils.testData( + resultSet, ImmutableList.of( "TABLE_CAT", "TABLE_SCHEM", @@ -959,8 +1020,7 @@ public void testGetColumnsCanBeAccessedByNames() throws SQLException { "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"), - EXPECTED_GET_COLUMNS_RESULTS - ); + EXPECTED_GET_COLUMNS_RESULTS); } } @@ -968,27 +1028,28 @@ public void testGetColumnsCanBeAccessedByNames() throws SQLException { public void testGetProcedures() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getProcedures(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetProceduresSchema = new HashMap() { - { - put(1, "PROCEDURE_CAT"); - put(2, "PROCEDURE_SCHEM"); - put(3, "PROCEDURE_NAME"); - put(4, "FUTURE_USE1"); - put(5, "FUTURE_USE2"); - put(6, "FUTURE_USE3"); - put(7, "REMARKS"); - put(8, "PROCEDURE_TYPE"); - put(9, "SPECIFIC_NAME"); - } - }; + final Map expectedGetProceduresSchema = + new HashMap() { + { + put(1, "PROCEDURE_CAT"); + put(2, "PROCEDURE_SCHEM"); + put(3, "PROCEDURE_NAME"); + put(4, "FUTURE_USE1"); + put(5, "FUTURE_USE2"); + put(6, "FUTURE_USE3"); + put(7, "REMARKS"); + put(8, "PROCEDURE_TYPE"); + put(9, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetProceduresSchema); } } @Test public void testGetProcedureColumns() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getProcedureColumns(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getProcedureColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetProcedureColumnsSchema = new HashMap() { @@ -1021,8 +1082,8 @@ public void testGetProcedureColumns() throws SQLException { @Test public void testGetColumnPrivileges() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getColumnPrivileges(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getColumnPrivileges(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetColumnPrivilegesSchema = new HashMap() { @@ -1045,25 +1106,26 @@ public void testGetColumnPrivileges() throws SQLException { public void testGetTablePrivileges() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getTablePrivileges(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetTablePrivilegesSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "GRANTOR"); - put(5, "GRANTEE"); - put(6, "PRIVILEGE"); - put(7, "IS_GRANTABLE"); - } - }; + final Map expectedGetTablePrivilegesSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "GRANTOR"); + put(5, "GRANTEE"); + put(6, "PRIVILEGE"); + put(7, "IS_GRANTABLE"); + } + }; testEmptyResultSet(resultSet, expectedGetTablePrivilegesSchema); } } @Test public void testGetBestRowIdentifier() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getBestRowIdentifier(null, null, null, 0, true)) { + try (ResultSet resultSet = + connection.getMetaData().getBestRowIdentifier(null, null, null, 0, true)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetBestRowIdentifierSchema = new HashMap() { @@ -1086,18 +1148,19 @@ public void testGetBestRowIdentifier() throws SQLException { public void testGetVersionColumns() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getVersionColumns(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetVersionColumnsSchema = new HashMap() { - { - put(1, "SCOPE"); - put(2, "COLUMN_NAME"); - put(3, "DATA_TYPE"); - put(4, "TYPE_NAME"); - put(5, "COLUMN_SIZE"); - put(6, "BUFFER_LENGTH"); - put(7, "DECIMAL_DIGITS"); - put(8, "PSEUDO_COLUMN"); - } - }; + final Map expectedGetVersionColumnsSchema = + new HashMap() { + { + put(1, "SCOPE"); + put(2, "COLUMN_NAME"); + put(3, "DATA_TYPE"); + put(4, "TYPE_NAME"); + put(5, "COLUMN_SIZE"); + put(6, "BUFFER_LENGTH"); + put(7, "DECIMAL_DIGITS"); + put(8, "PSEUDO_COLUMN"); + } + }; testEmptyResultSet(resultSet, expectedGetVersionColumnsSchema); } } @@ -1106,54 +1169,56 @@ public void testGetVersionColumns() throws SQLException { public void testGetTypeInfo() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getTypeInfo()) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetTypeInfoSchema = new HashMap() { - { - put(1, "TYPE_NAME"); - put(2, "DATA_TYPE"); - put(3, "PRECISION"); - put(4, "LITERAL_PREFIX"); - put(5, "LITERAL_SUFFIX"); - put(6, "CREATE_PARAMS"); - put(7, "NULLABLE"); - put(8, "CASE_SENSITIVE"); - put(9, "SEARCHABLE"); - put(10, "UNSIGNED_ATTRIBUTE"); - put(11, "FIXED_PREC_SCALE"); - put(12, "AUTO_INCREMENT"); - put(13, "LOCAL_TYPE_NAME"); - put(14, "MINIMUM_SCALE"); - put(15, "MAXIMUM_SCALE"); - put(16, "SQL_DATA_TYPE"); - put(17, "SQL_DATETIME_SUB"); - put(18, "NUM_PREC_RADIX"); - } - }; + final Map expectedGetTypeInfoSchema = + new HashMap() { + { + put(1, "TYPE_NAME"); + put(2, "DATA_TYPE"); + put(3, "PRECISION"); + put(4, "LITERAL_PREFIX"); + put(5, "LITERAL_SUFFIX"); + put(6, "CREATE_PARAMS"); + put(7, "NULLABLE"); + put(8, "CASE_SENSITIVE"); + put(9, "SEARCHABLE"); + put(10, "UNSIGNED_ATTRIBUTE"); + put(11, "FIXED_PREC_SCALE"); + put(12, "AUTO_INCREMENT"); + put(13, "LOCAL_TYPE_NAME"); + put(14, "MINIMUM_SCALE"); + put(15, "MAXIMUM_SCALE"); + put(16, "SQL_DATA_TYPE"); + put(17, "SQL_DATETIME_SUB"); + put(18, "NUM_PREC_RADIX"); + } + }; testEmptyResultSet(resultSet, expectedGetTypeInfoSchema); } } @Test public void testGetIndexInfo() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getIndexInfo(null, null, null, false, true)) { + try (ResultSet resultSet = + connection.getMetaData().getIndexInfo(null, null, null, false, true)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetIndexInfoSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "NON_UNIQUE"); - put(5, "INDEX_QUALIFIER"); - put(6, "INDEX_NAME"); - put(7, "TYPE"); - put(8, "ORDINAL_POSITION"); - put(9, "COLUMN_NAME"); - put(10, "ASC_OR_DESC"); - put(11, "CARDINALITY"); - put(12, "PAGES"); - put(13, "FILTER_CONDITION"); - } - }; + final Map expectedGetIndexInfoSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "NON_UNIQUE"); + put(5, "INDEX_QUALIFIER"); + put(6, "INDEX_NAME"); + put(7, "TYPE"); + put(8, "ORDINAL_POSITION"); + put(9, "COLUMN_NAME"); + put(10, "ASC_OR_DESC"); + put(11, "CARDINALITY"); + put(12, "PAGES"); + put(13, "FILTER_CONDITION"); + } + }; testEmptyResultSet(resultSet, expectedGetIndexInfoSchema); } } @@ -1162,17 +1227,18 @@ public void testGetIndexInfo() throws SQLException { public void testGetUDTs() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getUDTs(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetUDTsSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "CLASS_NAME"); - put(5, "DATA_TYPE"); - put(6, "REMARKS"); - put(7, "BASE_TYPE"); - } - }; + final Map expectedGetUDTsSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "CLASS_NAME"); + put(5, "DATA_TYPE"); + put(6, "REMARKS"); + put(7, "BASE_TYPE"); + } + }; testEmptyResultSet(resultSet, expectedGetUDTsSchema); } } @@ -1181,16 +1247,17 @@ public void testGetUDTs() throws SQLException { public void testGetSuperTypes() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getSuperTypes(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetSuperTypesSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "SUPERTYPE_CAT"); - put(5, "SUPERTYPE_SCHEM"); - put(6, "SUPERTYPE_NAME"); - } - }; + final Map expectedGetSuperTypesSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "SUPERTYPE_CAT"); + put(5, "SUPERTYPE_SCHEM"); + put(6, "SUPERTYPE_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetSuperTypesSchema); } } @@ -1199,14 +1266,15 @@ public void testGetSuperTypes() throws SQLException { public void testGetSuperTables() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getSuperTables(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetSuperTablesSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "SUPERTABLE_NAME"); - } - }; + final Map expectedGetSuperTablesSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "SUPERTABLE_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetSuperTablesSchema); } } @@ -1215,31 +1283,32 @@ public void testGetSuperTables() throws SQLException { public void testGetAttributes() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getAttributes(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetAttributesSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "ATTR_NAME"); - put(5, "DATA_TYPE"); - put(6, "ATTR_TYPE_NAME"); - put(7, "ATTR_SIZE"); - put(8, "DECIMAL_DIGITS"); - put(9, "NUM_PREC_RADIX"); - put(10, "NULLABLE"); - put(11, "REMARKS"); - put(12, "ATTR_DEF"); - put(13, "SQL_DATA_TYPE"); - put(14, "SQL_DATETIME_SUB"); - put(15, "CHAR_OCTET_LENGTH"); - put(16, "ORDINAL_POSITION"); - put(17, "IS_NULLABLE"); - put(18, "SCOPE_CATALOG"); - put(19, "SCOPE_SCHEMA"); - put(20, "SCOPE_TABLE"); - put(21, "SOURCE_DATA_TYPE"); - } - }; + final Map expectedGetAttributesSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "ATTR_NAME"); + put(5, "DATA_TYPE"); + put(6, "ATTR_TYPE_NAME"); + put(7, "ATTR_SIZE"); + put(8, "DECIMAL_DIGITS"); + put(9, "NUM_PREC_RADIX"); + put(10, "NULLABLE"); + put(11, "REMARKS"); + put(12, "ATTR_DEF"); + put(13, "SQL_DATA_TYPE"); + put(14, "SQL_DATETIME_SUB"); + put(15, "CHAR_OCTET_LENGTH"); + put(16, "ORDINAL_POSITION"); + put(17, "IS_NULLABLE"); + put(18, "SCOPE_CATALOG"); + put(19, "SCOPE_SCHEMA"); + put(20, "SCOPE_TABLE"); + put(21, "SOURCE_DATA_TYPE"); + } + }; testEmptyResultSet(resultSet, expectedGetAttributesSchema); } } @@ -1265,46 +1334,48 @@ public void testGetClientInfoProperties() throws SQLException { public void testGetFunctions() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getFunctions(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetFunctionsSchema = new HashMap() { - { - put(1, "FUNCTION_CAT"); - put(2, "FUNCTION_SCHEM"); - put(3, "FUNCTION_NAME"); - put(4, "REMARKS"); - put(5, "FUNCTION_TYPE"); - put(6, "SPECIFIC_NAME"); - } - }; + final Map expectedGetFunctionsSchema = + new HashMap() { + { + put(1, "FUNCTION_CAT"); + put(2, "FUNCTION_SCHEM"); + put(3, "FUNCTION_NAME"); + put(4, "REMARKS"); + put(5, "FUNCTION_TYPE"); + put(6, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetFunctionsSchema); } } @Test public void testGetFunctionColumns() throws SQLException { - try ( - ResultSet resultSet = connection.getMetaData().getFunctionColumns(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getFunctionColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetFunctionColumnsSchema = new HashMap() { - { - put(1, "FUNCTION_CAT"); - put(2, "FUNCTION_SCHEM"); - put(3, "FUNCTION_NAME"); - put(4, "COLUMN_NAME"); - put(5, "COLUMN_TYPE"); - put(6, "DATA_TYPE"); - put(7, "TYPE_NAME"); - put(8, "PRECISION"); - put(9, "LENGTH"); - put(10, "SCALE"); - put(11, "RADIX"); - put(12, "NULLABLE"); - put(13, "REMARKS"); - put(14, "CHAR_OCTET_LENGTH"); - put(15, "ORDINAL_POSITION"); - put(16, "IS_NULLABLE"); - put(17, "SPECIFIC_NAME"); - } - }; + final Map expectedGetFunctionColumnsSchema = + new HashMap() { + { + put(1, "FUNCTION_CAT"); + put(2, "FUNCTION_SCHEM"); + put(3, "FUNCTION_NAME"); + put(4, "COLUMN_NAME"); + put(5, "COLUMN_TYPE"); + put(6, "DATA_TYPE"); + put(7, "TYPE_NAME"); + put(8, "PRECISION"); + put(9, "LENGTH"); + put(10, "SCALE"); + put(11, "RADIX"); + put(12, "NULLABLE"); + put(13, "REMARKS"); + put(14, "CHAR_OCTET_LENGTH"); + put(15, "ORDINAL_POSITION"); + put(16, "IS_NULLABLE"); + put(17, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetFunctionColumnsSchema); } } @@ -1313,28 +1384,29 @@ public void testGetFunctionColumns() throws SQLException { public void testGetPseudoColumns() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getPseudoColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetPseudoColumnsSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "COLUMN_NAME"); - put(5, "DATA_TYPE"); - put(6, "COLUMN_SIZE"); - put(7, "DECIMAL_DIGITS"); - put(8, "NUM_PREC_RADIX"); - put(9, "COLUMN_USAGE"); - put(10, "REMARKS"); - put(11, "CHAR_OCTET_LENGTH"); - put(12, "IS_NULLABLE"); - } - }; + final Map expectedGetPseudoColumnsSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "COLUMN_NAME"); + put(5, "DATA_TYPE"); + put(6, "COLUMN_SIZE"); + put(7, "DECIMAL_DIGITS"); + put(8, "NUM_PREC_RADIX"); + put(9, "COLUMN_USAGE"); + put(10, "REMARKS"); + put(11, "CHAR_OCTET_LENGTH"); + put(12, "IS_NULLABLE"); + } + }; testEmptyResultSet(resultSet, expectedGetPseudoColumnsSchema); } } - private void testEmptyResultSet(final ResultSet resultSet, - final Map expectedResultSetSchema) + private void testEmptyResultSet( + final ResultSet resultSet, final Map expectedResultSetSchema) throws SQLException { assertFalse(resultSet.next()); final ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); @@ -1345,76 +1417,102 @@ private void testEmptyResultSet(final ResultSet resultSet, @Test public void testGetColumnSize() { - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_BYTE), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_BYTE), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Byte.SIZE, true))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_SHORT), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_SHORT), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Short.SIZE, true))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_INT), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_INT), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Integer.SIZE, true))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_LONG), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_LONG), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Long.SIZE, true))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Utf8())); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Binary())); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_SECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_SECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.SECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MILLISECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MILLISECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MICROSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MICROSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_NANOSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_NANOSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Time(TimeUnit.SECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MILLISECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MILLISECONDS), ArrowDatabaseMetadata.getColumnSize( new ArrowType.Time(TimeUnit.MILLISECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MICROSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MICROSECONDS), ArrowDatabaseMetadata.getColumnSize( new ArrowType.Time(TimeUnit.MICROSECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_NANOSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_NANOSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Time(TimeUnit.NANOSECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_DATE), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_DATE), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Date(DateUnit.DAY))); - assertNull(ArrowDatabaseMetadata.getColumnSize(new ArrowType.FloatingPoint( - FloatingPointPrecision.DOUBLE))); + assertNull( + ArrowDatabaseMetadata.getColumnSize( + new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))); } @Test public void testGetDecimalDigits() { - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Int(Byte.SIZE, true))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Timestamp(TimeUnit.SECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Timestamp(TimeUnit.MILLISECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Timestamp(TimeUnit.MICROSECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Time(TimeUnit.SECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.MILLISECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.MICROSECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.NANOSECOND, Integer.SIZE))); - assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Date(DateUnit.DAY))); assertNull(ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Utf8())); @@ -1430,7 +1528,8 @@ public void testSqlToRegexLike() { @Test public void testEmptySqlInfo() throws Exception { - try (final Connection testConnection = FLIGHT_SERVER_EMPTY_SQLINFO_TEST_RULE.getConnection(false)) { + try (final Connection testConnection = + FLIGHT_SERVER_EMPTY_SQLINFO_TEST_RULE.getConnection(false)) { final DatabaseMetaData metaData = testConnection.getMetaData(); collector.checkThat(metaData.getSQLKeywords(), is("")); collector.checkThat(metaData.getNumericFunctions(), is("")); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java index 36f110ac18ce2..d6208284adebe 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -23,9 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; - import javax.sql.PooledConnection; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.utils.ConnectionWrapper; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; @@ -35,8 +32,7 @@ import org.junit.Test; public class ArrowFlightJdbcConnectionPoolDataSourceTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); @@ -47,10 +43,11 @@ public class ArrowFlightJdbcConnectionPoolDataSourceTest { .user("user2", "pass2") .build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private ArrowFlightJdbcConnectionPoolDataSource dataSource; @@ -111,7 +108,8 @@ public void testShouldReuseConnectionsOnPool() throws Exception { assertSame(pooledConnection, pooledConnection2); assertNotSame(connection, connection2); - assertSame(connection.unwrap(ArrowFlightConnection.class), + assertSame( + connection.unwrap(ArrowFlightConnection.class), connection2.unwrap(ArrowFlightConnection.class)); } @@ -133,7 +131,8 @@ public void testShouldNotMixConnectionsForDifferentUsers() throws Exception { assertNotSame(pooledConnection, pooledConnection2); assertNotSame(connection, connection2); - assertNotSame(connection.unwrap(ArrowFlightConnection.class), + assertNotSame( + connection.unwrap(ArrowFlightConnection.class), connection2.unwrap(ArrowFlightConnection.class)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java index 891500fed52c9..65f06cf45e3dc 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -29,7 +28,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -43,13 +41,10 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionMutualTlsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final String tlsRootCertsPath; private static final String clientMTlsCertPath; private static final String badClientMTlsCertPath; @@ -60,15 +55,15 @@ public class ConnectionMutualTlsTest { private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); tlsRootCertsPath = certKey.cert.getPath(); final File serverMTlsCACert = FlightSqlTestCertificates.exampleCACert(); - final FlightSqlTestCertificates.CertKeyPair - clientMTlsCertKey = FlightSqlTestCertificates.exampleTlsCerts().get(1); + final FlightSqlTestCertificates.CertKeyPair clientMTlsCertKey = + FlightSqlTestCertificates.exampleTlsCerts().get(1); clientMTlsCertPath = clientMTlsCertKey.cert.getPath(); clientMTlsKeyPath = clientMTlsCertKey.key.getPath(); @@ -76,16 +71,16 @@ public class ConnectionMutualTlsTest { badClientMTlsCertPath = clientMTlsCertPath + ".bad"; badClientMTlsKeyPath = clientMTlsKeyPath + ".bad"; - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .useMTlsClientVerification(serverMTlsCACert) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .useMTlsClientVerification(serverMTlsCACert) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -110,17 +105,17 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -132,21 +127,24 @@ public void testGetEncryptedClientAuthenticated() throws Exception { @Test public void testGetEncryptedClientWithBadMTlsCertPath() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(badClientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(badClientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + fail(); + } + }); } /** @@ -156,21 +154,24 @@ public void testGetEncryptedClientWithBadMTlsCertPath() { @Test public void testGetEncryptedClientWithBadMTlsKeyPath() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(badClientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(badClientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + fail(); + } + }); } /** @@ -181,21 +182,21 @@ public void testGetEncryptedClientWithBadMTlsKeyPath() { @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid TLS Root Certs path. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid TLS Root Certs path. * * @throws Exception on error. */ @@ -204,18 +205,14 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), - clientMTlsCertPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), - clientMTlsKeyPath); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); @@ -225,8 +222,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro } /** - * Check if an encrypted connection can be established successfully when not - * providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -234,22 +231,26 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through - * the DriverManager using just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -258,9 +259,10 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&%s=%s&%s=%s&%s=%s", + final String jdbcUrl = + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&%s=%s&%s=%s&%s=%s", FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, @@ -277,14 +279,15 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -292,14 +295,15 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - properties.setProperty(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.setProperty( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.setProperty(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { assertTrue(connection.isValid(0)); @@ -307,8 +311,8 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -324,12 +328,12 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { assertTrue(connection.isValid(0)); @@ -337,8 +341,8 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -348,9 +352,10 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s&%s=%s", + final String jdbcUrl = + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s&%s=%s", FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, @@ -367,14 +372,16 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -382,12 +389,15 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); - properties.setProperty(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.setProperty( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.setProperty(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { assertTrue(connection.isValid(0)); @@ -395,14 +405,16 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -412,11 +424,12 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 1); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { assertTrue(connection.isValid(0)); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java index 3fea2fbb68395..9d39c18097a39 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,7 +27,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -41,27 +39,23 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests for {@link Connection}. - */ +/** Tests for {@link Connection}. */ public class ConnectionTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); private static final String userTest = "user1"; private static final String passTest = "pass1"; static { UserPasswordAuthentication authentication = - new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -78,8 +72,8 @@ public void tearDown() throws Exception { } /** - * Checks if an unencrypted connection can be established successfully when - * the provided valid credentials. + * Checks if an unencrypted connection can be established successfully when the provided valid + * credentials. * * @throws SQLException on error. */ @@ -89,58 +83,64 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWhenProvidedValidCred final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + - FLIGHT_SERVER_TEST_RULE.getPort(), properties)) { + try (Connection connection = + DriverManager.getConnection( + "jdbc:arrow-flight-sql://" + + FLIGHT_SERVER_TEST_RULE.getHost() + + ":" + + FLIGHT_SERVER_TEST_RULE.getPort(), + properties)) { assertTrue(connection.isValid(300)); } } /** - * Checks if a token is provided it takes precedence over username/pass. In this case, - * the connection should fail if a token is passed in. + * Checks if a token is provided it takes precedence over username/pass. In this case, the + * connection should fail if a token is passed in. */ @Test public void testTokenOverridesUsernameAndPasswordAuth() { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.TOKEN.camelName(), "token"); properties.put("useEncryption", false); - SQLException e = assertThrows(SQLException.class, () -> { - try (Connection conn = DriverManager.getConnection( - "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + FLIGHT_SERVER_TEST_RULE.getPort(), - properties)) { - fail(); - } - }); + SQLException e = + assertThrows( + SQLException.class, + () -> { + try (Connection conn = + DriverManager.getConnection( + "jdbc:arrow-flight-sql://" + + FLIGHT_SERVER_TEST_RULE.getHost() + + ":" + + FLIGHT_SERVER_TEST_RULE.getPort(), + properties)) { + fail(); + } + }); assertTrue(e.getMessage().contains("UNAUTHENTICATED")); } - /** - * Checks if the exception SQLException is thrown when trying to establish a connection without a host. + * Checks if the exception SQLException is thrown when trying to establish a connection without a + * host. * * @throws SQLException on error. */ @Test(expected = SQLException.class) - public void testUnencryptedConnectionWithEmptyHost() - throws Exception { + public void testUnencryptedConnectionWithEmptyHost() throws Exception { final Properties properties = new Properties(); properties.put("user", userTest); @@ -158,43 +158,38 @@ public void testUnencryptedConnectionWithEmptyHost() * @throws URISyntaxException on error. */ @Test - public void testGetBasicClientAuthenticatedShouldOpenConnection() - throws Exception { + public void testGetBasicClientAuthenticatedShouldOpenConnection() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withEncryption(false) - .withUsername(userTest) - .withPassword(passTest) - .withBufferAllocator(allocator) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withEncryption(false) + .withUsername(userTest) + .withPassword(passTest) + .withBufferAllocator(allocator) + .build()) { assertNotNull(client); } } /** - * Checks if the exception IllegalArgumentException is thrown when trying to establish an unencrypted - * connection providing with an invalid port. + * Checks if the exception IllegalArgumentException is thrown when trying to establish an + * unencrypted connection providing with an invalid port. * * @throws SQLException on error. */ @Test(expected = SQLException.class) - public void testUnencryptedConnectionProvidingInvalidPort() - throws Exception { + public void testUnencryptedConnectionProvidingInvalidPort() throws Exception { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - final String invalidUrl = "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + - ":" + 65537; + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + final String invalidUrl = + "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + 65537; try (Connection conn = DriverManager.getConnection(invalidUrl, properties)) { fail("Expected SQLException"); @@ -210,18 +205,18 @@ public void testUnencryptedConnectionProvidingInvalidPort() public void testGetBasicClientNoAuthShouldOpenConnection() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withBufferAllocator(allocator) - .withEncryption(false) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withBufferAllocator(allocator) + .withEncryption(false) + .build()) { assertNotNull(client); } } /** - * Checks if an unencrypted connection can be established successfully when - * not providing credentials. + * Checks if an unencrypted connection can be established successfully when not providing + * credentials. * * @throws SQLException on error. */ @@ -230,19 +225,17 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWithoutAuthentication throws Exception { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - try (Connection connection = DriverManager - .getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + try (Connection connection = + DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { assertTrue(connection.isValid(300)); } } /** - * Check if an unencrypted connection throws an exception when provided with - * invalid credentials. + * Check if an unencrypted connection throws an exception when provided with invalid credentials. * * @throws SQLException The exception expected to be thrown. */ @@ -253,17 +246,14 @@ public void testUnencryptedConnectionShouldThrowExceptionWhenProvidedWithInvalid final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - "invalidUser"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - "invalidPassword"); - - try (Connection ignored = DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", - properties)) { + properties.put(ArrowFlightConnectionProperty.USER.camelName(), "invalidUser"); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), "invalidPassword"); + + try (Connection ignored = + DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { fail(); } } @@ -279,12 +269,11 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlWithDriverManager() thro final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=false", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=false", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest))) { assertTrue(connection.isValid(0)); } } @@ -296,24 +285,23 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlWithDriverManager() thro * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "false"); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } @@ -331,17 +319,15 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingPutWit DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } @@ -358,70 +344,67 @@ public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlWithDriverManager final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=0", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=0", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest))) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "0"); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 0); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } @@ -438,73 +421,69 @@ public void testThreadPoolSizeConnectionPropertyCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&threadPoolSize=1&useEncryption=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - false))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&threadPoolSize=1&useEncryption=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, false))) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), "1"); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), 1); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } @@ -521,71 +500,67 @@ public void testPasswordConnectionPropertyIntegerCorrectCastUrlWithDriverManager final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - false))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, false))) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java index fd64741f51a74..cdfd1af7ab5b7 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,7 +27,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -42,13 +40,10 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionTlsRootCertsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final String tlsRootCertsPath; private static final String badTlsRootCertsPath; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); @@ -56,22 +51,22 @@ public class ConnectionTlsRootCertsTest { private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); tlsRootCertsPath = certKey.cert.getPath(); badTlsRootCertsPath = certKey.cert.getPath() + ".bad"; - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -96,35 +91,38 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Try to instantiate an encrypted FlightClient providing a bad TLS Root Certs Path. It's expected to - * receive the SQLException. + * Try to instantiate an encrypted FlightClient providing a bad TLS Root Certs Path. It's expected + * to receive the SQLException. */ @Test public void testGetEncryptedClientWithNoCertificateOnKeyStore() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(badTlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(badTlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + fail(); + } + }); } /** @@ -135,19 +133,19 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() { @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(tlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(tlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid TLS Root Certs path. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid TLS Root Certs path. * * @throws Exception on error. */ @@ -156,14 +154,11 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - tlsRootCertsPath); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); @@ -173,8 +168,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro } /** - * Check if an encrypted connection can be established successfully when not - * providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -182,20 +177,23 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through - * the DriverManager using just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -204,28 +202,30 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), + URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -233,21 +233,22 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -264,18 +265,18 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -285,28 +286,31 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), + URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -314,25 +318,30 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -343,10 +352,11 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 1); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java index ab384252ebe78..20cd452ca1132 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,7 +27,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -43,30 +41,27 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionTlsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); private static final String userTest = "user1"; private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .producer(PRODUCER) + .build(); } private String trustStorePath; @@ -76,10 +71,14 @@ public class ConnectionTlsTest { @Before public void setUp() throws Exception { - trustStorePath = Paths.get( - Preconditions.checkNotNull(getClass().getResource("/keys/keyStore.jks")).toURI()).toString(); - noCertificateKeyStorePath = Paths.get( - Preconditions.checkNotNull(getClass().getResource("/keys/noCertificate.jks")).toURI()).toString(); + trustStorePath = + Paths.get(Preconditions.checkNotNull(getClass().getResource("/keys/keyStore.jks")).toURI()) + .toString(); + noCertificateKeyStorePath = + Paths.get( + Preconditions.checkNotNull(getClass().getResource("/keys/noCertificate.jks")) + .toURI()) + .toString(); allocator = new RootAllocator(Long.MAX_VALUE); } @@ -98,15 +97,15 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticatedWithDisableCertVerification() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withDisableCertificateVerification(true) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withDisableCertificateVerification(true) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -120,24 +119,24 @@ public void testGetEncryptedClientAuthenticatedWithDisableCertVerification() thr public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withSystemTrustStore(false) - .withUsername(userTest) - .withPassword(passTest) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(trustStorePass) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withSystemTrustStore(false) + .withUsername(userTest) + .withPassword(passTest) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(trustStorePass) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Try to instantiate an encrypted FlightClient providing a keystore without certificate. It's expected to - * receive the SQLException. + * Try to instantiate an encrypted FlightClient providing a keystore without certificate. It's + * expected to receive the SQLException. * * @throws Exception on error. */ @@ -146,14 +145,14 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() throws Exception final String noCertificateKeyStorePassword = "flight1"; try (ArrowFlightSqlClientHandler ignored = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTrustStorePath(noCertificateKeyStorePath) - .withTrustStorePassword(noCertificateKeyStorePassword) - .withSystemTrustStore(false) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTrustStorePath(noCertificateKeyStorePath) + .withTrustStorePassword(noCertificateKeyStorePassword) + .withSystemTrustStore(false) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { fail(); } } @@ -166,14 +165,14 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() throws Exception @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withSystemTrustStore(false) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(trustStorePass) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withSystemTrustStore(false) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(trustStorePass) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -189,21 +188,21 @@ public void testGetEncryptedClientWithKeyStoreBadPasswordAndNoAuth() throws Exce String keyStoreBadPassword = "badPassword"; try (ArrowFlightSqlClientHandler ignored = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withSystemTrustStore(false) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(keyStoreBadPassword) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withSystemTrustStore(false) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(keyStoreBadPassword) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { fail(); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid Keystore. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid Keystore. * * @throws Exception on error. */ @@ -212,12 +211,10 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); @@ -230,8 +227,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E } /** - * Check if the SQLException is thrown when trying to establish an encrypted connection - * providing valid credentials but invalid password to the Keystore. + * Check if the SQLException is thrown when trying to establish an encrypted connection providing + * valid credentials but invalid password to the Keystore. * * @throws SQLException on error. */ @@ -239,14 +236,12 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), - FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), "badpassword"); @@ -259,7 +254,8 @@ public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() thr } /** - * Check if an encrypted connection can be established successfully when not providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -267,22 +263,25 @@ public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() thr public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -291,30 +290,32 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&useSystemTrustStore=false&%s=%s&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TRUST_STORE.camelName(), - URLEncoder.encode(trustStorePath, "UTF-8"), - ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), - URLEncoder.encode(trustStorePass, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&useSystemTrustStore=false&%s=%s&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TRUST_STORE.camelName(), + URLEncoder.encode(trustStorePath, "UTF-8"), + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), + URLEncoder.encode(trustStorePass, "UTF-8")))) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -323,22 +324,24 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); - properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); + properties.setProperty( + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "false"); - - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + properties.setProperty( + ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "false"); + + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -357,18 +360,18 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -378,30 +381,33 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TRUST_STORE.camelName(), - URLEncoder.encode(trustStorePath, "UTF-8"), - ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), - URLEncoder.encode(trustStorePass, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TRUST_STORE.camelName(), + URLEncoder.encode(trustStorePath, "UTF-8"), + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), + URLEncoder.encode(trustStorePass, "UTF-8")))) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -410,26 +416,31 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); - properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); + properties.setProperty( + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "0"); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -442,10 +453,11 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java index ccb1dd7c4e238..0bfef5e890661 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc.accessor; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -27,7 +26,6 @@ import java.sql.SQLException; import java.util.HashMap; import java.util.Map; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -39,8 +37,7 @@ public class ArrowFlightJdbcAccessorTest { static class MockedArrowFlightJdbcAccessor extends ArrowFlightJdbcAccessor { protected MockedArrowFlightJdbcAccessor() { - super(() -> 0, (boolean wasNull) -> { - }); + super(() -> 0, (boolean wasNull) -> {}); } @Override @@ -49,8 +46,7 @@ public Class getObjectClass() { } } - @Mock - MockedArrowFlightJdbcAccessor accessor; + @Mock MockedArrowFlightJdbcAccessor accessor; @Test public void testShouldGetObjectWithByteClassReturnGetByte() throws SQLException { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java index 7f635369109e7..bb97442be2ac6 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc.accessor.impl.calendar; import static org.apache.arrow.driver.jdbc.utils.IntervalStringUtils.formatIntervalDay; @@ -29,7 +28,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -53,73 +51,86 @@ public class ArrowFlightJdbcIntervalVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final Supplier vectorSupplier; private ValueVector vector; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof IntervalDayVector) { - return new ArrowFlightJdbcIntervalVectorAccessor((IntervalDayVector) vector, - getCurrentRow, noOpWasNullConsumer); - } else if (vector instanceof IntervalYearVector) { - return new ArrowFlightJdbcIntervalVectorAccessor((IntervalYearVector) vector, - getCurrentRow, noOpWasNullConsumer); - } else if (vector instanceof IntervalMonthDayNanoVector) { - return new ArrowFlightJdbcIntervalVectorAccessor((IntervalMonthDayNanoVector) vector, - getCurrentRow, noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof IntervalDayVector) { + return new ArrowFlightJdbcIntervalVectorAccessor( + (IntervalDayVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof IntervalYearVector) { + return new ArrowFlightJdbcIntervalVectorAccessor( + (IntervalYearVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof IntervalMonthDayNanoVector) { + return new ArrowFlightJdbcIntervalVectorAccessor( + (IntervalMonthDayNanoVector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; final AccessorTestUtils.AccessorIterator accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> { - IntervalDayVector vector = - new IntervalDayVector("", rootAllocatorTestRule.getRootAllocator()); + return Arrays.asList( + new Object[][] { + { + (Supplier) + () -> { + IntervalDayVector vector = + new IntervalDayVector("", rootAllocatorTestRule.getRootAllocator()); - int valueCount = 10; - vector.setValueCount(valueCount); - for (int i = 0; i < valueCount; i++) { - vector.set(i, i + 1, (i + 1) * 1000); - } - return vector; - }, "IntervalDayVector"}, - {(Supplier) () -> { - IntervalYearVector vector = - new IntervalYearVector("", rootAllocatorTestRule.getRootAllocator()); + int valueCount = 10; + vector.setValueCount(valueCount); + for (int i = 0; i < valueCount; i++) { + vector.set(i, i + 1, (i + 1) * 1000); + } + return vector; + }, + "IntervalDayVector" + }, + { + (Supplier) + () -> { + IntervalYearVector vector = + new IntervalYearVector("", rootAllocatorTestRule.getRootAllocator()); - int valueCount = 10; - vector.setValueCount(valueCount); - for (int i = 0; i < valueCount; i++) { - vector.set(i, i + 1); - } - return vector; - }, "IntervalYearVector"}, - {(Supplier) () -> { - IntervalMonthDayNanoVector vector = - new IntervalMonthDayNanoVector("", rootAllocatorTestRule.getRootAllocator()); + int valueCount = 10; + vector.setValueCount(valueCount); + for (int i = 0; i < valueCount; i++) { + vector.set(i, i + 1); + } + return vector; + }, + "IntervalYearVector" + }, + { + (Supplier) + () -> { + IntervalMonthDayNanoVector vector = + new IntervalMonthDayNanoVector("", rootAllocatorTestRule.getRootAllocator()); - int valueCount = 10; - vector.setValueCount(valueCount); - for (int i = 0; i < valueCount; i++) { - vector.set(i, i + 1, (i + 1) * 10, (i + 1) * 100); - } - return vector; - }, "IntervalMonthDayNanoVector"}, - }); + int valueCount = 10; + vector.setValueCount(valueCount); + for (int i = 0; i < valueCount; i++) { + vector.set(i, i + 1, (i + 1) * 10, (i + 1) * 100); + } + return vector; + }, + "IntervalMonthDayNanoVector" + }, + }); } - public ArrowFlightJdbcIntervalVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + public ArrowFlightJdbcIntervalVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -135,21 +146,27 @@ public void tearDown() { @Test public void testShouldGetObjectReturnValidObject() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getObject, (accessor, currentRow) -> is(getExpectedObject(vector, currentRow))); } @Test public void testShouldGetObjectPassingObjectClassAsParameterReturnValidObject() throws Exception { Class objectClass = getExpectedObjectClassForVector(vector); - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getObject(objectClass), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getObject(objectClass), (accessor, currentRow) -> is(getExpectedObject(vector, currentRow))); } @Test public void testShouldGetObjectReturnNull() throws Exception { setAllNullOnVector(vector); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getObject, (accessor, currentRow) -> equalTo(null)); } @@ -165,15 +182,19 @@ private String getStringOnVector(ValueVector vector, int index) { String iso8601IntervalString = ((PeriodDuration) object).toISO8601IntervalString(); String[] periodAndDuration = iso8601IntervalString.split("T"); if (periodAndDuration.length == 1) { - // If there is no 'T', then either Period or Duration is zero, and the other one will successfully parse it + // If there is no 'T', then either Period or Duration is zero, and the other one will + // successfully parse it String periodOrDuration = periodAndDuration[0]; try { - return new PeriodDuration(Period.parse(periodOrDuration), Duration.ZERO).toISO8601IntervalString(); + return new PeriodDuration(Period.parse(periodOrDuration), Duration.ZERO) + .toISO8601IntervalString(); } catch (DateTimeParseException e) { - return new PeriodDuration(Period.ZERO, Duration.parse(periodOrDuration)).toISO8601IntervalString(); + return new PeriodDuration(Period.ZERO, Duration.parse(periodOrDuration)) + .toISO8601IntervalString(); } } else { - // If there is a 'T', both Period and Duration are non-zero, and we just need to prepend the 'PT' to the + // If there is a 'T', both Period and Duration are non-zero, and we just need to prepend the + // 'PT' to the // duration for both to parse successfully Period parse = Period.parse(periodAndDuration[0]); Duration duration = Duration.parse("PT" + periodAndDuration[1]); @@ -184,7 +205,7 @@ private String getStringOnVector(ValueVector vector, int index) { } @Test - public void testShouldGetIntervalYear( ) { + public void testShouldGetIntervalYear() { assertEquals("-002-00", formatIntervalYear(Period.parse("P-2Y"))); assertEquals("-001-01", formatIntervalYear(Period.parse("P-1Y-1M"))); assertEquals("-001-02", formatIntervalYear(Period.parse("P-1Y-2M"))); @@ -200,19 +221,22 @@ public void testShouldGetIntervalYear( ) { } @Test - public void testShouldGetIntervalDay( ) { + public void testShouldGetIntervalDay() { assertEquals("-001 00:00:00.000", formatIntervalDay(Duration.parse("PT-24H"))); assertEquals("+001 00:00:00.000", formatIntervalDay(Duration.parse("PT+24H"))); assertEquals("-000 01:00:00.000", formatIntervalDay(Duration.parse("PT-1H"))); - // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and nanos" not fixed on JDK8 - //assertEquals("-000 01:00:00.001", formatIntervalDay(Duration.parse("PT-1H-0M-00.001S"))); + // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and + // nanos" not fixed on JDK8 + // assertEquals("-000 01:00:00.001", formatIntervalDay(Duration.parse("PT-1H-0M-00.001S"))); assertEquals("-000 01:00:00.001", formatIntervalDay(Duration.ofHours(-1).minusMillis(1))); assertEquals("-000 01:01:01.000", formatIntervalDay(Duration.parse("PT-1H-1M-1S"))); assertEquals("-000 02:02:02.002", formatIntervalDay(Duration.parse("PT-2H-2M-02.002S"))); assertEquals("-000 23:59:59.999", formatIntervalDay(Duration.parse("PT-23H-59M-59.999S"))); - // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and nanos" not fixed on JDK8 - //assertEquals("-000 11:59:00.100", formatIntervalDay(Duration.parse("PT-11H-59M-00.100S"))); - assertEquals("-000 11:59:00.100", + // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and + // nanos" not fixed on JDK8 + // assertEquals("-000 11:59:00.100", formatIntervalDay(Duration.parse("PT-11H-59M-00.100S"))); + assertEquals( + "-000 11:59:00.100", formatIntervalDay(Duration.ofHours(-11).minusMinutes(59).minusMillis(100))); assertEquals("-000 05:02:03.000", formatIntervalDay(Duration.parse("PT-5H-2M-3S"))); assertEquals("-000 22:22:22.222", formatIntervalDay(Duration.parse("PT-22H-22M-22.222S"))); @@ -228,29 +252,32 @@ public void testShouldGetIntervalDay( ) { @Test public void testIntervalDayWithJodaPeriodObject() { - assertEquals("+1567 00:00:00.000", - formatIntervalDay(Duration.ofDays(1567))); - assertEquals("-1567 00:00:00.000", - formatIntervalDay(Duration.ofDays(-1567))); + assertEquals("+1567 00:00:00.000", formatIntervalDay(Duration.ofDays(1567))); + assertEquals("-1567 00:00:00.000", formatIntervalDay(Duration.ofDays(-1567))); } @Test public void testShouldGetStringReturnCorrectString() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getString, (accessor, currentRow) -> is(getStringOnVector(vector, currentRow))); } @Test public void testShouldGetStringReturnNull() throws Exception { setAllNullOnVector(vector); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getString, (accessor, currentRow) -> equalTo(null)); } @Test public void testShouldGetObjectClassReturnCorrectClass() throws Exception { Class expectedObjectClass = getExpectedObjectClassForVector(vector); - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcIntervalVectorAccessor::getObjectClass, (accessor, currentRow) -> equalTo(expectedObjectClass)); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java index 14997975ad2bf..4dfaaf9222445 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc.client.utils; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,7 +30,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; - import org.bouncycastle.openssl.jcajce.JcaPEMWriter; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,8 +40,7 @@ @RunWith(MockitoJUnitRunner.class) public class ClientAuthenticationUtilsTest { - @Mock - KeyStore keyStoreMock; + @Mock KeyStore keyStoreMock; @Test public void testGetCertificatesInputStream() throws IOException, KeyStoreException { @@ -61,29 +58,27 @@ public void testGetCertificatesInputStream() throws IOException, KeyStoreExcepti } @Test - public void testGetKeyStoreInstance() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetKeyStoreInstance() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic .when(() -> ClientAuthenticationUtils.getKeyStoreInstance(Mockito.any())) .thenReturn(keyStoreMock); KeyStore receiveKeyStore = ClientAuthenticationUtils.getKeyStoreInstance("test1"); - Mockito - .verify(keyStoreMock) - .load(null, null); + Mockito.verify(keyStoreMock).load(null, null); assertEquals(receiveKeyStore, keyStoreMock); } } @Test - public void testGetDefaultKeyStoreInstancePassword() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetDefaultKeyStoreInstancePassword() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic - .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) .thenReturn(keyStoreMock); KeyStore receiveKeyStore = ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit"); assertEquals(receiveKeyStore, keyStoreMock); @@ -91,8 +86,8 @@ public void testGetDefaultKeyStoreInstancePassword() throws IOException, } @Test - public void testGetDefaultKeyStoreInstanceNoPassword() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetDefaultKeyStoreInstanceNoPassword() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic @@ -103,44 +98,44 @@ public void testGetDefaultKeyStoreInstanceNoPassword() throws IOException, } } - @Test - public void testGetCertificateInputStreamFromMacSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromMacSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, false, true); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getKeyStoreInstance("KeychainStore")) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getKeyStoreInstance("KeychainStore")) .thenReturn(keyStoreMock); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getDefaultKeyStoreInstance("changeit")) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) .thenReturn(keyStoreMock); clientAuthenticationUtilsMockedStatic .when(ClientAuthenticationUtils::getKeystoreInputStream) .thenCallRealMethod(); keyStoreMockedStatic.when(KeyStore::getDefaultType).thenCallRealMethod(); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getCertificatesInputStream(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); assertEquals(inputStream, mock); } } @Test - public void testGetCertificateInputStreamFromWindowsSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromWindowsSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, true, false); keyStoreMockedStatic @@ -153,67 +148,74 @@ public void testGetCertificateInputStreamFromWindowsSystem() throws IOException, .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("test"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("test"); assertEquals(inputStream, mock); } } @Test - public void testGetCertificateInputStreamFromLinuxSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromLinuxSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); - try ( - MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, false, false); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getCertificatesInputStream(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getDefaultKeyStoreInstance(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance(Mockito.any())) .thenReturn(keyStoreMock); clientAuthenticationUtilsMockedStatic .when(ClientAuthenticationUtils::getKeystoreInputStream) .thenCallRealMethod(); keyStoreMockedStatic.when(KeyStore::getDefaultType).thenCallRealMethod(); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); assertEquals(inputStream, mock); inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem(null); assertEquals(inputStream, mock); } } - private MockedStatic createKeyStoreStaticMock() { - return Mockito.mockStatic(KeyStore.class, invocationOnMock -> { + return Mockito.mockStatic( + KeyStore.class, + invocationOnMock -> { Method method = invocationOnMock.getMethod(); if (method.getName().equals("getInstance")) { return invocationOnMock.callRealMethod(); } return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); - } - ); + }); } private MockedStatic createClientAuthenticationUtilsStaticMock() { - return Mockito.mockStatic(ClientAuthenticationUtils.class , invocationOnMock -> { - Method method = invocationOnMock.getMethod(); - if (method.getName().equals("getCertificateInputStreamFromSystem")) { - return invocationOnMock.callRealMethod(); - } - return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); - }); + return Mockito.mockStatic( + ClientAuthenticationUtils.class, + invocationOnMock -> { + Method method = invocationOnMock.getMethod(); + if (method.getName().equals("getCertificateInputStreamFromSystem")) { + return invocationOnMock.callRealMethod(); + } + return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); + }); } - private void setOperatingSystemMock(MockedStatic clientAuthenticationUtilsMockedStatic, - boolean isWindows, boolean isMac) { + private void setOperatingSystemMock( + MockedStatic clientAuthenticationUtilsMockedStatic, + boolean isWindows, + boolean isMac) { clientAuthenticationUtilsMockedStatic.when(ClientAuthenticationUtils::isMac).thenReturn(isMac); assertEquals(ClientAuthenticationUtils.isMac(), isMac); - clientAuthenticationUtilsMockedStatic.when(ClientAuthenticationUtils::isWindows).thenReturn(isWindows); + clientAuthenticationUtilsMockedStatic + .when(ClientAuthenticationUtils::isWindows) + .thenReturn(isWindows); assertEquals(ClientAuthenticationUtils.isWindows(), isWindows); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java index b2d55b1a6af6a..6578032bc7c05 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc.utils; import static org.apache.arrow.util.AutoCloseables.close; @@ -24,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.junit.After; import org.junit.Assume; @@ -39,13 +37,11 @@ @RunWith(Parameterized.class) public final class ArrowFlightConnectionPropertyTest { - @Mock - public Properties properties; + @Mock public Properties properties; private AutoCloseable mockitoResource; - @Parameter - public ArrowFlightConnectionProperty arrowFlightConnectionProperty; + @Parameter public ArrowFlightConnectionProperty arrowFlightConnectionProperty; @Before public void setUp() { @@ -59,21 +55,22 @@ public void tearDown() throws Exception { @Test public void testWrapIsUnsupported() { - ThrowableAssertionUtils.simpleAssertThrowableClass(UnsupportedOperationException.class, - () -> arrowFlightConnectionProperty.wrap(properties)); + ThrowableAssertionUtils.simpleAssertThrowableClass( + UnsupportedOperationException.class, () -> arrowFlightConnectionProperty.wrap(properties)); } @Test public void testRequiredPropertyThrows() { Assume.assumeTrue(arrowFlightConnectionProperty.required()); - ThrowableAssertionUtils.simpleAssertThrowableClass(IllegalStateException.class, - () -> arrowFlightConnectionProperty.get(new Properties())); + ThrowableAssertionUtils.simpleAssertThrowableClass( + IllegalStateException.class, () -> arrowFlightConnectionProperty.get(new Properties())); } @Test public void testOptionalPropertyReturnsDefault() { Assume.assumeTrue(!arrowFlightConnectionProperty.required()); - assertEquals(arrowFlightConnectionProperty.defaultValue(), + assertEquals( + arrowFlightConnectionProperty.defaultValue(), arrowFlightConnectionProperty.get(new Properties())); } @@ -82,7 +79,8 @@ public static List provideParameters() { final ArrowFlightConnectionProperty[] arrowFlightConnectionProperties = ArrowFlightConnectionProperty.values(); final List parameters = new ArrayList<>(arrowFlightConnectionProperties.length); - for (final ArrowFlightConnectionProperty arrowFlightConnectionProperty : arrowFlightConnectionProperties) { + for (final ArrowFlightConnectionProperty arrowFlightConnectionProperty : + arrowFlightConnectionProperties) { parameters.add(new Object[] {arrowFlightConnectionProperty}); } return parameters; diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java index 6915536cdf2bd..a13839a66fd7a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.driver.jdbc.utils; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -22,9 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import com.google.common.collect.ImmutableList; import java.util.List; import java.util.stream.Collectors; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VarBinaryVector; @@ -38,12 +37,9 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class VectorSchemaRootTransformerTest { - @Rule - public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); + @Rule public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); private final BufferAllocator rootAllocator = rootAllocatorTestRule.getRootAllocator(); @Test @@ -53,11 +49,10 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final VarBinaryVector field3 = rootAllocatorTestRule.createVarBinaryVector("FIELD_3"); try (final VectorSchemaRoot originalRoot = VectorSchemaRoot.of(field1, field2, field3); - final VectorSchemaRoot clonedRoot = cloneVectorSchemaRoot(originalRoot)) { + final VectorSchemaRoot clonedRoot = cloneVectorSchemaRoot(originalRoot)) { final VectorSchemaRootTransformer.Builder builder = - new VectorSchemaRootTransformer.Builder(originalRoot.getSchema(), - rootAllocator); + new VectorSchemaRootTransformer.Builder(originalRoot.getSchema(), rootAllocator); builder.renameFieldVector("FIELD_3", "FIELD_3_RENAMED"); builder.addEmptyField("EMPTY_FIELD", new ArrowType.Bool()); @@ -66,12 +61,13 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final VectorSchemaRootTransformer transformer = builder.build(); - final Schema transformedSchema = new Schema(ImmutableList.of( - Field.nullable("FIELD_3_RENAMED", new ArrowType.Binary()), - Field.nullable("EMPTY_FIELD", new ArrowType.Bool()), - Field.nullable("FIELD_2_RENAMED", new ArrowType.Binary()), - Field.nullable("FIELD_1_RENAMED", new ArrowType.Binary()) - )); + final Schema transformedSchema = + new Schema( + ImmutableList.of( + Field.nullable("FIELD_3_RENAMED", new ArrowType.Binary()), + Field.nullable("EMPTY_FIELD", new ArrowType.Bool()), + Field.nullable("FIELD_2_RENAMED", new ArrowType.Binary()), + Field.nullable("FIELD_1_RENAMED", new ArrowType.Binary()))); try (final VectorSchemaRoot transformedRoot = createVectorSchemaRoot(transformedSchema)) { assertSame(transformedRoot, transformer.transform(clonedRoot, transformedRoot)); assertEquals(transformedSchema, transformedRoot.getSchema()); @@ -79,12 +75,9 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final int rowCount = originalRoot.getRowCount(); assertEquals(rowCount, transformedRoot.getRowCount()); - final VarBinaryVector originalField1 = - (VarBinaryVector) originalRoot.getVector("FIELD_1"); - final VarBinaryVector originalField2 = - (VarBinaryVector) originalRoot.getVector("FIELD_2"); - final VarBinaryVector originalField3 = - (VarBinaryVector) originalRoot.getVector("FIELD_3"); + final VarBinaryVector originalField1 = (VarBinaryVector) originalRoot.getVector("FIELD_1"); + final VarBinaryVector originalField2 = (VarBinaryVector) originalRoot.getVector("FIELD_2"); + final VarBinaryVector originalField3 = (VarBinaryVector) originalRoot.getVector("FIELD_3"); final VarBinaryVector transformedField1 = (VarBinaryVector) transformedRoot.getVector("FIELD_1_RENAMED"); @@ -115,9 +108,10 @@ private VectorSchemaRoot cloneVectorSchemaRoot(final VectorSchemaRoot originalRo } private VectorSchemaRoot createVectorSchemaRoot(final Schema schema) { - final List fieldVectors = schema.getFields().stream() - .map(field -> field.createVector(rootAllocator)) - .collect(Collectors.toList()); + final List fieldVectors = + schema.getFields().stream() + .map(field -> field.createVector(rootAllocator)) + .collect(Collectors.toList()); return new VectorSchemaRoot(fieldVectors); } }