|
16 | 16 | */ |
17 | 17 | package org.apache.arrow.driver.jdbc; |
18 | 18 |
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertThrows; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertTrue; |
|
26 | 27 | import java.sql.Driver; |
27 | 28 | import java.sql.DriverManager; |
28 | 29 | import java.sql.SQLException; |
| 30 | +import java.sql.Statement; |
29 | 31 | import java.util.Properties; |
30 | 32 | import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; |
31 | 33 | import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; |
@@ -622,4 +624,40 @@ public void testJdbcDriverVersionIntegration() throws Exception { |
622 | 624 | "Expected: " + expectedUserAgent + " but found: " + actualUserAgent); |
623 | 625 | } |
624 | 626 | } |
| 627 | + |
| 628 | + @Test |
| 629 | + public void testStatementsClosedOnConnectionClose() throws Exception { |
| 630 | + // create a connection |
| 631 | + final Properties properties = new Properties(); |
| 632 | + properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); |
| 633 | + properties.put( |
| 634 | + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_EXTENSION.getPort()); |
| 635 | + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); |
| 636 | + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); |
| 637 | + properties.put("useEncryption", false); |
| 638 | + |
| 639 | + Connection connection = |
| 640 | + DriverManager.getConnection( |
| 641 | + "jdbc:arrow-flight-sql://" |
| 642 | + + FLIGHT_SERVER_TEST_EXTENSION.getHost() |
| 643 | + + ":" |
| 644 | + + FLIGHT_SERVER_TEST_EXTENSION.getPort(), |
| 645 | + properties); |
| 646 | + |
| 647 | + // create some statements |
| 648 | + int numStatements = 3; |
| 649 | + Statement[] statements = new Statement[numStatements]; |
| 650 | + for (int i = 0; i < numStatements; i++) { |
| 651 | + statements[i] = connection.createStatement(); |
| 652 | + assertFalse(statements[i].isClosed()); |
| 653 | + } |
| 654 | + |
| 655 | + // close the connection |
| 656 | + connection.close(); |
| 657 | + |
| 658 | + // assert the statements are closed |
| 659 | + for (int i = 0; i < numStatements; i++) { |
| 660 | + assertTrue(statements[i].isClosed()); |
| 661 | + } |
| 662 | + } |
625 | 663 | } |
0 commit comments