xborder commented on code in PR #1090:
URL: https://github.com/apache/arrow-java/pull/1090#discussion_r4527109953


##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java:
##########
@@ -235,6 +235,44 @@ public void 
testShouldCloseStatementWhenIsCloseOnCompletion() throws Exception {
     }
   }
 
+  @Test
+  public void 
testCloseOnCompletionUnregistersDirectStatementWhenResultSetClosedEarly()
+      throws Exception {
+    try (Statement statement = connection.createStatement()) {
+      final ResultSet resultSet =
+          
statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD);
+      statement.closeOnCompletion();
+
+      resultSet.close();
+
+      assertThat(statement.isClosed(), is(true));
+      assertThat(isStatementOwner(statement), is(false));
+    }
+  }
+
+  @Test
+  public void 
testCloseOnCompletionUnregistersPreparedStatementWhenResultSetClosedEarly()
+      throws Exception {
+    try (PreparedStatement statement =
+        
connection.prepareStatement(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) {
+      final ResultSet resultSet = statement.executeQuery();
+      statement.closeOnCompletion();
+
+      resultSet.close();
+
+      assertThat(statement.isClosed(), is(true));
+      assertThat(isStatementOwner(statement), is(false));
+    }
+  }
+
+  private static boolean isStatementOwner(final Statement statement)
+      throws ReflectiveOperationException {
+    final java.lang.reflect.Field statementOwnersField =
+        ArrowFlightConnection.class.getDeclaredField("statementOwners");
+    statementOwnersField.setAccessible(true);
+    return ((Set<?>) statementOwnersField.get(connection)).contains(statement);

Review Comment:
   done. replaced reflection with a package-private @VisibleForTesting accessor 
instead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to