-
Notifications
You must be signed in to change notification settings - Fork 208
test(java/driver/jni): add more integration/unit tests #4440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
...validation/src/test/java/org/apache/arrow/adbc/driver/jni/MultiDriverIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.arrow.adbc.driver.jni; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.apache.arrow.adbc.core.AdbcConnection; | ||
| import org.apache.arrow.adbc.core.AdbcDatabase; | ||
| import org.apache.arrow.adbc.core.AdbcDriver; | ||
| import org.apache.arrow.adbc.core.AdbcException; | ||
| import org.apache.arrow.adbc.driver.testsuite.ArrowToJava; | ||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.memory.RootAllocator; | ||
| import org.apache.arrow.util.AutoCloseables; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Assumptions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Integration test that uses multiple drivers simultaneously. */ | ||
| public class MultiDriverIntegrationTest { | ||
| BufferAllocator allocator; | ||
| JniDriver driver; | ||
|
|
||
| AdbcDatabase pgDb, mssqlDb, fsqlDb; | ||
| AdbcConnection pgConn, mssqlConn, fsqlConn; | ||
|
|
||
| @BeforeAll | ||
| static void beforeAll() { | ||
| Assumptions.assumeFalse( | ||
| FlightSqlSqliteIntegrationTest.URI == null || FlightSqlSqliteIntegrationTest.URI.isEmpty(), | ||
| String.format("Must set %s", FlightSqlSqliteIntegrationTest.URI_ENV)); | ||
| Assumptions.assumeFalse( | ||
| PostgresIntegrationTest.URI == null || PostgresIntegrationTest.URI.isEmpty(), | ||
| String.format("Must set %s", PostgresIntegrationTest.URI_ENV)); | ||
| Assumptions.assumeFalse( | ||
| SqlServerIntegrationTest.URI == null || SqlServerIntegrationTest.URI.isEmpty(), | ||
| String.format("Must set %s", SqlServerIntegrationTest.URI_ENV)); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void beforeEach() throws Exception { | ||
| allocator = new RootAllocator(); | ||
| driver = new JniDriver(allocator); | ||
|
|
||
| { | ||
| System.err.println( | ||
| "Connecting to Flight SQL with URI: " + FlightSqlSqliteIntegrationTest.URI); | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "adbc_driver_flightsql"); | ||
| AdbcDriver.PARAM_URI.set(parameters, FlightSqlSqliteIntegrationTest.URI); | ||
| fsqlDb = driver.open(parameters); | ||
| fsqlConn = fsqlDb.connect(); | ||
| } | ||
| { | ||
| System.err.println("Connecting to MSSQL with URI: " + SqlServerIntegrationTest.URI); | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "mssql"); | ||
| AdbcDriver.PARAM_URI.set(parameters, SqlServerIntegrationTest.URI); | ||
| mssqlDb = driver.open(parameters); | ||
| mssqlConn = mssqlDb.connect(); | ||
| } | ||
| { | ||
| System.err.println("Connecting to PostgreSQL with URI: " + PostgresIntegrationTest.URI); | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "adbc_driver_postgresql"); | ||
| AdbcDriver.PARAM_URI.set(parameters, PostgresIntegrationTest.URI); | ||
| pgDb = driver.open(parameters); | ||
| pgConn = pgDb.connect(); | ||
| } | ||
| } | ||
|
|
||
| @AfterEach | ||
| void afterEach() throws Exception { | ||
| AutoCloseables.close(pgConn, mssqlConn, fsqlConn, pgDb, mssqlDb, fsqlDb, allocator); | ||
| } | ||
|
|
||
| @Test | ||
| void queryAll() throws Exception { | ||
| try (var pgStmt = pgConn.createStatement(); | ||
| var mssqlStmt = mssqlConn.createStatement(); | ||
| var fsqlStmt = fsqlConn.createStatement()) { | ||
| pgStmt.setSqlQuery("SELECT 1 as foo"); | ||
| mssqlStmt.setSqlQuery("SELECT 1 as bar"); | ||
| fsqlStmt.setSqlQuery("SELECT 1 as baz"); | ||
|
|
||
| try (var pgRes = pgStmt.executeQuery(); | ||
| var mssqlRes = mssqlStmt.executeQuery(); | ||
| var fsqlRes = fsqlStmt.executeQuery()) { | ||
| assertThat(ArrowToJava.toIntegers(pgRes.getReader(), "foo")).containsExactly(1); | ||
| assertThat(ArrowToJava.toIntegers(mssqlRes.getReader(), "bar")).containsExactly(1); | ||
| assertThat(ArrowToJava.toLongs(fsqlRes.getReader(), "baz")).containsExactly(1L); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void errorDriverDoesNotExist() { | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "thisdriverdoesnotexist"); | ||
| assertThatThrownBy( | ||
| () -> { | ||
| try (var db = driver.open(parameters)) {} | ||
| }) | ||
| .isInstanceOf(AdbcException.class); | ||
| } | ||
|
|
||
| @Test | ||
| void errorFailedConnection() throws Exception { | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "mssql"); | ||
| AdbcDriver.PARAM_URI.set(parameters, "mssql://localhost:9999"); | ||
| try (var db = driver.open(parameters)) { | ||
| assertThatThrownBy(db::connect).hasMessageContaining("Could not get connection"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void errorBadConnectionParameter() throws Exception { | ||
| Map<String, Object> parameters = new HashMap<>(); | ||
| JniDriver.PARAM_DRIVER.set(parameters, "mssql"); | ||
| parameters.put("this parameter does not exist", ""); | ||
| AdbcDriver.PARAM_URI.set(parameters, "mssql://localhost:9999"); | ||
| assertThatThrownBy(() -> driver.open(parameters)) | ||
| .hasMessageContaining("Unknown database option"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
java/driver/jni/src/test/java/org/apache/arrow/adbc/driver/jni/impl/ImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.arrow.adbc.driver.jni.impl; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class ImplTest { | ||
| @Test | ||
| void emptyHeap() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.allocate(0); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
|
|
||
| buf = ByteBuffer.allocate(16); | ||
| buf.position(16); | ||
| assertThat(buf.remaining()).isEqualTo(0); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void emptyDirect() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.allocateDirect(0); | ||
| assertThat(buf.isDirect()).isTrue(); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
|
|
||
| buf = ByteBuffer.allocateDirect(16); | ||
| assertThat(buf.isDirect()).isTrue(); | ||
| buf.position(16); | ||
| assertThat(buf.remaining()).isEqualTo(0); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void emptyArray() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.wrap(new byte[0]); | ||
| assertThat(buf.hasArray()).isTrue(); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
|
|
||
| buf = ByteBuffer.wrap(new byte[16]); | ||
| buf.position(16); | ||
| assertThat(buf.hasArray()).isTrue(); | ||
| assertThat(buf.remaining()).isEqualTo(0); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void emptySlow() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.wrap(new byte[0]).asReadOnlyBuffer(); | ||
| // take the slow path | ||
| assertThat(buf.hasArray()).isFalse(); | ||
| assertThat(buf.isDirect()).isFalse(); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
|
|
||
| buf = ByteBuffer.wrap(new byte[16]); | ||
| buf.position(16); | ||
| buf = buf.asReadOnlyBuffer(); | ||
| assertThat(buf.hasArray()).isFalse(); | ||
| assertThat(buf.isDirect()).isFalse(); | ||
| assertThat(buf.remaining()).isEqualTo(0); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void offsetHeap() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.allocate(4); | ||
| buf.put((byte) 0); | ||
| buf.put((byte) 1); | ||
| buf.put((byte) 2); | ||
| buf.put((byte) 3); | ||
| buf.position(1); | ||
| assertThat(buf.remaining()).isEqualTo(3); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEqualTo(new byte[] {1, 2, 3}); | ||
| } | ||
|
|
||
| @Test | ||
| void offsetDirect() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.allocateDirect(4); | ||
| buf.put((byte) 0); | ||
| buf.put((byte) 1); | ||
| buf.put((byte) 2); | ||
| buf.put((byte) 3); | ||
| buf.position(1); | ||
| assertThat(buf.remaining()).isEqualTo(3); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEqualTo(new byte[] {1, 2, 3}); | ||
| } | ||
|
|
||
| @Test | ||
| void offsetArray() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.wrap(new byte[] {(byte) 0, (byte) 1, (byte) 2, (byte) 3}); | ||
| buf.position(1); | ||
| assertThat(buf.hasArray()).isTrue(); | ||
| assertThat(buf.remaining()).isEqualTo(3); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEqualTo(new byte[] {1, 2, 3}); | ||
| } | ||
|
|
||
| @Test | ||
| void offsetSlow() throws Exception { | ||
| ByteBuffer buf = ByteBuffer.wrap(new byte[] {(byte) 0, (byte) 1, (byte) 2, (byte) 3}); | ||
| buf.position(1); | ||
| buf = buf.asReadOnlyBuffer(); | ||
| assertThat(buf.hasArray()).isFalse(); | ||
| assertThat(buf.isDirect()).isFalse(); | ||
| assertThat(buf.remaining()).isEqualTo(3); | ||
| assertThat(JniLoader.INSTANCE.internalGetByteBuffer(buf)).isEqualTo(new byte[] {1, 2, 3}); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.