Skip to content

Commit 2018ac0

Browse files
committed
Add test
1 parent 3c2c004 commit 2018ac0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.arrow.driver.jdbc;
1818

19+
import static org.junit.jupiter.api.Assertions.assertFalse;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021
import static org.junit.jupiter.api.Assertions.assertThrows;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -26,6 +27,7 @@
2627
import java.sql.Driver;
2728
import java.sql.DriverManager;
2829
import java.sql.SQLException;
30+
import java.sql.Statement;
2931
import java.util.Properties;
3032
import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication;
3133
import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler;
@@ -622,4 +624,40 @@ public void testJdbcDriverVersionIntegration() throws Exception {
622624
"Expected: " + expectedUserAgent + " but found: " + actualUserAgent);
623625
}
624626
}
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+
}
625663
}

0 commit comments

Comments
 (0)