This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new e5978d545 GH-66: [JDBC] Add test for closing a connection with a 
catalog twice (#1503)
e5978d545 is described below

commit e5978d54574c458341b936fd46312030da8122e1
Author: Abhishek Pathania <[email protected]>
AuthorDate: Thu Nov 19 19:39:01 2026 +0530

    GH-66: [JDBC] Add test for closing a connection with a catalog twice (#1503)
    
    ## What's Changed
    
    Adds a regression test for #66: closing a connection that was opened
    with a `catalog` twice no longer throws, and `CloseSession` reaches the
    server only once. The original failure is already fixed on main. #933
    removed the duplicate `ArrowFlightSqlClientHandler#close` call, and the
    second `CloseSession` on the shut-down channel now fails with
    `UNAVAILABLE`, which #910 suppresses.
    
    `MockFlightSqlProducer` now implements `closeSession` so the test can
    count the calls.
    
    The test was drafted with an AI assistant (Claude). I reviewed it and
    checked that it passes on main.
    
    Closes #66.
---
 .../apache/arrow/driver/jdbc/ConnectionTest.java   | 22 ++++++++++++++++++++++
 .../driver/jdbc/utils/MockFlightSqlProducer.java   | 19 +++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
index 1fb0eba65..ca9ae1adf 100644
--- 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
+++ 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
@@ -683,6 +683,28 @@ public class ConnectionTest {
     }
   }
 
+  @Test
+  public void testCloseTwiceWithCatalogClosesSessionOnce() throws Exception {
+    final Properties properties = new Properties();
+    properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
+    properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), 
passTest);
+    properties.put(ArrowFlightConnectionProperty.CATALOG.camelName(), 
"test_catalog");
+    properties.put("useEncryption", false);
+    final int closeSessionCountBefore = PRODUCER.getCloseSessionCount();
+
+    final Connection connection =
+        DriverManager.getConnection(
+            "jdbc:arrow-flight-sql://"
+                + FLIGHT_SERVER_TEST_EXTENSION.getHost()
+                + ":"
+                + FLIGHT_SERVER_TEST_EXTENSION.getPort(),
+            properties);
+    connection.close();
+    connection.close();
+
+    assertEquals(closeSessionCountBefore + 1, PRODUCER.getCloseSessionCount());
+  }
+
   @Test
   public void testStatementsClosedOnConnectionClose() throws Exception {
     // create a connection
diff --git 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java
 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java
index 36c07ce5d..c764a1c01 100644
--- 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java
+++ 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java
@@ -40,11 +40,14 @@ import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.stream.IntStream;
 import org.apache.arrow.flight.Action;
 import org.apache.arrow.flight.CallStatus;
+import org.apache.arrow.flight.CloseSessionRequest;
+import org.apache.arrow.flight.CloseSessionResult;
 import org.apache.arrow.flight.Criteria;
 import org.apache.arrow.flight.FlightDescriptor;
 import org.apache.arrow.flight.FlightEndpoint;
@@ -758,6 +761,22 @@ public final class MockFlightSqlProducer implements 
FlightSqlProducer {
     return sessionOptions;
   }
 
+  private final AtomicInteger closeSessionCount = new AtomicInteger();
+
+  @Override
+  public void closeSession(
+      final CloseSessionRequest request,
+      final CallContext context,
+      final StreamListener<CloseSessionResult> listener) {
+    closeSessionCount.incrementAndGet();
+    listener.onNext(new CloseSessionResult(CloseSessionResult.Status.CLOSED));
+    listener.onCompleted();
+  }
+
+  public int getCloseSessionCount() {
+    return closeSessionCount.get();
+  }
+
   private static final class TicketConversionUtils {
     private TicketConversionUtils() {
       // Prevent instantiation.

Reply via email to