This is an automated email from the ASF dual-hosted git repository.
vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new d3499ef141 PHOENIX-7711 Make Phoenix test jar available for
consumption by applications (#2306)
d3499ef141 is described below
commit d3499ef141f80b1d8bc6f84e31894cb79cd4b00b
Author: Jing Yu <[email protected]>
AuthorDate: Mon Oct 20 14:10:40 2025 -0700
PHOENIX-7711 Make Phoenix test jar available for consumption by
applications (#2306)
---
.../phoenix/jdbc/FailoverPhoenixConnection.java | 2 +-
.../apache/phoenix/jdbc/HighAvailabilityGroup.java | 18 ++--
.../phoenix/jdbc/ParallelPhoenixConnection.java | 2 +-
.../phoenix/jdbc/ParallelPhoenixContext.java | 7 +-
.../jdbc/HighAvailabilityTestingUtility.java | 110 +++++++++++++++++++++
5 files changed, 128 insertions(+), 11 deletions(-)
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection.java
index aebd21586d..cac17115b7 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection.java
@@ -606,7 +606,7 @@ public class FailoverPhoenixConnection implements
PhoenixMonitoredConnection {
/** Returns the currently wrapped connection. */
@VisibleForTesting
- PhoenixConnection getWrappedConnection() {
+ public PhoenixConnection getWrappedConnection() {
return connection;
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java
index e45e9e99b0..5e522db88a 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java
@@ -136,15 +136,17 @@ public class HighAvailabilityGroup {
*/
@VisibleForTesting
static final Map<HAGroupInfo, HighAvailabilityGroup> GROUPS = new
ConcurrentHashMap<>();
- static final Map<HAGroupInfo, Set<HAURLInfo>> URLS = new
ConcurrentHashMap<>();
@VisibleForTesting
- static final Cache<HAGroupInfo, Boolean> MISSING_CRR_GROUPS_CACHE =
CacheBuilder.newBuilder()
- .expireAfterWrite(PHOENIX_HA_TRANSITION_TIMEOUT_MS_DEFAULT,
TimeUnit.MILLISECONDS).build();
+ public static final Map<HAGroupInfo, Set<HAURLInfo>> URLS = new
ConcurrentHashMap<>();
+ @VisibleForTesting
+ public static final Cache<HAGroupInfo, Boolean> MISSING_CRR_GROUPS_CACHE =
+ CacheBuilder.newBuilder()
+ .expireAfterWrite(PHOENIX_HA_TRANSITION_TIMEOUT_MS_DEFAULT,
TimeUnit.MILLISECONDS).build();
/**
* The Curator client cache, one client instance per cluster.
*/
@VisibleForTesting
- static final Cache<String,
+ public static final Cache<String,
CuratorFramework> CURATOR_CACHE = CacheBuilder.newBuilder()
.expireAfterAccess(DEFAULT_CLIENT_CONNECTION_CACHE_MAX_DURATION,
TimeUnit.MILLISECONDS)
.removalListener(
@@ -644,7 +646,8 @@ public class HighAvailabilityGroup {
}
/** Returns true if the given phoenix connection points to ACTIVE cluster,
else false */
- boolean isActive(PhoenixConnection connection) {
+ @VisibleForTesting
+ public boolean isActive(PhoenixConnection connection) {
if (state != State.READY || connection == null) {
return false;
}
@@ -687,11 +690,12 @@ public class HighAvailabilityGroup {
}
@VisibleForTesting
- HAGroupInfo getGroupInfo() {
+ public HAGroupInfo getGroupInfo() {
return info;
}
- Properties getProperties() {
+ @VisibleForTesting
+ public Properties getProperties() {
return properties;
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixConnection.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixConnection.java
index 1cfcee6347..5562b552a2 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixConnection.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixConnection.java
@@ -118,7 +118,7 @@ public class ParallelPhoenixConnection implements
PhoenixMonitoredConnection {
}
@VisibleForTesting
- ParallelPhoenixContext getContext() {
+ public ParallelPhoenixContext getContext() {
return this.context;
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixContext.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixContext.java
index 896582cc69..928ad2923b 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixContext.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ParallelPhoenixContext.java
@@ -38,6 +38,7 @@ import org.apache.phoenix.query.QueryServicesOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
/**
@@ -219,11 +220,13 @@ public class ParallelPhoenixContext {
return this.operationTimeoutMs;
}
- CompletableFuture<?> getChainOnConn1() {
+ @VisibleForTesting
+ public CompletableFuture<?> getChainOnConn1() {
return this.cluster1Context.getChainOnConn();
}
- CompletableFuture<?> getChainOnConn2() {
+ @VisibleForTesting
+ public CompletableFuture<?> getChainOnConn2() {
return this.cluster2Context.getChainOnConn();
}
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityTestingUtility.java
b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityTestingUtility.java
index 1a50e4f4aa..f87d57cbb9 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityTestingUtility.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityTestingUtility.java
@@ -784,4 +784,114 @@ public class HighAvailabilityTestingUtility {
properties.setProperty(HConstants.THREAD_WAKE_FREQUENCY, "100");
return properties;
}
+
+ /**
+ * Helper method to close HighAvailabilityGroup from external packages. This
is needed because
+ * HighAvailabilityGroup.close() is package-private.
+ * @param haGroup the HighAvailabilityGroup to close
+ */
+ @VisibleForTesting
+ public static void closeHighAvailabilityGroup(HighAvailabilityGroup haGroup)
{
+ if (haGroup != null) {
+ try {
+ haGroup.close();
+ } catch (Exception e) {
+ LOG.warn("Failed to close HighAvailabilityGroup", e);
+ }
+ }
+ }
+
+ /**
+ * Helper method to get wrapped connection from FailoverPhoenixConnection.
This is needed because
+ * FailoverPhoenixConnection.getWrappedConnection() is package-private.
+ * @param failoverConnection the FailoverPhoenixConnection
+ * @return the wrapped PhoenixConnection
+ */
+ public static PhoenixConnection
+ getWrappedConnection(FailoverPhoenixConnection failoverConnection) {
+ if (failoverConnection != null) {
+ return failoverConnection.getWrappedConnection();
+ }
+ return null;
+ }
+
+ /**
+ * Helper method to get ConnectionQueryServices from PhoenixDriver. This is
needed because
+ * PhoenixDriver.getConnectionQueryServices() has protected access.
+ * @param url the JDBC URL
+ * @param properties the connection properties
+ * @return the ConnectionQueryServices
+ * @throws SQLException if connection cannot be established
+ */
+ public static org.apache.phoenix.query.ConnectionQueryServices
+ getConnectionQueryServices(String url, Properties properties) throws
SQLException {
+ return PhoenixDriver.INSTANCE.getConnectionQueryServices(url, properties);
+ }
+
+ /**
+ * Helper method to get the PRINCIPAL constant from HBaseTestingUtilityPair.
This is needed
+ * because HBaseTestingUtilityPair.PRINCIPAL is package-private.
+ * @return the PRINCIPAL constant value
+ */
+ public static String getPrincipal() {
+ return HBaseTestingUtilityPair.PRINCIPAL;
+ }
+
+ /**
+ * Helper method to check if ConnectionInfo is in PhoenixDriver cache. This
is needed because
+ * PhoenixDriver.checkIfCQSIIsInCache() has protected access.
+ * @param connectionInfo the ConnectionInfo to check
+ * @return true if the ConnectionInfo is in cache, false otherwise
+ */
+ public static boolean checkIfCQSIIsInCache(ConnectionInfo connectionInfo) {
+ return PhoenixDriver.INSTANCE.checkIfCQSIIsInCache(connectionInfo);
+ }
+
+ /**
+ * Helper method to get HA group name from HighAvailabilityGroup. This is
needed because
+ * HAGroupInfo.getName() is defined in an inaccessible class.
+ * @param haGroup the HighAvailabilityGroup
+ * @return the HA group name
+ */
+ public static String getHAGroupName(HighAvailabilityGroup haGroup) {
+ if (haGroup != null && haGroup.getGroupInfo() != null) {
+ return haGroup.getGroupInfo().getName();
+ }
+ return null;
+ }
+
+ /**
+ * Helper method to connect to the active cluster in an HA group. This is
needed because
+ * HighAvailabilityGroup.connectActive() is package-private.
+ * @param haGroup the HighAvailabilityGroup
+ * @param properties the connection properties
+ * @param haurlInfo the HA URL info
+ * @return the PhoenixConnection to the active cluster
+ * @throws SQLException if connection cannot be established
+ */
+ public static PhoenixConnection connectActiveCluster(HighAvailabilityGroup
haGroup,
+ Properties properties, HAURLInfo haurlInfo) throws SQLException {
+ if (haGroup != null) {
+ return haGroup.connectActive(properties, haurlInfo);
+ }
+ return null;
+ }
+
+ /**
+ * Helper method to connect to a specific cluster in an HA group. This is
needed because
+ * HighAvailabilityGroup.connectToOneCluster() is package-private.
+ * @param haGroup the HighAvailabilityGroup
+ * @param url the cluster URL to connect to
+ * @param properties the connection properties
+ * @param haurlInfo the HA URL info
+ * @return the PhoenixConnection to the specified cluster
+ * @throws SQLException if connection cannot be established
+ */
+ public static PhoenixConnection connectToOneCluster(HighAvailabilityGroup
haGroup, String url,
+ Properties properties, HAURLInfo haurlInfo) throws SQLException {
+ if (haGroup != null) {
+ return haGroup.connectToOneCluster(url, properties, haurlInfo);
+ }
+ return null;
+ }
}