Repository navigation
GH-1502: [JDBC] Close the server session on Connection#close without a catalog #1504
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
base: main
Are you sure you want to change the base?
Changes from all commits
d78609c
0e381f8
e1d7f15
9a7ecdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,10 @@ | |
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doThrow; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
| import static org.mockito.Mockito.when; | ||
|
|
@@ -149,6 +151,46 @@ public void testCloseHandlesFlightRuntimeException( | |
| verify(sqlClient).close(); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource | ||
| public void testCloseSessionWithoutCatalog(FlightStatusCode code, boolean shouldSuppress) | ||
| throws Exception { | ||
| FlightSqlClient sqlClient = mock(FlightSqlClient.class); | ||
| doThrow(new CallStatus(code, null, null, null).toRuntimeException()) | ||
| .when(sqlClient) | ||
| .closeSession(any(CloseSessionRequest.class), any(CallOption[].class)); | ||
| ArrowFlightSqlClientHandler sqlClientHandler = | ||
| new ArrowFlightSqlClientHandler( | ||
| "cacheKey", | ||
| sqlClient, | ||
| new ArrowFlightSqlClientHandler.Builder(), | ||
| new ArrayList<>(), | ||
| Optional.empty(), | ||
| null); | ||
|
|
||
| if (shouldSuppress) { | ||
| assertDoesNotThrow(sqlClientHandler::close); | ||
| } else { | ||
| assertThrows(SQLException.class, sqlClientHandler::close); | ||
| } | ||
| verify(sqlClient) | ||
| .closeSession( | ||
| any(CloseSessionRequest.class), eq(ArrowFlightSqlClientHandler.CLOSE_SESSION_TIMEOUT)); | ||
| verify(sqlClient).close(); | ||
| } | ||
|
|
||
| private static Object[] testCloseSessionWithoutCatalog() { | ||
| return new Object[] { | ||
| new Object[] {FlightStatusCode.UNIMPLEMENTED, true}, | ||
| new Object[] {FlightStatusCode.INVALID_ARGUMENT, true}, | ||
| new Object[] {FlightStatusCode.NOT_FOUND, true}, | ||
| new Object[] {FlightStatusCode.UNAVAILABLE, true}, | ||
| new Object[] {FlightStatusCode.UNAUTHENTICATED, true}, | ||
| new Object[] {FlightStatusCode.UNKNOWN, false}, | ||
| new Object[] {FlightStatusCode.TIMED_OUT, false}, | ||
| }; | ||
|
Comment on lines
+182
to
+191
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also include
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering this non-blocking as well — nice-to-have if you push another update, otherwise fine as is.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. Flight maps DEADLINE_EXCEEDED to TIMED_OUT, so the new row is {TIMED_OUT, false}. |
||
| } | ||
|
|
||
| private static Object[] testCloseHandlesFlightRuntimeException() { | ||
| CallStatus benignInternalError = | ||
| new CallStatus(FlightStatusCode.INTERNAL, null, "Connection closed after GOAWAY", null); | ||
|
|
@@ -168,4 +210,23 @@ private static Object[] testCloseHandlesFlightRuntimeException() { | |
| new Object[] {true, CallStatus.CANCELLED, false}, | ||
| }; | ||
| } | ||
|
|
||
| @Test | ||
| public void testCloseFromBuilderCopyDoesNotCloseSession() throws Exception { | ||
| FlightSqlClient sqlClient = mock(FlightSqlClient.class); | ||
| ArrowFlightSqlClientHandler sqlClientHandler = | ||
| new ArrowFlightSqlClientHandler( | ||
| "cacheKey", | ||
| sqlClient, | ||
| new ArrowFlightSqlClientHandler.Builder(new ArrowFlightSqlClientHandler.Builder()), | ||
| new ArrayList<>(), | ||
| Optional.of("test_catalog"), | ||
| null); | ||
|
|
||
| sqlClientHandler.close(); | ||
|
|
||
| verify(sqlClient, never()) | ||
| .closeSession(any(CloseSessionRequest.class), any(CallOption[].class)); | ||
| verify(sqlClient).close(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is catalog such a relevant piece of information here? I don't understand why close was only called when there was a catalog and I don't understand why we surpress errors if it is empty.
This seems tuned to a specific server implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xborder makes sense. I kept the catalog path as it was to keep the change small, but these statuses all mean there's no session to close, catalog or not. Happy to drop the catalog check so both work the same way.