diff --git a/client/trino-client/src/test/java/io/trino/client/uri/TestTrinoUri.java b/client/trino-client/src/test/java/io/trino/client/uri/TestTrinoUri.java index 1a25e64596a4..bb4e5a63cc1e 100644 --- a/client/trino-client/src/test/java/io/trino/client/uri/TestTrinoUri.java +++ b/client/trino-client/src/test/java/io/trino/client/uri/TestTrinoUri.java @@ -199,18 +199,6 @@ public void testInvalidUrls() "Provided connection properties are invalid:\n" + "Connection property assumeLiteralNamesInMetadataCallsForNonConformingClients cannot be set if assumeLiteralUnderscoreInMetadataCallsForNonConformingClients is enabled\n" + "Connection property assumeLiteralUnderscoreInMetadataCallsForNonConformingClients cannot be set if assumeLiteralNamesInMetadataCallsForNonConformingClients is enabled"); - - // invalid validateConnection - assertInvalid("trino://localhost:8080?validateConnection=0", "Connection property validateConnection value is invalid: 0"); - assertInvalid("trino://localhost:8080?validateConnection=1", "Connection property validateConnection value is invalid: 1"); - assertInvalid("trino://localhost:8080?validateConnection=-1", "Connection property validateConnection value is invalid: -1"); - assertInvalid("trino://localhost:8080?validateConnection=yes", "Connection property validateConnection value is invalid: yes"); - assertInvalid("trino://localhost:8080?validateConnection=no", "Connection property validateConnection value is invalid: no"); - assertInvalid("trino://localhost:8080?validateConnection=on", "Connection property validateConnection value is invalid: on"); - assertInvalid("trino://localhost:8080?validateConnection=off", "Connection property validateConnection value is invalid: off"); - assertInvalid("trino://localhost:8080?validateConnection=T", "Connection property validateConnection value is invalid: T"); - assertInvalid("trino://localhost:8080?validateConnection=F", "Connection property validateConnection value is invalid: F"); - assertInvalid("trino://localhost:8080?validateConnection=abc", "Connection property validateConnection value is invalid: abc"); } @Test diff --git a/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java b/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java index 7a648cd4b750..0c4a3ca86ada 100644 --- a/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java +++ b/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java @@ -172,7 +172,7 @@ public class TrinoConnection uri.getExplicitPrepare().ifPresent(value -> this.useExplicitPrepare = value); uri.getAssumeNullCatalogMeansCurrentCatalog().ifPresent(value -> this.assumeNullCatalogMeansCurrentCatalog = value); - validateConnection = uri.isValidateConnection(); + this.validateConnection = uri.isValidateConnection(); if (validateConnection) { try { if (!validateCredentials(CONNECTION_TIMEOUT_SECONDS)) { @@ -186,7 +186,7 @@ public class TrinoConnection } private boolean validateCredentials(int timeout) - throws IOException + throws IOException, UnsupportedOperationException { HttpUrl url = HttpUrl.get(httpUri); url = url.newBuilder().encodedPath("/v1/statement").build(); @@ -216,18 +216,18 @@ private boolean validateCredentials(int timeout) case HTTP_BAD_METHOD: throw new UnsupportedOperationException("Target server does not support HEAD /v1/statement"); default: - throw new IOException(format("Unexpected HTTP status code %d returned from HEAD " + + throw new IOException(format("Unexpected HTTP status code %d returned for HEAD " + "/v1/statement", response.code())); } } - catch (IOException ioe) { - if (getCausalChain(ioe).stream() - .anyMatch(e -> (e instanceof InterruptedIOException - || e instanceof ProtocolException))) { - lastException = ioe; + catch (IOException e) { + if (getCausalChain(e).stream() + .anyMatch(th -> th instanceof InterruptedIOException && th.getMessage().equals("timeout") + || th instanceof ProtocolException)) { + lastException = e; } else { - throw ioe; + throw e; } } @@ -624,9 +624,8 @@ public boolean isValid(int timeout) return validateCredentials(timeout); } catch (UnsupportedOperationException e) { - // Backward compatible with older Trino server logger.log(Level.FINE, "Remote server does not support validating connection.", e); - return true; + return false; } catch (IOException e) { logger.log(Level.FINE, "Validating connection failed.", e);