diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HAConnectionWithMasterAndRPCRegistryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HAConnectionWithMasterAndRPCRegistryIT.java index 46674b61db8..6da09aaee6d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HAConnectionWithMasterAndRPCRegistryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HAConnectionWithMasterAndRPCRegistryIT.java @@ -37,6 +37,7 @@ import java.sql.SQLException; import java.util.*; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.RandomStringUtils; import org.apache.hadoop.hbase.util.VersionInfo; import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest; @@ -582,8 +583,14 @@ private Connection getFailoverConnection() throws SQLException { * Returns a Parallel Phoenix Connection * @return Parallel Phoenix Connection */ - private Connection getParallelConnection() throws SQLException { - return DriverManager.getConnection(CLUSTERS.getJdbcHAUrl(), parallelClientProperties); + private Connection getParallelConnection() throws Exception { + ParallelPhoenixConnection conn = (ParallelPhoenixConnection) DriverManager + .getConnection(CLUSTERS.getJdbcHAUrl(), parallelClientProperties); + // The parallel connection returns when one cluster connects. Wait for both clusters, so that + // the cluster change acts on two open connections. + conn.futureConnection1.get(60, TimeUnit.SECONDS); + conn.futureConnection2.get(60, TimeUnit.SECONDS); + return conn; } } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionIT.java index 4a0c518efea..09d3ef34b1a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionIT.java @@ -67,6 +67,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.RandomStringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; @@ -891,7 +892,12 @@ public void testAllWrappedConnectionsClosedAfterRegistryChangeToMaster() throws short numberOfConnections = 10; List connectionList = new ArrayList<>(numberOfConnections); for (short i = 0; i < numberOfConnections; i++) { - connectionList.add(getParallelConnection()); + ParallelPhoenixConnection conn = (ParallelPhoenixConnection) getParallelConnection(); + // The parallel connection returns when one cluster connects. Wait for both clusters, so + // that the registry change acts on two open connections. + conn.futureConnection1.get(60, TimeUnit.SECONDS); + conn.futureConnection2.get(60, TimeUnit.SECONDS); + connectionList.add(conn); } ConnectionQueryServicesImpl cqsi = (ConnectionQueryServicesImpl) PhoenixDriver.INSTANCE .getConnectionQueryServices(CLUSTERS.getJdbcUrl1(haGroup), clientProperties); @@ -929,7 +935,12 @@ public void testAllWrappedConnectionsClosedAfterRegistryChangeToRpc() throws Exc short numberOfConnections = 10; List connectionList = new ArrayList<>(numberOfConnections); for (short i = 0; i < numberOfConnections; i++) { - connectionList.add(getParallelConnection()); + ParallelPhoenixConnection conn = (ParallelPhoenixConnection) getParallelConnection(); + // The parallel connection returns when one cluster connects. Wait for both clusters, so + // that the registry change acts on two open connections. + conn.futureConnection1.get(60, TimeUnit.SECONDS); + conn.futureConnection2.get(60, TimeUnit.SECONDS); + connectionList.add(conn); } ConnectionQueryServicesImpl cqsi = (ConnectionQueryServicesImpl) PhoenixDriver.INSTANCE .getConnectionQueryServices(CLUSTERS.getJdbcUrl1(haGroup), clientProperties);