From d94cecbc56ae979e8614bc0c224b173039053dd2 Mon Sep 17 00:00:00 2001 From: Mingliang Liu Date: Sat, 18 Aug 2018 00:21:59 -0700 Subject: [PATCH] HBASE-21071 HBaseTestingUtility::startMiniCluster() to use builder pattern --- .../TableSnapshotInputFormatTestBase.java | 5 +- .../mapreduce/TestHFileOutputFormat2.java | 5 +- .../hadoop/hbase/HBaseTestingUtility.java | 247 ++++------------- .../hadoop/hbase/StartMiniClusterOption.java | 251 ++++++++++++++++++ .../hbase/TestClientOperationTimeout.java | 5 +- .../hadoop/hbase/TestLocalHBaseCluster.java | 5 +- .../hadoop/hbase/TestMultiVersions.java | 4 +- .../apache/hadoop/hbase/TestZooKeeper.java | 4 +- .../client/TestTableSnapshotScanner.java | 5 +- .../fs/TestBlockReorderBlockLocation.java | 2 +- .../hbase/fs/TestBlockReorderMultiBlocks.java | 2 +- .../hadoop/hbase/master/AbstractTestDLS.java | 5 +- .../hbase/master/TestGetReplicationLoad.java | 6 +- .../TestMasterFileSystemWithWALDir.java | 4 +- .../hbase/master/TestMasterMetrics.java | 6 +- ...TestMasterOperationsForRegionReplicas.java | 7 +- .../hbase/master/TestMetaShutdownHandler.java | 5 +- .../assignment/TestRegionMoveAndAbandon.java | 5 +- .../hbase/regionserver/TestClusterId.java | 7 +- .../TestEncryptionKeyRotation.java | 2 +- .../hbase/regionserver/TestHRegion.java | 5 +- .../TestHRegionServerBulkLoad.java | 4 +- .../regionserver/TestJoinedScanners.java | 5 +- .../TestRegionMergeTransactionOnCluster.java | 5 +- .../regionserver/TestRegionServerAbort.java | 5 +- .../TestSplitTransactionOnCluster.java | 5 +- .../wal/AbstractTestLogRolling.java | 4 +- .../TestReplicationDisableInactivePeer.java | 5 +- .../TestReplicationDroppedTables.java | 4 +- .../wal/TestWALOpenAfterDNRollingStart.java | 2 +- .../hbase/spark/TestJavaHBaseContext.java | 2 +- 31 files changed, 395 insertions(+), 233 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TableSnapshotInputFormatTestBase.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TableSnapshotInputFormatTestBase.java index 385ad3e6b2..8dbe29316f 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TableSnapshotInputFormatTestBase.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TableSnapshotInputFormatTestBase.java @@ -29,6 +29,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Result; @@ -57,7 +58,9 @@ public abstract class TableSnapshotInputFormatTestBase { public void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(NUM_REGION_SERVERS, true); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(NUM_REGION_SERVERS).create(true).build(); + UTIL.startMiniCluster(option); rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); fs = rootDir.getFileSystem(UTIL.getConfiguration()); } diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java index 286610373d..88a7d7a085 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java @@ -62,6 +62,7 @@ import org.apache.hadoop.hbase.HadoopShims; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.PerformanceEvaluation; import org.apache.hadoop.hbase.PrivateCellUtil; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; @@ -612,7 +613,9 @@ public class TestHFileOutputFormat2 { for (int i = 0; i < hostCount; ++i) { hostnames[i] = "datanode_" + i; } - util.startMiniCluster(1, hostCount, hostnames); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(hostCount).dataNodeHosts(hostnames).build(); + util.startMiniCluster(option); Map allTables = new HashMap<>(tableStr.size()); List tableInfo = new ArrayList<>(tableStr.size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index b938d2834f..245940a31e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -765,40 +765,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { } } - - /** - * Start up a minicluster of hbase, dfs, and zookeeper. - * @throws Exception - * @return Mini hbase cluster instance created. - * @see #shutdownMiniDFSCluster() - */ - public MiniHBaseCluster startMiniCluster() throws Exception { - return startMiniCluster(1, 1); - } - - /** - * Start up a minicluster of hbase, dfs, and zookeeper where WAL's walDir is created separately. - * @throws Exception - * @return Mini hbase cluster instance created. - * @see #shutdownMiniDFSCluster() - */ - public MiniHBaseCluster startMiniCluster(boolean withWALDir) throws Exception { - return startMiniCluster(1, 1, 1, null, null, null, false, withWALDir); - } - - /** - * Start up a minicluster of hbase, dfs, and zookeeper. - * Set the create flag to create root or data directory path or not - * (will overwrite if dir already exists) - * @throws Exception - * @return Mini hbase cluster instance created. - * @see #shutdownMiniDFSCluster() - */ - public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create) - throws Exception { - return startMiniCluster(1, numSlaves, create); - } - /** * Start up a minicluster of hbase, optionally dfs, and zookeeper. * Modifies Configuration. Homes the cluster data directory under a random @@ -812,27 +778,8 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { * @see #shutdownMiniCluster() * @return Mini hbase cluster instance created. */ - public MiniHBaseCluster startMiniCluster(final int numSlaves) - throws Exception { - return startMiniCluster(1, numSlaves, false); - } - - public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create, boolean withWALDir) - throws Exception { - return startMiniCluster(1, numSlaves, numSlaves, null, null, null, create, withWALDir); - } - - /** - * Start minicluster. Whether to create a new root or data dir path even if such a path - * has been created earlier is decided based on flag create - * @throws Exception - * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. - */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, boolean create) - throws Exception { - return startMiniCluster(numMasters, numSlaves, null, create); + public MiniHBaseCluster startMiniCluster(int numSlaves) throws Exception { + return startMiniCluster(StartMiniClusterOption.builder().numRegionServers(numSlaves).build()); } /** @@ -841,121 +788,29 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { * @see #shutdownMiniCluster() * @return Mini hbase cluster instance created. */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves) - throws Exception { - return startMiniCluster(numMasters, numSlaves, null, false); - } - - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final String[] dataNodeHosts, boolean create) - throws Exception { - return startMiniCluster(numMasters, numSlaves, numSlaves, dataNodeHosts, - null, null, create, false); + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves) throws Exception { + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numSlaves).build(); + return startMiniCluster(option); } /** - * Start up a minicluster of hbase, optionally dfs, and zookeeper. - * Modifies Configuration. Homes the cluster data directory under a random - * subdirectory in a directory under System property test.build.data. - * Directory is cleaned up on exit. - * @param numMasters Number of masters to start up. We'll start this many - * hbase masters. If numMasters > 1, you can find the active/primary master - * with {@link MiniHBaseCluster#getMaster()}. - * @param numSlaves Number of slaves to start up. We'll start this many - * regionservers. If dataNodeHosts == null, this also indicates the number of - * datanodes to start. If dataNodeHosts != null, the number of datanodes is - * based on dataNodeHosts.length. - * If numSlaves is > 1, then make sure - * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise - * bind errors. - * @param dataNodeHosts hostnames DNs to run on. - * This is useful if you want to run datanode on distinct hosts for things - * like HDFS block location verification. - * If you start MiniDFSCluster without host names, - * all instances of the datanodes will have the same host name. - * @throws Exception - * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. - */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final String[] dataNodeHosts) throws Exception { - return startMiniCluster(numMasters, numSlaves, numSlaves, dataNodeHosts, - null, null); - } - - /** - * Same as {@link #startMiniCluster(int, int)}, but with custom number of datanodes. - * @param numDataNodes Number of data nodes. - */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final int numDataNodes) throws Exception { - return startMiniCluster(numMasters, numSlaves, numDataNodes, null, null, null); - } - - /** - * Start up a minicluster of hbase, optionally dfs, and zookeeper. - * Modifies Configuration. Homes the cluster data directory under a random - * subdirectory in a directory under System property test.build.data. - * Directory is cleaned up on exit. - * @param numMasters Number of masters to start up. We'll start this many - * hbase masters. If numMasters > 1, you can find the active/primary master - * with {@link MiniHBaseCluster#getMaster()}. - * @param numSlaves Number of slaves to start up. We'll start this many - * regionservers. If dataNodeHosts == null, this also indicates the number of - * datanodes to start. If dataNodeHosts != null, the number of datanodes is - * based on dataNodeHosts.length. - * If numSlaves is > 1, then make sure - * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise - * bind errors. - * @param dataNodeHosts hostnames DNs to run on. - * This is useful if you want to run datanode on distinct hosts for things - * like HDFS block location verification. - * If you start MiniDFSCluster without host names, - * all instances of the datanodes will have the same host name. - * @param masterClass The class to use as HMaster, or null for default - * @param regionserverClass The class to use as HRegionServer, or null for - * default - * @throws Exception - * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * Start up a minicluster of hbase, dfs and zookeeper all using default options. + * @see #startMiniCluster(StartMiniClusterOption option) + * @see #shutdownMiniDFSCluster() */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final String[] dataNodeHosts, Class masterClass, - Class regionserverClass) - throws Exception { - return startMiniCluster( - numMasters, numSlaves, numSlaves, dataNodeHosts, masterClass, regionserverClass); - } - - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, int numDataNodes, final String[] dataNodeHosts, - Class masterClass, - Class regionserverClass) - throws Exception { - return startMiniCluster(numMasters, numSlaves, numDataNodes, dataNodeHosts, - masterClass, regionserverClass, false, false); + public MiniHBaseCluster startMiniCluster() throws Exception { + return startMiniCluster(StartMiniClusterOption.builder().build()); } /** - * Same as {@link #startMiniCluster(int, int, String[], Class, Class)}, but with custom - * number of datanodes. - * @param numDataNodes Number of data nodes. - * @param create Set this flag to create a new - * root or data directory path or not (will overwrite if exists already). + * Start up a mini cluster of hbase, optionally dfs and zookeeper if needed. + * It modifies Configuration. It homes the cluster data directory under a random + * subdirectory in a directory under System property test.build.data, to be cleaned up on exit. + * @see #shutdownMiniDFSCluster() */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, int numDataNodes, final String[] dataNodeHosts, - Class masterClass, - Class regionserverClass, - boolean create, boolean withWALDir) - throws Exception { - if (dataNodeHosts != null && dataNodeHosts.length != 0) { - numDataNodes = dataNodeHosts.length; - } - - LOG.info("Starting up minicluster with " + numMasters + " master(s) and " + - numSlaves + " regionserver(s) and " + numDataNodes + " datanode(s)"); + public MiniHBaseCluster startMiniCluster(StartMiniClusterOption option) throws Exception { + LOG.info("Starting up minicluster with option: {}", option); // If we already put up a cluster, fail. if (miniClusterRunning) { @@ -968,54 +823,34 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { // Bring up mini dfs cluster. This spews a bunch of warnings about missing // scheme. Complaints are 'Scheme is undefined for build/test/data/dfs/name1'. - if(this.dfsCluster == null) { + if (dfsCluster == null) { LOG.info("STARTING DFS"); - dfsCluster = startMiniDFSCluster(numDataNodes, dataNodeHosts); - } else LOG.info("NOT STARTING DFS"); + dfsCluster = startMiniDFSCluster(option.getNumDataNodes(), option.getDataNodeHosts()); + } else { + LOG.info("NOT STARTING DFS"); + } // Start up a zk cluster. if (getZkCluster() == null) { - startMiniZKCluster(); + startMiniZKCluster(option.getNumZkServers()); } // Start the MiniHBaseCluster - return startMiniHBaseCluster(numMasters, numSlaves, null, masterClass, - regionserverClass, create, withWALDir); - } - - public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, final int numSlaves) - throws IOException, InterruptedException { - return startMiniHBaseCluster(numMasters, numSlaves, null); - } - - public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, final int numSlaves, - List rsPorts) throws IOException, InterruptedException { - return startMiniHBaseCluster(numMasters, numSlaves, rsPorts, null, null, false, false); + return startMiniHBaseCluster(option); } /** - * Starts up mini hbase cluster. Usually used after call to - * {@link #startMiniCluster(int, int)} when doing stepped startup of clusters. + * Starts up mini hbase cluster. * Usually you won't want this. You'll usually want {@link #startMiniCluster()}. - * @param rsPorts Ports that RegionServer should use; pass ports if you want to test cluster - * restart where for sure the regionservers come up on same address+port (but - * just with different startcode); by default mini hbase clusters choose new - * arbitrary ports on each cluster start. - * @param create Whether to create a - * root or data directory path or not; will overwrite if exists already. + * This is useful when doing stepped startup of clusters. * @return Reference to the hbase mini hbase cluster. - * @throws IOException - * @throws InterruptedException - * @see #startMiniCluster() + * @see #startMiniCluster(StartMiniClusterOption) */ - public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, - final int numSlaves, List rsPorts, Class masterClass, - Class regionserverClass, - boolean create, boolean withWALDir) - throws IOException, InterruptedException { + public MiniHBaseCluster startMiniHBaseCluster(StartMiniClusterOption option) + throws IOException, InterruptedException { // Now do the mini hbase cluster. Set the hbase.rootdir in config. - createRootDir(create); - if (withWALDir) { + createRootDir(option.isCreate()); + if (option.isWithWALDir()) { createWALRootDir(); } // Set the hbase.fs.tmp.dir config to make sure that we have some default value. This is @@ -1025,16 +860,17 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { // These settings will make the server waits until this exact number of // regions servers are connected. if (conf.getInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1) == -1) { - conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, numSlaves); + conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, option.getNumRegionServers()); } if (conf.getInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1) == -1) { - conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, numSlaves); + conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, option.getNumRegionServers()); } Configuration c = new Configuration(this.conf); TraceUtil.initTracer(c); this.hbaseCluster = - new MiniHBaseCluster(c, numMasters, numSlaves, rsPorts, masterClass, regionserverClass); + new MiniHBaseCluster(c, option.getNumMasters(), option.getNumRegionServers(), + option.getRsPorts(), option.getMasterClass(), option.getRsClass()); // Don't leave here till we've done a successful scan of the hbase:meta Table t = getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner s = t.getScanner(new Scan()); @@ -1045,9 +881,18 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { t.close(); getAdmin(); // create immediately the hbaseAdmin - LOG.info("Minicluster is up; activeMaster=" + this.getHBaseCluster().getMaster()); + LOG.info("Minicluster is up; activeMaster={}", getHBaseCluster().getMaster()); + + return (MiniHBaseCluster) hbaseCluster; + } - return (MiniHBaseCluster)this.hbaseCluster; + /** + * Starts up mini hbase cluster using default options. + * Default options can be found in {@link StartMiniClusterOption.Builder}. + * @see #startMiniHBaseCluster(StartMiniClusterOption) + */ + public MiniHBaseCluster startMiniHBaseCluster() throws IOException, InterruptedException { + return startMiniHBaseCluster(StartMiniClusterOption.builder().build()); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java new file mode 100644 index 0000000000..5b5c0ff31e --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java @@ -0,0 +1,251 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hbase.master.HMaster; + +import java.util.Arrays; +import java.util.List; + +/** + * Options for starting up a mini cluster (including an hbase, dfs and zookeeper clusters) in test. + * The options include HDFS options to build mini dfs cluster, Zookeeper options to build mini zk + * cluster, and mostly HBase options to build mini hbase cluster. + * + * To create an object, use a {@link Builder}. + * Example usage: + *
+ *    StartMiniClusterOption option = StartMiniClusterOption.builder().
+ *        .numMasters(3).rsClass(MyRegionServer.class).withWALDir(true).build();
+ * 
+ * + * Default values can be found in {@link Builder}. + */ +public class StartMiniClusterOption { + /** + * Number of masters to start up. We'll start this many hbase masters. If numMasters > 1, you + * can find the active/primary master with {@link MiniHBaseCluster#getMaster()}. + */ + private final int numMasters; + /** + * The class to use as HMaster, or null for default. + */ + private final Class masterClass; + + /** + * Number of slaves to start up. We'll start this many regionservers. If dataNodeHosts == null, + * this also indicates the number of datanodes to start. If dataNodeHosts != null, the number of + * datanodes is based on dataNodeHosts.length. If numSlaves is > 1, then make sure config + * "hbase.regionserver.info.port" is -1 (i.e. no ui per regionserver) otherwise bind errors. + */ + private final int numRegionServers; + /** + * Ports that RegionServer should use. Pass ports if you want to test cluster restart where for + * sure the regionservers come up on same address+port (but just with different startcode); by + * default mini hbase clusters choose new arbitrary ports on each cluster start. + */ + private final List rsPorts; + /** + * The class to use as HRegionServer, or null for default. + */ + private Class rsClass; + + /** + * Number of datanodes. Used to create mini DSF cluster. Surpassed by {@link #dataNodeHosts} size. + */ + private final int numDataNodes; + /** + * The hostnames of DataNodes to run on. This is useful if you want to run datanode on distinct + * hosts for things like HDFS block location verification. If you start MiniDFSCluster without + * host names, all instances of the datanodes will have the same host name. + */ + private final String[] dataNodeHosts; + + /** + * Number of Zookeeper servers. + */ + private final int numZkServers; + + /** + * Whether to create a root or data directory path or not; will overwrite if exists already. + */ + private final boolean create; + + /** + * True if WAL's walDir is created separately. + */ + private final boolean withWALDir; + + /** + * Private constructor. Use {@link Builder#build()}. + */ + private StartMiniClusterOption(int numMasters, Class masterClass, + int numRegionServers, List rsPorts, + Class rsClass, int numDataNodes, + String[] dataNodeHosts, int numZkServers, boolean create, boolean withWALDir) { + this.numMasters = numMasters; + this.masterClass = masterClass; + this.numRegionServers = numRegionServers; + this.rsPorts = rsPorts; + this.rsClass = rsClass; + this.numDataNodes = numDataNodes; + this.dataNodeHosts = dataNodeHosts; + this.numZkServers = numZkServers; + this.create = create; + this.withWALDir = withWALDir; + } + + public int getNumMasters() { + return numMasters; + } + + public Class getMasterClass() { + return masterClass; + } + + public int getNumRegionServers() { + return numRegionServers; + } + + public List getRsPorts() { + return rsPorts; + } + + public Class getRsClass() { + return rsClass; + } + + public int getNumDataNodes() { + return numDataNodes; + } + + public String[] getDataNodeHosts() { + return dataNodeHosts; + } + + public int getNumZkServers() { + return numZkServers; + } + + public boolean isCreate() { + return create; + } + + public boolean isWithWALDir() { + return withWALDir; + } + + @Override + public String toString() { + return "StartMiniClusterOption{" + "numMasters=" + numMasters + ", masterClass=" + masterClass + + ", numRegionServers=" + numRegionServers + ", rsPorts=" + StringUtils.join(rsPorts) + + ", rsClass=" + rsClass + ", numDataNodes=" + numDataNodes + + ", dataNodeHosts=" + Arrays.toString(dataNodeHosts) + ", numZkServers=" + numZkServers + + ", create=" + create + ", withWALDir=" + withWALDir + '}'; + } + + /** + * @return a new builder. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder pattern for creating an {@link StartMiniClusterOption}. + * + * The default values of its fields should be considered public and constant. Changing the default + * values may cause other tests fail. + */ + public static class Builder { + private int numMasters = 1; + private Class masterClass = null; + private int numRegionServers = 1; + private List rsPorts = null; + private Class rsClass = null; + private int numDataNodes = 1; + private String[] dataNodeHosts = null; + private int numZkServers = 1; + private boolean create = false; + private boolean withWALDir = false; + + private Builder() { + } + + public StartMiniClusterOption build() { + if (dataNodeHosts != null && dataNodeHosts.length != 0) { + numDataNodes = dataNodeHosts.length; + } + return new StartMiniClusterOption(numMasters, masterClass, numRegionServers, rsPorts, rsClass, + numDataNodes, dataNodeHosts, numZkServers, create, withWALDir); + } + + public Builder numMasters(int numMasters) { + this.numMasters = numMasters; + return this; + } + + public Builder masterClass(Class masterClass) { + this.masterClass = masterClass; + return this; + } + + public Builder numRegionServers(int numRegionServers) { + this.numRegionServers = numRegionServers; + return this; + } + + public Builder rsPorts(List rsPorts) { + this.rsPorts = rsPorts; + return this; + } + + public Builder rsClass(Class rsClass) { + this.rsClass = rsClass; + return this; + } + + public Builder numDataNodes(int numDataNodes) { + this.numDataNodes = numDataNodes; + return this; + } + + public Builder dataNodeHosts(String[] dataNodeHosts) { + this.dataNodeHosts = dataNodeHosts; + return this; + } + + public Builder numZkServers(int numZkServers) { + this.numZkServers = numZkServers; + return this; + } + + public Builder create(boolean create) { + this.create = create; + return this; + } + + public Builder withWALDir(boolean withWALDir) { + this.withWALDir = withWALDir; + return this; + } + } + +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java index fa4e017f4c..9e2a110408 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java @@ -88,7 +88,10 @@ public class TestClientOperationTimeout { TESTING_UTIL.getConfiguration().setLong(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 500); TESTING_UTIL.getConfiguration().setLong(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); - TESTING_UTIL.startMiniCluster(1, 1, null, null, DelayedRegionServer.class); + // Set RegionServer class and using default values for other options. + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .rsClass(DelayedRegionServer.class).build(); + TESTING_UTIL.startMiniCluster(option); } @Before diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java index 4403739623..e2700dac1f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java @@ -47,7 +47,10 @@ public class TestLocalHBaseCluster { */ @Test public void testLocalHBaseCluster() throws Exception { - TEST_UTIL.startMiniCluster(1, 1, null, MyHMaster.class, MyHRegionServer.class); + // Set Master class and RegionServer class, and using default values for other options. + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .masterClass(MyHMaster.class).rsClass(MyHRegionServer.class).build(); + TEST_UTIL.startMiniCluster(option); // Can we cast back to our master class? try { int val = ((MyHMaster)TEST_UTIL.getHBaseCluster().getMaster(0)).echo(42); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java index a7327401d7..ed77a5ba6d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java @@ -150,7 +150,9 @@ public class TestMultiVersions { table.close(); UTIL.shutdownMiniHBaseCluster(); LOG.debug("HBase cluster shut down -- restarting"); - UTIL.startMiniHBaseCluster(1, NUM_SLAVES); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(NUM_SLAVES).build(); + UTIL.startMiniHBaseCluster(option); // Make a new connection. table = UTIL.getConnection().getTable(desc.getTableName()); // Overwrite previous value diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java index 2d579542ec..d6cdc4b53a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java @@ -88,7 +88,9 @@ public class TestZooKeeper { @Before public void setUp() throws Exception { - TEST_UTIL.startMiniHBaseCluster(2, 2); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(2).numRegionServers(2).build(); + TEST_UTIL.startMiniHBaseCluster(option); } @After diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java index 408953ad6e..220e817d0d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper; @@ -74,7 +75,9 @@ public class TestTableSnapshotScanner { public void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(NUM_REGION_SERVERS, true); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(NUM_REGION_SERVERS).create(true).build(); + UTIL.startMiniCluster(option); rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); fs = rootDir.getFileSystem(UTIL.getConfiguration()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java index 5ef5ba4b8d..84b1532a68 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java @@ -101,7 +101,7 @@ public class TestBlockReorderBlockLocation { public void testBlockLocation() throws Exception { // We need to start HBase to get HConstants.HBASE_DIR set in conf htu.startMiniZKCluster(); - MiniHBaseCluster hbm = htu.startMiniHBaseCluster(1, 1); + final MiniHBaseCluster hbm = htu.startMiniHBaseCluster(); conf = hbm.getConfiguration(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java index 937b5dd662..76d73762d2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java @@ -116,7 +116,7 @@ public class TestBlockReorderMultiBlocks { byte[] sb = Bytes.toBytes("sb"); htu.startMiniZKCluster(); - MiniHBaseCluster hbm = htu.startMiniHBaseCluster(1, 1); + final MiniHBaseCluster hbm = htu.startMiniHBaseCluster(); hbm.waitForActiveAndReadyMaster(); HRegionServer targetRs = LoadBalancer.isTablesOnMaster(hbm.getConf())? hbm.getMaster(): hbm.getRegionServer(0); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java index a6c12e437e..145ebfe85b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java @@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SplitLogCounters; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Put; @@ -146,7 +147,9 @@ public abstract class AbstractTestDLS { conf.setInt("hbase.regionserver.wal.max.splitters", 3); conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10); conf.set("hbase.wal.provider", getWalProvider()); - TEST_UTIL.startMiniHBaseCluster(NUM_MASTERS, numRS); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(NUM_MASTERS).numRegionServers(numRS).build(); + TEST_UTIL.startMiniHBaseCluster(option); cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java index 836f4ffdd4..5967541bd2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java @@ -21,6 +21,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.replication.ReplicationLoadSource; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.testclassification.MasterTests; @@ -66,7 +67,10 @@ public class TestGetReplicationLoad { public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtility(); - TEST_UTIL.startMiniCluster(1, 1, 1, null, TestMasterMetrics.MyMaster.class, null); + // Set master class and using default values for other options. + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .masterClass(TestMasterMetrics.MyMaster.class).build(); + TEST_UTIL.startMiniCluster(option); cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java index d8f400ee77..2b9c91fce7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.fs.HFileSystem; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -46,7 +47,8 @@ public class TestMasterFileSystemWithWALDir { @BeforeClass public static void setupTest() throws Exception { - UTIL.startMiniCluster(true); + // Set withWALDir to true and use default values for other options. + UTIL.startMiniCluster(StartMiniClusterOption.builder().withWALDir(true).build()); } @AfterClass diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java index 91955f802f..a158f2d26c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java @@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.test.MetricsAssertHelper; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -71,7 +72,10 @@ public class TestMasterMetrics { public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtility(); - TEST_UTIL.startMiniCluster(1, 1, 1, null, MyMaster.class, null); + // Set master class and using default values for other options. + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .masterClass(MyMaster.class).build(); + TEST_UTIL.startMiniCluster(option); cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java index f1a45e1dfc..3da9a661db 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java @@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MetaTableAccessor.Visitor; import org.apache.hadoop.hbase.RegionLocations; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; @@ -196,7 +197,9 @@ public class TestMasterOperationsForRegionReplicas { rsports.add(rst.getRegionServer().getRpcServer().getListenerAddress().getPort()); } TEST_UTIL.shutdownMiniHBaseCluster(); - TEST_UTIL.startMiniHBaseCluster(1, numSlaves, rsports); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(numSlaves).rsPorts(rsports).build(); + TEST_UTIL.startMiniHBaseCluster(option); TEST_UTIL.waitTableEnabled(tableName); validateFromSnapshotFromMeta(TEST_UTIL, tableName, numRegions, numReplica, ADMIN.getConnection()); @@ -204,7 +207,7 @@ public class TestMasterOperationsForRegionReplicas { // Now shut the whole cluster down, and verify regions are assigned even if there is only // one server running TEST_UTIL.shutdownMiniHBaseCluster(); - TEST_UTIL.startMiniHBaseCluster(1, 1); + TEST_UTIL.startMiniHBaseCluster(); TEST_UTIL.waitTableEnabled(tableName); validateSingleRegionServerAssignment(ADMIN.getConnection(), numRegions, numReplica); for (int i = 1; i < numSlaves; i++) { //restore the cluster diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java index 9497210233..38f9fd1647 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java @@ -29,6 +29,7 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.master.assignment.RegionStates; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -60,7 +61,9 @@ public class TestMetaShutdownHandler { @BeforeClass public static void setUpBeforeClass() throws Exception { - TEST_UTIL.startMiniCluster(1, 3, null, null, MyRegionServer.class); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(3).rsClass(MyRegionServer.class).build(); + TEST_UTIL.startMiniCluster(option); } @AfterClass diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionMoveAndAbandon.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionMoveAndAbandon.java index 2e9c417298..bbff0920ae 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionMoveAndAbandon.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionMoveAndAbandon.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Get; @@ -69,7 +70,9 @@ public class TestRegionMoveAndAbandon { public void setup() throws Exception { UTIL = new HBaseTestingUtility(); zkCluster = UTIL.startMiniZKCluster(); - cluster = UTIL.startMiniHBaseCluster(1, 2); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(2).build(); + cluster = UTIL.startMiniHBaseCluster(option); rs1 = cluster.getRegionServer(0); rs2 = cluster.getRegionServer(1); assertEquals(2, cluster.getRegionServerThreads().size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java index e0323a0fa1..88a2ea1eee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java @@ -27,6 +27,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.LoadBalancer; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -82,7 +83,9 @@ public class TestClusterId { //Make sure RS is in blocking state Thread.sleep(10000); - TEST_UTIL.startMiniHBaseCluster(1, 0); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(0).build(); + TEST_UTIL.startMiniHBaseCluster(option); rst.waitForServerOnline(); @@ -108,7 +111,7 @@ public class TestClusterId { s.close(); } } - TEST_UTIL.startMiniHBaseCluster(1, 1); + TEST_UTIL.startMiniHBaseCluster(); HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); int expected = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration())? 2: 1; assertEquals(expected, master.getServerManager().getOnlineServersList().size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java index 52d6aae81d..3a212f8816 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java @@ -198,7 +198,7 @@ public class TestEncryptionKeyRotation { conf.set(HConstants.CRYPTO_MASTERKEY_ALTERNATE_NAME_CONF_KEY, "hbase"); // Start the cluster back up - TEST_UTIL.startMiniHBaseCluster(1, 1); + TEST_UTIL.startMiniHBaseCluster(); // Verify the table can still be loaded TEST_UTIL.waitTableAvailable(htd.getTableName(), 5000); // Double check that the store file keys can be unwrapped diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index da07c7b752..5baeda04af 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -95,6 +95,7 @@ import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.RegionTooBusyException; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TagType; import org.apache.hadoop.hbase.Waiter; @@ -4258,7 +4259,9 @@ public class TestHRegion { int regionServersCount = 3; try { - cluster = htu.startMiniCluster(1, regionServersCount, dataNodeHosts); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(regionServersCount).dataNodeHosts(dataNodeHosts).build(); + cluster = htu.startMiniCluster(option); byte[][] families = { fam1, fam2 }; Table ht = htu.createTable(tableName, families); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java index 51d2f0230a..6e2ae04e55 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java @@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread; import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ClientServiceCallable; @@ -375,7 +376,8 @@ public class TestHRegionServerBulkLoad { int millisToRun = 30000; int numScanners = 50; - UTIL.startMiniCluster(1, false, true); + // Set withWALDir to true and use default values for other options. + UTIL.startMiniCluster(StartMiniClusterOption.builder().withWALDir(true).build()); try { WAL log = UTIL.getHBaseCluster().getRegionServer(0).getWAL(null); FindBulkHBaseListener listener = new FindBulkHBaseListener(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestJoinedScanners.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestJoinedScanners.java index 3e23eeaba7..e1d9dda20a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestJoinedScanners.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestJoinedScanners.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -98,7 +99,9 @@ public class TestJoinedScanners { String[] dataNodeHosts = new String[] {"host1", "host2", "host3"}; int regionServersCount = 3; - TEST_UTIL.startMiniCluster(1, regionServersCount, dataNodeHosts); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(regionServersCount).dataNodeHosts(dataNodeHosts).build(); + TEST_UTIL.startMiniCluster(option); } @AfterClass diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java index 52ed7ba2f4..5679e75134 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java @@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.UnknownRegionException; import org.apache.hadoop.hbase.client.Admin; @@ -117,7 +118,9 @@ public class TestRegionMergeTransactionOnCluster { @BeforeClass public static void beforeAllTests() throws Exception { // Start a cluster - TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).masterClass(MyMaster.class).numRegionServers(NB_SERVERS).build(); + TEST_UTIL.startMiniCluster(option); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); MASTER = cluster.getMaster(); MASTER.balanceSwitch(false); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java index d5cbad01c4..fd2dd78bfe 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java @@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Durability; @@ -101,7 +102,9 @@ public class TestRegionServerAbort { testUtil.startMiniZKCluster(); dfsCluster = testUtil.startMiniDFSCluster(2); - cluster = testUtil.startMiniHBaseCluster(1, 2); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(2).build(); + cluster = testUtil.startMiniHBaseCluster(option); } @After diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java index eb162de773..9b422bb327 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java @@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.UnknownRegionException; import org.apache.hadoop.hbase.ZooKeeperConnectionException; @@ -135,7 +136,9 @@ public class TestSplitTransactionOnCluster { @BeforeClass public static void before() throws Exception { TESTING_UTIL.getConfiguration().setInt(HConstants.HBASE_BALANCER_PERIOD, 60000); - TESTING_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).masterClass(MyMaster.class).numRegionServers(NB_SERVERS).build(); + TESTING_UTIL.startMiniCluster(option); } @AfterClass public static void after() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/AbstractTestLogRolling.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/AbstractTestLogRolling.java index 610af61fec..83bd9abecd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/AbstractTestLogRolling.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/AbstractTestLogRolling.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -119,7 +120,8 @@ public abstract class AbstractTestLogRolling { @Before public void setUp() throws Exception { - TEST_UTIL.startMiniCluster(1, 1, 2); + // Use 2 DataNodes and default values for other StartMiniCluster options. + TEST_UTIL.startMiniCluster(StartMiniClusterOption.builder().numDataNodes(2).build()); cluster = TEST_UTIL.getHBaseCluster(); dfsCluster = TEST_UTIL.getDFSCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java index 8b795aa423..3c6999f232 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDisableInactivePeer.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.fail; import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; @@ -65,7 +66,9 @@ public class TestReplicationDisableInactivePeer extends TestReplicationBase { // disable and start the peer admin.disablePeer("2"); - utility2.startMiniHBaseCluster(1, 2); + final StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(1).numRegionServers(2).build(); + utility2.startMiniHBaseCluster(option); Get get = new Get(rowkey); for (int i = 0; i < NB_RETRIES; i++) { Result res = htable2.get(get); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDroppedTables.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDroppedTables.java index f280c7c193..31750a8bf9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDroppedTables.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationDroppedTables.java @@ -149,7 +149,7 @@ public class TestReplicationDroppedTables extends TestReplicationBase { // make sure we have a single region server only, so that all // edits for all tables go there utility1.shutdownMiniHBaseCluster(); - utility1.startMiniHBaseCluster(1, 1); + utility1.startMiniHBaseCluster(); TableName tablename = TableName.valueOf(tName); byte[] familyName = Bytes.toBytes("fam"); @@ -224,7 +224,7 @@ public class TestReplicationDroppedTables extends TestReplicationBase { // make sure we have a single region server only, so that all // edits for all tables go there utility1.shutdownMiniHBaseCluster(); - utility1.startMiniHBaseCluster(1, 1); + utility1.startMiniHBaseCluster(); TableName tablename = TableName.valueOf("testdroppedtimed"); byte[] familyName = Bytes.toBytes("fam"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALOpenAfterDNRollingStart.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALOpenAfterDNRollingStart.java index d9775a535d..7d7896c3f9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALOpenAfterDNRollingStart.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALOpenAfterDNRollingStart.java @@ -80,7 +80,7 @@ public class TestWALOpenAfterDNRollingStart { @Before public void setUp() throws IOException, InterruptedException { TEST_UTIL.getConfiguration().set("hbase.wal.provider", walProvider); - TEST_UTIL.startMiniHBaseCluster(1, 1); + TEST_UTIL.startMiniHBaseCluster(); } @After diff --git a/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java b/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java index 4134ee66ea..723b09aac7 100644 --- a/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java +++ b/hbase-spark/src/test/java/org/apache/hadoop/hbase/spark/TestJavaHBaseContext.java @@ -99,7 +99,7 @@ public class TestJavaHBaseContext implements Serializable { LOG.info("starting minicluster"); htu.startMiniZKCluster(); - htu.startMiniHBaseCluster(1, 1); + htu.startMiniHBaseCluster(); LOG.info(" - minicluster started"); -- 2.18.0