From 60a2926546d163123ee672a8b5580449bad1991d Mon Sep 17 00:00:00 2001 From: Nick Vercammen Date: Wed, 22 Jan 2020 19:58:27 +0100 Subject: [PATCH] SOLR-14205 Do not fail when given timeout to connectionImpl.isValid() = 0 Closes #1204 Signed-off-by: Kevin Risden --- solr/CHANGES.txt | 2 ++ .../org/apache/solr/client/solrj/io/sql/ConnectionImpl.java | 6 +++++- .../test/org/apache/solr/client/solrj/io/sql/JdbcTest.java | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index f8544552312..c135e903688 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -242,6 +242,8 @@ Bug Fixes * SOLR-14196: AdminUI login not working for JWTAuth when blockUnknown=false (janhoy) +* SOLR-14205: Do not fail when given timeout to connectionImpl.isValid() = 0 (Nick Vercammen via Kevin Risden) + Other Changes --------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java index 8e0466d203a..869387eacca 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ConnectionImpl.java @@ -335,7 +335,11 @@ class ConnectionImpl implements Connection { // check that the connection isn't closed and able to connect within the timeout try { if(!isClosed()) { - this.client.connect(timeout, TimeUnit.SECONDS); + if (timeout == 0) { + this.client.connect(); + } else { + this.client.connect(timeout, TimeUnit.SECONDS); + } return true; } } catch (InterruptedException|TimeoutException ignore) { diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java index c3b41e8cc21..9ae7aa992df 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java @@ -496,6 +496,8 @@ public class JdbcTest extends SolrCloudTestCase { private void testJDBCMethods(String collection, String connectionString, Properties properties, String sql) throws Exception { try (Connection con = DriverManager.getConnection(connectionString, properties)) { assertTrue(con.isValid(DEFAULT_CONNECTION_TIMEOUT)); + assertTrue("connection should be valid when checked with timeout = 0 -> con.isValid(0)", con.isValid(0)); + assertEquals(zkHost, con.getCatalog()); con.setCatalog(zkHost);