Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public int getNetworkTimeout() throws SQLException {

/** Returns the currently wrapped connection. */
@VisibleForTesting
PhoenixConnection getWrappedConnection() {
public PhoenixConnection getWrappedConnection() {
return connection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -644,7 +646,8 @@ PhoenixConnection connectActive(final Properties properties, final HAURLInfo hau
}

/** 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;
}
Expand Down Expand Up @@ -687,11 +690,12 @@ PhoenixConnection connectToOneCluster(String url, Properties properties, HAURLIn
}

@VisibleForTesting
HAGroupInfo getGroupInfo() {
public HAGroupInfo getGroupInfo() {
return info;
}

Properties getProperties() {
@VisibleForTesting
public Properties getProperties() {
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public CompletableFuture<PhoenixConnection> getFutureConnection2() {
}

@VisibleForTesting
ParallelPhoenixContext getContext() {
public ParallelPhoenixContext getContext() {
return this.context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;

/**
Expand Down Expand Up @@ -219,11 +220,13 @@ public long getOperationTimeout() {
return this.operationTimeoutMs;
}

CompletableFuture<?> getChainOnConn1() {
@VisibleForTesting
public CompletableFuture<?> getChainOnConn1() {
return this.cluster1Context.getChainOnConn();
}

CompletableFuture<?> getChainOnConn2() {
@VisibleForTesting
public CompletableFuture<?> getChainOnConn2() {
return this.cluster2Context.getChainOnConn();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,114 @@ public static Properties getHATestProperties() {
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;
}
}