Skip to content

Conversation

@enqueue
Copy link
Contributor

@enqueue enqueue commented Jul 10, 2025

Summary

The API doc for Connection says:

Returns true if the connection has not been closed and is still valid. The driver shall submit a query on the connection or use some other mechanism that positively verifies the connection is still valid when this method is called.

  1. Do not throw Exception when connection is closed.
  2. Check that connection may be used to perform queries.

Client already provides ping method with timeout which is used here.

Closes #2472

Checklist

@windsurf-bot
Copy link
Contributor

windsurf-bot bot commented Jul 10, 2025

PR review rate limit exceeded

@mshustov mshustov requested review from chernser and Copilot July 10, 2025 08:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the Connection#isValid(int) method to correctly return false for closed connections and to use the client’s ping mechanism, and it adds integration tests for both closed and invalid-credential scenarios.

  • Replace placeholder implementation of isValid with real logic (check closed, call client.ping)
  • Add two integration tests covering closed connections and wrong credentials
  • Change createValidDatabaseNames DataProvider to private static

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java Implement isValid(int): handle closed state and delegate to ping
jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java Add tests for closed/invalid connections and adjust DataProvider visibility
Comments suppressed due to low confidence (3)

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:491

  • The negative timeout branch (timeout < 0) isn't covered by existing tests. Add a unit test that verifies isValid(-1) throws the expected SQLException.
        if (timeout < 0) {

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:490

  • [nitpick] Update the Javadoc for isValid(int) to explain the behavior when the connection is closed and that it delegates to client.ping under the hood, in line with the JDBC API contract.
    public boolean isValid(int timeout) throws SQLException {

jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java:597

  • TestNG DataProvider methods are typically required to be public; making this method private may prevent the framework from discovering it. Consider reverting to public static visibility.
    private static Object[][] createValidDatabaseNames() {

@chernser chernser merged commit 539fd94 into ClickHouse:main Jul 15, 2025
29 of 45 checks passed
@enqueue enqueue deleted the connection_isvalid branch July 15, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Result of connection.isValid() returned true even incorrect credentials provided

2 participants