Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public Scanner scan(Scan scan) throws ExecutionException {
close(connection);
throw new ExecutionException(
CoreError.JDBC_ERROR_OCCURRED_IN_SELECTION.buildMessage(e.getMessage()), e);
} catch (Exception e) {
if (connection != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to connection.rollback() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I focused on the connection leak, but I think the transaction should be rolled-back immediately to avoid potential future lazy-recovery. Addressed it in e96888e.

close(connection);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null handling is already done in the close() method, so we don't need to do that here:

Suggested change
if (connection != null) {
close(connection);
}
close(connection);

throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th
verify(connection).close();
}

@Test
public void
whenScanOperationExecutedAndJdbcServiceThrowsIllegalArgumentException_shouldCloseConnectionAndThrowIllegalArgumentException()
throws Exception {
// Arrange
Exception cause = new IllegalArgumentException("Table not found");
// Simulate the table not found scenario.
when(jdbcService.getScanner(any(), any())).thenThrow(cause);

// Act Assert
assertThatThrownBy(
() -> {
Scan scan = new Scan(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.scan(scan);
})
.isInstanceOf(IllegalArgumentException.class);
verify(connection).close();
}

@Test
public void
whenScanOperationExecutedAndScannerClosed_SQLExceptionThrownByConnectionCommit_shouldThrowIOException()
Expand Down