Implement Connection#isValid#2490
Merged
chernser merged 3 commits intoClickHouse:mainfrom Jul 15, 2025
Merged
Conversation
Contributor
|
PR review rate limit exceeded |
There was a problem hiding this comment.
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
isValidwith real logic (check closed, callclient.ping) - Add two integration tests covering closed connections and wrong credentials
- Change
createValidDatabaseNamesDataProvider toprivate 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 verifiesisValid(-1)throws the expectedSQLException.
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 toclient.pingunder 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 staticvisibility.
private static Object[][] createValidDatabaseNames() {
chernser
approved these changes
Jul 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The API doc for Connection says:
Clientalready provides ping method with timeout which is used here.Closes #2472
Checklist