Skip to content

Commit

Permalink
HBASE-24640 Purge use of VisibleForTesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Purtell committed Nov 24, 2020
1 parent edccfe4 commit 3ea01c2
Show file tree
Hide file tree
Showing 158 changed files with 141 additions and 670 deletions.
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hbase;

import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ServiceException;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -668,7 +667,6 @@ protected static byte[] getRegionInfoColumn() {
* @param replicaId the replicaId of the region
* @return a byte[] for server column qualifier
*/
@VisibleForTesting
public static byte[] getServerColumn(int replicaId) {
return replicaId == 0
? HConstants.SERVER_QUALIFIER
Expand All @@ -681,7 +679,6 @@ public static byte[] getServerColumn(int replicaId) {
* @param replicaId the replicaId of the region
* @return a byte[] for server start code column qualifier
*/
@VisibleForTesting
public static byte[] getStartCodeColumn(int replicaId) {
return replicaId == 0
? HConstants.STARTCODE_QUALIFIER
Expand All @@ -694,7 +691,6 @@ public static byte[] getStartCodeColumn(int replicaId) {
* @param replicaId the replicaId of the region
* @return a byte[] for seqNum column qualifier
*/
@VisibleForTesting
public static byte[] getSeqNumColumn(int replicaId) {
return replicaId == 0
? HConstants.SEQNUM_QUALIFIER
Expand All @@ -708,7 +704,6 @@ public static byte[] getSeqNumColumn(int replicaId) {
* @param serverColumn the column qualifier
* @return an int for the replicaId
*/
@VisibleForTesting
static int parseReplicaIdFromServerColumn(byte[] serverColumn) {
String serverStr = Bytes.toString(serverColumn);

Expand Down
Expand Up @@ -19,7 +19,6 @@

package org.apache.hadoop.hbase.client;

import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
Expand All @@ -30,7 +29,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -436,7 +434,6 @@ public void setOperationTimeout(int operationTimeout) {
* @return pool if non null, otherwise returns this.pool if non null, otherwise throws
* RuntimeException
*/
@VisibleForTesting
ExecutorService getPool(ExecutorService pool) {
if (pool != null) {
return pool;
Expand Down Expand Up @@ -803,13 +800,11 @@ private void addReplicaActionsAgain(
* Runnable (that can be submitted to thread pool) that submits MultiAction to a
* single server. The server call is synchronous, therefore we do it on a thread pool.
*/
@VisibleForTesting
class SingleServerRequestRunnable implements Runnable {
private final MultiAction<Row> multiAction;
private final int numAttempt;
private final ServerName server;
private final Set<PayloadCarryingServerCallable> callsInProgress;
@VisibleForTesting
SingleServerRequestRunnable(
MultiAction<Row> multiAction, int numAttempt, ServerName server,
Set<PayloadCarryingServerCallable> callsInProgress) {
Expand Down Expand Up @@ -988,7 +983,6 @@ public Set<PayloadCarryingServerCallable> getCallsInProgress() {
return callsInProgress;
}

@VisibleForTesting
SingleServerRequestRunnable createSingleServerRequest(MultiAction<Row> multiAction, int numAttempt, ServerName server,
Set<PayloadCarryingServerCallable> callsInProgress) {
return new SingleServerRequestRunnable(multiAction, numAttempt, server, callsInProgress);
Expand Down Expand Up @@ -1387,7 +1381,6 @@ private void logNoResubmit(ServerName oldServer, int numAttempt,
}
}

@VisibleForTesting
long getActionsInProgress() {
return actionsInProgress.get();
}
Expand Down Expand Up @@ -1798,15 +1791,13 @@ public Object[] getResults() throws InterruptedIOException {
/**
* Create a callable. Isolated to be easily overridden in the tests.
*/
@VisibleForTesting
protected MultiServerCallable<Row> createCallable(final ServerName server,
TableName tableName, final MultiAction<Row> multi) {
return new MultiServerCallable<Row>(connection, tableName, server,
AsyncProcess.this.rpcFactory, multi, rpcTimeout, tracker, multi.getPriority());
}
}

@VisibleForTesting
protected void updateStats(ServerName server, Map<byte[], MultiResponse.RegionResult> results) {
boolean metrics = AsyncProcess.this.connection.getConnectionMetrics() != null;
boolean stats = AsyncProcess.this.connection.getStatisticsTracker() != null;
Expand All @@ -1823,7 +1814,6 @@ protected void updateStats(ServerName server, Map<byte[], MultiResponse.RegionRe
}
}

@VisibleForTesting
<CResult> AsyncRequestFutureImpl<CResult> createAsyncRequestFuture(
TableName tableName, List<Action<Row>> actions, long nonceGroup, ExecutorService pool,
Batch.Callback<CResult> callback, Object[] results, boolean needResults,
Expand All @@ -1836,13 +1826,11 @@ tableName, actions, nonceGroup, getPool(pool), needResults,
/**
* Create a caller. Isolated to be easily overridden in the tests.
*/
@VisibleForTesting
protected RpcRetryingCaller<MultiResponse> createCaller(PayloadCarryingServerCallable callable,
int rpcTimeout) {
return rpcCallerFactory.<MultiResponse> newCaller(rpcTimeout);
}

@VisibleForTesting
/** Waits until all outstanding tasks are done. Used in tests. */
void waitUntilDone() throws InterruptedIOException {
waitForMaximumCurrentTasks(0, null);
Expand All @@ -1855,7 +1843,6 @@ private void waitForMaximumCurrentTasks(int max, String tableName)
}

// Break out this method so testable
@VisibleForTesting
void waitForMaximumCurrentTasks(int max, final AtomicLong tasksInProgress, final long id,
String tableName) throws InterruptedIOException {
long lastLog = EnvironmentEdgeManager.currentTime();
Expand Down Expand Up @@ -2011,7 +1998,6 @@ private enum Retry {
/**
* Collect all advices from checkers and make the final decision.
*/
@VisibleForTesting
static class RowCheckerHost {
private final List<RowChecker> checkers;
private boolean isEnd = false;
Expand Down Expand Up @@ -2064,7 +2050,6 @@ ReturnCode canTakeOperation(HRegionLocation loc, long rowSize) {
/**
* Provide a way to control the flow of rows iteration.
*/
@VisibleForTesting
interface RowChecker {
enum ReturnCode {
/**
Expand Down Expand Up @@ -2098,7 +2083,6 @@ enum ReturnCode {
* Reduce the limit of heapsize for submitting quickly
* if there is no running task.
*/
@VisibleForTesting
static class SubmittedSizeChecker implements RowChecker {
private final long maxHeapSizeSubmit;
private long heapSize = 0;
Expand Down Expand Up @@ -2128,7 +2112,6 @@ public void reset() {
/**
* limit the max number of tasks in an AsyncProcess.
*/
@VisibleForTesting
static class TaskCountChecker implements RowChecker {
private static final long MAX_WAITING_TIME = 1000; //ms
private final Set<HRegionInfo> regionsIncluded = new HashSet<>();
Expand Down Expand Up @@ -2233,7 +2216,6 @@ public void notifyFinal(ReturnCode code, HRegionLocation loc, long rowSize) {
/**
* limit the request size for each regionserver.
*/
@VisibleForTesting
static class RequestSizeChecker implements RowChecker {
private final long maxHeapSizePerRequest;
private final Map<ServerName, Long> serverRequestSizes = new HashMap<>();
Expand Down
Expand Up @@ -16,7 +16,6 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.BufferedMutatorParams.UNSET;
import com.google.common.annotations.VisibleForTesting;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
Expand Down Expand Up @@ -67,16 +66,13 @@ public class BufferedMutatorImpl implements BufferedMutator {
protected ClusterConnection connection; // non-final so can be overridden in test
private final TableName tableName;
private volatile Configuration conf;
@VisibleForTesting
final ConcurrentLinkedQueue<Mutation> writeAsyncBuffer = new ConcurrentLinkedQueue<Mutation>();
@VisibleForTesting
AtomicLong currentWriteBufferSize = new AtomicLong(0);

/**
* Count the size of {@link BufferedMutatorImpl#writeAsyncBuffer}.
* The {@link ConcurrentLinkedQueue#size()} is NOT a constant-time operation.
*/
@VisibleForTesting
final AtomicInteger undealtMutationCount = new AtomicInteger(0);
private long writeBufferSize;
/**
Expand All @@ -96,7 +92,6 @@ public class BufferedMutatorImpl implements BufferedMutator {
private int writeRpcTimeout; // needed to pass in through AsyncProcess constructor
private int operationTimeout;

@VisibleForTesting
protected AsyncProcess ap; // non-final so can be overridden in test

BufferedMutatorImpl(ClusterConnection conn, RpcRetryingCallerFactory rpcCallerFactory,
Expand Down Expand Up @@ -200,7 +195,6 @@ public void mutate(List<? extends Mutation> ms) throws InterruptedIOException,
}
}

@VisibleForTesting
protected long getExecutedWriteBufferPeriodicFlushes() {
return executedWriteBufferPeriodicFlushes.get();
}
Expand Down Expand Up @@ -425,7 +419,6 @@ public void setOperationTimeout(int operationTimeout) {
this.ap.setOperationTimeout(operationTimeout);
}

@VisibleForTesting
long getCurrentWriteBufferSize() {
return currentWriteBufferSize.get();
}
Expand All @@ -440,12 +433,10 @@ public List<Row> getWriteBuffer() {
return Arrays.asList(writeAsyncBuffer.toArray(new Row[0]));
}

@VisibleForTesting
QueueRowAccess createQueueRowAccess() {
return new QueueRowAccess();
}

@VisibleForTesting
class QueueRowAccess implements RowAccess<Row>, Closeable {
private int remainder = undealtMutationCount.getAndSet(0);
private Mutation last = null;
Expand Down
Expand Up @@ -19,8 +19,6 @@

import static org.apache.hadoop.hbase.client.ConnectionUtils.createScanResultCache;

import com.google.common.annotations.VisibleForTesting;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.LinkedList;
Expand Down Expand Up @@ -186,7 +184,6 @@ protected long getTimestamp() {
return lastNext;
}

@VisibleForTesting
protected long getMaxResultSize() {
return maxScannerResultSize;
}
Expand Down Expand Up @@ -219,7 +216,6 @@ private void closeScanner() throws IOException {
* Marked as protected only because TestClientScanner need to override this method.
* @return false if we should terminate the scan. Otherwise
*/
@VisibleForTesting
protected boolean moveToNextRegion() {
// Close the previous scanner if it's open
try {
Expand Down Expand Up @@ -258,7 +254,6 @@ protected boolean moveToNextRegion() {
return true;
}

@VisibleForTesting
boolean isAnyRPCcancelled() {
return callable.isAnyRPCcancelled();
}
Expand Down Expand Up @@ -317,7 +312,6 @@ public Result next() throws IOException {
return null;
}

@VisibleForTesting
public int getCacheSize() {
return cache != null ? cache.size() : 0;
}
Expand Down
Expand Up @@ -11,7 +11,6 @@

package org.apache.hadoop.hbase.client;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -126,7 +125,6 @@ public class ConnectionConfiguration {
* This is for internal testing purpose (using the default value).
* In real usage, we should read the configuration from the Configuration object.
*/
@VisibleForTesting
protected ConnectionConfiguration() {
this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT;
this.writeBufferPeriodicFlushTimeoutMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT;
Expand Down
Expand Up @@ -202,13 +202,11 @@
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ExceptionUtil;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.zookeeper.KeeperException;

import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.BlockingRpcChannel;
import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;
Expand Down Expand Up @@ -282,7 +280,6 @@ private ConnectionManager() {
* @param cnm Replaces the nonce generator used, for testing.
* @return old nonce generator.
*/
@VisibleForTesting
static NonceGenerator injectNonceGeneratorForTesting(
ClusterConnection conn, NonceGenerator cnm) {
HConnectionImplementation connImpl = (HConnectionImplementation)conn;
Expand Down Expand Up @@ -752,7 +749,6 @@ public void newDead(ServerName sn) {
/**
* @param useMetaReplicas
*/
@VisibleForTesting
void setUseMetaReplicas(final boolean useMetaReplicas) {
this.useMetaReplicas = useMetaReplicas;
}
Expand Down Expand Up @@ -933,7 +929,6 @@ private ConnectionRegistry setupRegistry() throws IOException {
/**
* For tests only.
*/
@VisibleForTesting
RpcClient getRpcClient() {
return rpcClient;
}
Expand Down Expand Up @@ -2503,7 +2498,6 @@ public ClientBackoffPolicy getBackoffPolicy() {
* Return the number of cached region for a table. It will only be called
* from a unit test.
*/
@VisibleForTesting
int getNumberOfCachedRegionLocations(final TableName tableName) {
return metaCache.getNumberOfCachedRegionLocations(tableName);
}
Expand Down
Expand Up @@ -20,8 +20,6 @@
import static org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW;
import static org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW;

import com.google.common.annotations.VisibleForTesting;

import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -169,7 +167,6 @@ public ClientService.BlockingInterface getClient(ServerName sn) throws IOExcepti
* Setup the connection class, so that it will not depend on master being online. Used for testing
* @param conf configuration to set
*/
@VisibleForTesting
public static void setupMasterlessConnection(Configuration conf) {
conf.set(HConnection.HBASE_CLIENT_CONNECTION_IMPL,
MasterlessConnection.class.getName());
Expand Down
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.hadoop.hbase.client;

import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;
import com.google.protobuf.ServiceException;

Expand Down Expand Up @@ -2810,7 +2809,6 @@ public void split(final byte[] tableNameOrRegionName,
}
}

@VisibleForTesting
public void split(final ServerName sn, final HRegionInfo hri,
byte[] splitPoint) throws IOException {
if (hri.getStartKey() != null && splitPoint != null &&
Expand Down

0 comments on commit 3ea01c2

Please sign in to comment.