HBASE-21071 HBaseTestingUtility::startMiniCluster() to use builder pattern Signed-off-by: zhangduo <zhang...@apache.org> Signed-off-by: Michael Stack <st...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a0cbfb8e Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a0cbfb8e Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a0cbfb8e Branch: refs/heads/branch-2 Commit: a0cbfb8ea6a7e33f21a1add8bc4c288ea04a6ec2 Parents: f9790b0 Author: Mingliang Liu <lium...@apache.org> Authored: Mon Aug 20 21:42:34 2018 -0700 Committer: Michael Stack <st...@apache.org> Committed: Mon Aug 27 10:22:04 2018 -0700 ---------------------------------------------------------------------- .../example/TestRefreshHFilesEndpoint.java | 3 +- .../TableSnapshotInputFormatTestBase.java | 6 +- .../hbase/mapreduce/TestHFileOutputFormat2.java | 5 +- .../hbase/snapshot/TestExportSnapshot.java | 2 +- .../hbase/snapshot/TestMobExportSnapshot.java | 2 +- .../snapshot/TestMobSecureExportSnapshot.java | 2 +- .../snapshot/TestSecureExportSnapshot.java | 2 +- .../hadoop/hbase/rest/TestStatusResource.java | 2 +- .../hbase/rsgroup/TestRSGroupsOfflineMode.java | 5 +- .../hadoop/hbase/HBaseTestingUtility.java | 487 ++++++++++++------- .../hadoop/hbase/StartMiniClusterOption.java | 254 ++++++++++ .../hadoop/hbase/TestClientClusterMetrics.java | 4 +- .../hadoop/hbase/TestClientClusterStatus.java | 4 +- .../hbase/TestClientOperationTimeout.java | 5 +- .../hadoop/hbase/TestGlobalMemStoreSize.java | 2 +- .../hadoop/hbase/TestLocalHBaseCluster.java | 5 +- .../apache/hadoop/hbase/TestMultiVersions.java | 4 +- .../org/apache/hadoop/hbase/TestZooKeeper.java | 4 +- .../hbase/client/TestAsyncClusterAdminApi2.java | 2 +- .../hbase/client/TestGetScanPartialResult.java | 2 +- .../client/TestSeparateClientZKCluster.java | 5 +- .../hbase/client/TestTableSnapshotScanner.java | 6 +- .../hbase/client/TestUpdateConfiguration.java | 5 +- .../hbase/fs/TestBlockReorderBlockLocation.java | 2 +- .../hbase/fs/TestBlockReorderMultiBlocks.java | 2 +- .../hadoop/hbase/master/AbstractTestDLS.java | 5 +- .../hadoop/hbase/master/TestGetInfoPort.java | 2 +- .../master/TestGetLastFlushedSequenceId.java | 2 +- .../hbase/master/TestGetReplicationLoad.java | 6 +- .../hadoop/hbase/master/TestMasterFailover.java | 10 +- .../TestMasterFailoverBalancerPersistence.java | 8 +- .../master/TestMasterFileSystemWithWALDir.java | 5 +- .../hadoop/hbase/master/TestMasterMetrics.java | 6 +- .../hbase/master/TestMasterMetricsWrapper.java | 2 +- .../TestMasterOperationsForRegionReplicas.java | 7 +- .../TestMasterRestartAfterDisablingTable.java | 6 +- .../hadoop/hbase/master/TestMasterShutdown.java | 5 +- .../TestMetaAssignmentWithStopMaster.java | 5 +- .../hbase/master/TestMetaShutdownHandler.java | 5 +- .../hadoop/hbase/master/TestRollingRestart.java | 5 +- .../hbase/master/TestShutdownBackupMaster.java | 5 +- .../assignment/TestRegionMoveAndAbandon.java | 4 +- .../balancer/TestRegionLocationFinder.java | 2 +- .../balancer/TestRegionsOnMasterOptions.java | 5 +- .../TestMasterFailoverWithProcedures.java | 5 +- .../procedure/TestMasterProcedureWalLease.java | 5 +- .../hbase/namespace/TestNamespaceAuditor.java | 2 +- .../regionserver/TestClearRegionBlockCache.java | 3 +- .../hbase/regionserver/TestClusterId.java | 7 +- .../regionserver/TestEncryptionKeyRotation.java | 2 +- .../hadoop/hbase/regionserver/TestHRegion.java | 5 +- .../regionserver/TestHRegionOnCluster.java | 3 +- .../regionserver/TestHRegionServerBulkLoad.java | 4 +- .../hbase/regionserver/TestJoinedScanners.java | 5 +- .../TestRegionMergeTransactionOnCluster.java | 5 +- .../regionserver/TestRegionServerAbort.java | 4 +- .../regionserver/TestRegionServerHostname.java | 13 +- .../regionserver/TestRegionServerMetrics.java | 2 +- .../TestRegionServerOnlineConfigChange.java | 2 +- .../regionserver/TestRemoveRegionMetrics.java | 2 +- .../TestSplitTransactionOnCluster.java | 5 +- .../hadoop/hbase/regionserver/TestTags.java | 2 +- .../wal/AbstractTestLogRolling.java | 4 +- .../TestReplicationDisableInactivePeer.java | 4 +- .../TestReplicationDroppedTables.java | 4 +- .../TestGlobalReplicationThrottler.java | 4 +- .../hadoop/hbase/trace/TestHTraceHooks.java | 5 +- .../util/TestMiniClusterLoadSequential.java | 2 +- .../hadoop/hbase/wal/TestWALFiltering.java | 3 +- .../wal/TestWALOpenAfterDNRollingStart.java | 2 +- .../hbase/client/rsgroup/TestShellRSGroups.java | 2 +- 71 files changed, 754 insertions(+), 269 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestRefreshHFilesEndpoint.java ---------------------------------------------------------------------- diff --git a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestRefreshHFilesEndpoint.java b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestRefreshHFilesEndpoint.java index b28db11..d942104 100644 --- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestRefreshHFilesEndpoint.java +++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestRefreshHFilesEndpoint.java @@ -65,7 +65,6 @@ public class TestRefreshHFilesEndpoint { private static final Logger LOG = LoggerFactory.getLogger(TestRefreshHFilesEndpoint.class); private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); - private static final int NUM_MASTER = 1; private static final int NUM_RS = 2; private static final TableName TABLE_NAME = TableName.valueOf("testRefreshRegionHFilesEP"); private static final byte[] FAMILY = Bytes.toBytes("family"); @@ -84,7 +83,7 @@ public class TestRefreshHFilesEndpoint { CONF.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); CONF.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, RefreshHFilesEndpoint.class.getName()); - cluster = HTU.startMiniCluster(NUM_MASTER, NUM_RS); + cluster = HTU.startMiniCluster(NUM_RS); // Create table table = HTU.createTable(TABLE_NAME, FAMILY, SPLIT_KEY); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TableSnapshotInputFormatTestBase.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 385ad3e..744c356 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,10 @@ public abstract class TableSnapshotInputFormatTestBase { public void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(NUM_REGION_SERVERS, true); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(NUM_REGION_SERVERS).numDataNodes(NUM_REGION_SERVERS) + .createRootDir(true).build(); + UTIL.startMiniCluster(option); rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); fs = rootDir.getFileSystem(UTIL.getConfiguration()); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat2.java ---------------------------------------------------------------------- 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 d9c0ae9..679b231 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 @@ -59,6 +59,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; @@ -607,7 +608,9 @@ public class TestHFileOutputFormat2 { for (int i = 0; i < hostCount; ++i) { hostnames[i] = "datanode_" + i; } - util.startMiniCluster(1, hostCount, hostnames); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(hostCount).dataNodeHosts(hostnames).build(); + util.startMiniCluster(option); Map<String, Table> allTables = new HashMap<>(tableStr.size()); List<HFileOutputFormat2.TableInfo> tableInfo = new ArrayList<>(tableStr.size()); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java ---------------------------------------------------------------------- diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java index 6dca6e7..c988854 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshot.java @@ -99,7 +99,7 @@ public class TestExportSnapshot { @BeforeClass public static void setUpBeforeClass() throws Exception { setUpBaseConf(TEST_UTIL.getConfiguration()); - TEST_UTIL.startMiniCluster(1, 3); + TEST_UTIL.startMiniCluster(3); TEST_UTIL.startMiniMapReduceCluster(); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobExportSnapshot.java ---------------------------------------------------------------------- diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobExportSnapshot.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobExportSnapshot.java index ed605b9..9bffd08 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobExportSnapshot.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobExportSnapshot.java @@ -47,7 +47,7 @@ public class TestMobExportSnapshot extends TestExportSnapshot { @BeforeClass public static void setUpBeforeClass() throws Exception { setUpBaseConf(TEST_UTIL.getConfiguration()); - TEST_UTIL.startMiniCluster(1, 3); + TEST_UTIL.startMiniCluster(3); TEST_UTIL.startMiniMapReduceCluster(); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobSecureExportSnapshot.java ---------------------------------------------------------------------- diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobSecureExportSnapshot.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobSecureExportSnapshot.java index b4e0afd..1a5756b 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobSecureExportSnapshot.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobSecureExportSnapshot.java @@ -53,7 +53,7 @@ public class TestMobSecureExportSnapshot extends TestMobExportSnapshot { // setup configuration SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); - TEST_UTIL.startMiniCluster(1, 3); + TEST_UTIL.startMiniCluster(3); TEST_UTIL.startMiniMapReduceCluster(); // Wait for the ACL table to become available http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestSecureExportSnapshot.java ---------------------------------------------------------------------- diff --git a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestSecureExportSnapshot.java b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestSecureExportSnapshot.java index 8804b83..77da0d5 100644 --- a/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestSecureExportSnapshot.java +++ b/hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestSecureExportSnapshot.java @@ -52,7 +52,7 @@ public class TestSecureExportSnapshot extends TestExportSnapshot { // setup configuration SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); - TEST_UTIL.startMiniCluster(1, 3); + TEST_UTIL.startMiniCluster(3); TEST_UTIL.startMiniMapReduceCluster(); // Wait for the ACL table to become available http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java ---------------------------------------------------------------------- diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java index 43d586f..5e4c2d7 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java @@ -89,7 +89,7 @@ public class TestStatusResource { @BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); - TEST_UTIL.startMiniCluster(1, 1); + TEST_UTIL.startMiniCluster(); TEST_UTIL.createTable(TableName.valueOf("TestStatusResource"), Bytes.toBytes("D")); TEST_UTIL.createTable(TableName.valueOf("TestStatusResource2"), Bytes.toBytes("D")); REST_TEST_UTIL.startServletContainer(conf); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsOfflineMode.java ---------------------------------------------------------------------- diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsOfflineMode.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsOfflineMode.java index d6df910..1d5881e 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsOfflineMode.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsOfflineMode.java @@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; 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.Admin; @@ -83,7 +84,9 @@ public class TestRSGroupsOfflineMode { TEST_UTIL.getConfiguration().set( ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, "1"); - TEST_UTIL.startMiniCluster(2, 3); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(2).numRegionServers(3).numDataNodes(3).build(); + TEST_UTIL.startMiniCluster(option); cluster = TEST_UTIL.getHBaseCluster(); master = ((MiniHBaseCluster)cluster).getMaster(); master.balanceSwitch(false); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java ---------------------------------------------------------------------- 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 b938d28..732f6e6 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,197 +765,266 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { } } + /** + * Start up a minicluster of hbase, dfs, and zookeeper where WAL's walDir is created separately. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param createWALDir Whether to create a new WAL directory. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniCluster(boolean createWALDir) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .createWALDir(createWALDir).build(); + return startMiniCluster(option); + } /** * Start up a minicluster of hbase, dfs, and zookeeper. - * @throws Exception - * @return Mini hbase cluster instance created. - * @see #shutdownMiniDFSCluster() + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param createRootDir Whether to create a new root or data directory path. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster() throws Exception { - return startMiniCluster(1, 1); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numSlaves, boolean createRootDir) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(numSlaves).numDataNodes(numSlaves).createRootDir(createRootDir).build(); + return startMiniCluster(option); } /** - * 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() + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param createRootDir Whether to create a new root or data directory path. + * @param createWALDir Whether to create a new WAL directory. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(boolean withWALDir) throws Exception { - return startMiniCluster(1, 1, 1, null, null, null, false, withWALDir); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numSlaves, boolean createRootDir, + boolean createWALDir) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(numSlaves).numDataNodes(numSlaves).createRootDir(createRootDir) + .createWALDir(createWALDir).build(); + return startMiniCluster(option); } /** * Start up a minicluster of hbase, dfs, and zookeeper. - * Set the <code>create</code> 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() + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param createRootDir Whether to create a new root or data directory path. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create) - throws Exception { - return startMiniCluster(1, numSlaves, create); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves, boolean createRootDir) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numSlaves).createRootDir(createRootDir) + .numDataNodes(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 numSlaves Number of slaves to start up. We'll start this many - * datanodes and regionservers. If numSlaves is > 1, then make sure - * hbase.regionserver.info.port is -1 (i.e. no ui per regionserver) otherwise - * bind errors. - * @throws Exception + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @return The mini HBase cluster created. * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numSlaves) - throws Exception { - return startMiniCluster(1, numSlaves, false); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numSlaves).numDataNodes(numSlaves).build(); + return startMiniCluster(option); } - public MiniHBaseCluster startMiniCluster(final int numSlaves, boolean create, boolean withWALDir) - throws Exception { - return startMiniCluster(1, numSlaves, numSlaves, null, null, null, create, withWALDir); + /** + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param dataNodeHosts The hostnames of DataNodes to run on. If not null, its size will overwrite + * HDFS data node number. + * @param createRootDir Whether to create a new root or data directory path. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves, String[] dataNodeHosts, + boolean createRootDir) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numSlaves).createRootDir(createRootDir) + .numDataNodes(numSlaves).dataNodeHosts(dataNodeHosts).build(); + return startMiniCluster(option); } /** - * 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 <code>create</code> - * @throws Exception + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param dataNodeHosts The hostnames of DataNodes to run on. If not null, its size will overwrite + * HDFS data node number. + * @return The mini HBase cluster created. * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, boolean create) - throws Exception { - return startMiniCluster(numMasters, numSlaves, null, create); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves, String[] dataNodeHosts) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numSlaves) + .numDataNodes(numSlaves).dataNodeHosts(dataNodeHosts).build(); + return startMiniCluster(option); } /** - * start minicluster - * @throws Exception + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @param numDataNodes Number of datanodes. + * @return The mini HBase cluster created. * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves) - throws Exception { - return startMiniCluster(numMasters, numSlaves, null, false); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numRegionServers, int numDataNodes) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numRegionServers).numDataNodes(numDataNodes) + .build(); + return startMiniCluster(option); } - 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); - } - - /** - * 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 + /** + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numSlaves Slave node number, for both HBase region server and HDFS data node. + * @param dataNodeHosts The hostnames of DataNodes to run on. If not null, its size will overwrite + * HDFS data node number. + * @param masterClass The class to use as HMaster, or null for default. + * @param rsClass The class to use as HRegionServer, or null for default. + * @return The mini HBase cluster created. * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final String[] dataNodeHosts) throws Exception { - return startMiniCluster(numMasters, numSlaves, numSlaves, dataNodeHosts, - null, null); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numSlaves, String[] dataNodeHosts, + Class<? extends HMaster> masterClass, + Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).masterClass(masterClass) + .numRegionServers(numSlaves).rsClass(rsClass) + .numDataNodes(numSlaves).dataNodeHosts(dataNodeHosts) + .build(); + return startMiniCluster(option); } /** - * Same as {@link #startMiniCluster(int, int)}, but with custom number of datanodes. - * @param numDataNodes Number of data nodes. + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @param numDataNodes Number of datanodes. + * @param dataNodeHosts The hostnames of DataNodes to run on. If not null, its size will overwrite + * HDFS data node number. + * @param masterClass The class to use as HMaster, or null for default. + * @param rsClass The class to use as HRegionServer, or null for default. + * @return The mini HBase cluster created. + * @see #shutdownMiniCluster() + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final int numDataNodes) throws Exception { - return startMiniCluster(numMasters, numSlaves, numDataNodes, null, null, null); + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numRegionServers, int numDataNodes, + String[] dataNodeHosts, Class<? extends HMaster> masterClass, + Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass) + throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).masterClass(masterClass) + .numRegionServers(numRegionServers).rsClass(rsClass) + .numDataNodes(numDataNodes).dataNodeHosts(dataNodeHosts) + .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. - * @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 + * Start up a minicluster of hbase, dfs, and zookeeper. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @param numDataNodes Number of datanodes. + * @param dataNodeHosts The hostnames of DataNodes to run on. If not null, its size will overwrite + * HDFS data node number. + * @param masterClass The class to use as HMaster, or null for default. + * @param rsClass The class to use as HRegionServer, or null for default. + * @param createRootDir Whether to create a new root or data directory path. + * @param createWALDir Whether to create a new WAL directory. + * @return The mini HBase cluster created. * @see #shutdownMiniCluster() - * @return Mini hbase cluster instance created. + * @deprecated Use {@link #startMiniCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniCluster(int numMasters, int numRegionServers, int numDataNodes, + String[] dataNodeHosts, Class<? extends HMaster> masterClass, + Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass, boolean createRootDir, + boolean createWALDir) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).masterClass(masterClass) + .numRegionServers(numRegionServers).rsClass(rsClass) + .numDataNodes(numDataNodes).dataNodeHosts(dataNodeHosts) + .createRootDir(createRootDir).createWALDir(createWALDir) + .build(); + return startMiniCluster(option); + } + + /** + * Start up a minicluster of hbase, dfs and zookeeper clusters with given slave node number. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numSlaves slave node number, for both HBase region server and HDFS data node. + * @see #startMiniCluster(StartMiniClusterOption option) + * @see #shutdownMiniDFSCluster() */ - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, final String[] dataNodeHosts, Class<? extends HMaster> masterClass, - Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) - throws Exception { - return startMiniCluster( - numMasters, numSlaves, numSlaves, dataNodeHosts, masterClass, regionserverClass); + public MiniHBaseCluster startMiniCluster(int numSlaves) throws Exception { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(numSlaves).numDataNodes(numSlaves).build(); + return startMiniCluster(option); } - public MiniHBaseCluster startMiniCluster(final int numMasters, - final int numSlaves, int numDataNodes, final String[] dataNodeHosts, - Class<? extends HMaster> masterClass, - Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass) - throws Exception { - return startMiniCluster(numMasters, numSlaves, numDataNodes, dataNodeHosts, - masterClass, regionserverClass, false, false); + /** + * Start up a minicluster of hbase, dfs and zookeeper all using default options. + * Option default value can be found in {@link StartMiniClusterOption.Builder}. + * @see #startMiniCluster(StartMiniClusterOption option) + * @see #shutdownMiniDFSCluster() + */ + 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<? extends HMaster> masterClass, - Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> 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 +1037,35 @@ 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<Integer> 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) + * @see #shutdownMiniHBaseCluster() */ - public MiniHBaseCluster startMiniHBaseCluster(final int numMasters, - final int numSlaves, List<Integer> rsPorts, Class<? extends HMaster> masterClass, - Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> 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.isCreateRootDir()); + if (option.isCreateWALDir()) { createWALRootDir(); } // Set the hbase.fs.tmp.dir config to make sure that we have some default value. This is @@ -1025,16 +1075,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 +1096,83 @@ 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; + } + + /** + * Starts up mini hbase cluster using default options. + * Default options can be found in {@link StartMiniClusterOption.Builder}. + * @see #startMiniHBaseCluster(StartMiniClusterOption) + * @see #shutdownMiniHBaseCluster() + */ + public MiniHBaseCluster startMiniHBaseCluster() throws IOException, InterruptedException { + return startMiniHBaseCluster(StartMiniClusterOption.builder().build()); + } - return (MiniHBaseCluster)this.hbaseCluster; + /** + * Starts up mini hbase cluster. + * Usually you won't want this. You'll usually want {@link #startMiniCluster()}. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @return The mini HBase cluster created. + * @see #shutdownMiniHBaseCluster() + * @deprecated Use {@link #startMiniHBaseCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniHBaseCluster(int numMasters, int numRegionServers) + throws IOException, InterruptedException { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numRegionServers).build(); + return startMiniHBaseCluster(option); + } + + /** + * Starts up mini hbase cluster. + * Usually you won't want this. You'll usually want {@link #startMiniCluster()}. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @param rsPorts Ports that RegionServer should use. + * @return The mini HBase cluster created. + * @see #shutdownMiniHBaseCluster() + * @deprecated Use {@link #startMiniHBaseCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniHBaseCluster(int numMasters, int numRegionServers, + List<Integer> rsPorts) throws IOException, InterruptedException { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).numRegionServers(numRegionServers).rsPorts(rsPorts).build(); + return startMiniHBaseCluster(option); + } + + /** + * Starts up mini hbase cluster. + * Usually you won't want this. You'll usually want {@link #startMiniCluster()}. + * All other options will use default values, defined in {@link StartMiniClusterOption.Builder}. + * @param numMasters Master node number. + * @param numRegionServers Number of region servers. + * @param rsPorts Ports that RegionServer should use. + * @param masterClass The class to use as HMaster, or null for default. + * @param rsClass The class to use as HRegionServer, or null for default. + * @param createRootDir Whether to create a new root or data directory path. + * @param createWALDir Whether to create a new WAL directory. + * @return The mini HBase cluster created. + * @see #shutdownMiniHBaseCluster() + * @deprecated Use {@link #startMiniHBaseCluster(StartMiniClusterOption)} instead. + */ + @Deprecated + public MiniHBaseCluster startMiniHBaseCluster(int numMasters, int numRegionServers, + List<Integer> rsPorts, Class<? extends HMaster> masterClass, + Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass, + boolean createRootDir, boolean createWALDir) throws IOException, InterruptedException { + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(numMasters).masterClass(masterClass) + .numRegionServers(numRegionServers).rsClass(rsClass).rsPorts(rsPorts) + .createRootDir(createRootDir).createWALDir(createWALDir).build(); + return startMiniHBaseCluster(option); } /** http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java ---------------------------------------------------------------------- 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 0000000..ad70c95 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/StartMiniClusterOption.java @@ -0,0 +1,254 @@ +/** + * + * 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 java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hbase.master.HMaster; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * 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: + * <pre> + * StartMiniClusterOption option = StartMiniClusterOption.builder(). + * .numMasters(3).rsClass(MyRegionServer.class).createWALDir(true).build(); + * </pre> + * + * Default values can be found in {@link Builder}. + */ +@InterfaceAudience.Public +public final 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<? extends HMaster> masterClass; + + /** + * Number of region servers to start up. + * If this value 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<Integer> rsPorts; + /** + * The class to use as HRegionServer, or null for default. + */ + private Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> 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 new root or data directory path. If true, the newly created data directory + * will be configured as HBase rootdir. This will overwrite existing root directory config. + */ + private final boolean createRootDir; + + /** + * Whether to create a new WAL directory. If true, the newly created directory will be configured + * as HBase wal.dir which is separate from HBase rootdir. + */ + private final boolean createWALDir; + + /** + * Private constructor. Use {@link Builder#build()}. + */ + private StartMiniClusterOption(int numMasters, Class<? extends HMaster> masterClass, + int numRegionServers, List<Integer> rsPorts, + Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass, int numDataNodes, + String[] dataNodeHosts, int numZkServers, boolean createRootDir, boolean createWALDir) { + 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.createRootDir = createRootDir; + this.createWALDir = createWALDir; + } + + public int getNumMasters() { + return numMasters; + } + + public Class<? extends HMaster> getMasterClass() { + return masterClass; + } + + public int getNumRegionServers() { + return numRegionServers; + } + + public List<Integer> getRsPorts() { + return rsPorts; + } + + public Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> getRsClass() { + return rsClass; + } + + public int getNumDataNodes() { + return numDataNodes; + } + + public String[] getDataNodeHosts() { + return dataNodeHosts; + } + + public int getNumZkServers() { + return numZkServers; + } + + public boolean isCreateRootDir() { + return createRootDir; + } + + public boolean isCreateWALDir() { + return createWALDir; + } + + @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 + + ", createRootDir=" + createRootDir + ", createWALDir=" + createWALDir + '}'; + } + + /** + * @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 final class Builder { + private int numMasters = 1; + private Class<? extends HMaster> masterClass = null; + private int numRegionServers = 1; + private List<Integer> rsPorts = null; + private Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> rsClass = null; + private int numDataNodes = 1; + private String[] dataNodeHosts = null; + private int numZkServers = 1; + private boolean createRootDir = false; + private boolean createWALDir = 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, createRootDir, createWALDir); + } + + public Builder numMasters(int numMasters) { + this.numMasters = numMasters; + return this; + } + + public Builder masterClass(Class<? extends HMaster> masterClass) { + this.masterClass = masterClass; + return this; + } + + public Builder numRegionServers(int numRegionServers) { + this.numRegionServers = numRegionServers; + return this; + } + + public Builder rsPorts(List<Integer> rsPorts) { + this.rsPorts = rsPorts; + return this; + } + + public Builder rsClass(Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> 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 createRootDir(boolean createRootDir) { + this.createRootDir = createRootDir; + return this; + } + + public Builder createWALDir(boolean createWALDir) { + this.createWALDir = createWALDir; + return this; + } + } + +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterMetrics.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterMetrics.java index a2605f2..ff04bb2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterMetrics.java @@ -66,7 +66,9 @@ public class TestClientClusterMetrics { Configuration conf = HBaseConfiguration.create(); conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName()); UTIL = new HBaseTestingUtility(conf); - UTIL.startMiniCluster(MASTERS, SLAVES); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(MASTERS).numRegionServers(SLAVES).numDataNodes(SLAVES).build(); + UTIL.startMiniCluster(option); CLUSTER = UTIL.getHBaseCluster(); CLUSTER.waitForActiveAndReadyMaster(); ADMIN = UTIL.getAdmin(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java index 392ff6e..960b18d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java @@ -67,7 +67,9 @@ public class TestClientClusterStatus { Configuration conf = HBaseConfiguration.create(); conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName()); UTIL = new HBaseTestingUtility(conf); - UTIL.startMiniCluster(MASTERS, SLAVES); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(MASTERS).numRegionServers(SLAVES).numDataNodes(SLAVES).build(); + UTIL.startMiniCluster(option); CLUSTER = UTIL.getHBaseCluster(); CLUSTER.waitForActiveAndReadyMaster(); ADMIN = UTIL.getAdmin(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java ---------------------------------------------------------------------- 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 fa4e017..6c46e50 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 use default values for other options. + StartMiniClusterOption option = StartMiniClusterOption.builder() + .rsClass(DelayedRegionServer.class).build(); + TESTING_UTIL.startMiniCluster(option); } @Before http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java index 2e2d978..9aecf06 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java @@ -78,7 +78,7 @@ public class TestGlobalMemStoreSize { LOG.info("Starting cluster"); Configuration conf = HBaseConfiguration.create(); TEST_UTIL = new HBaseTestingUtility(conf); - TEST_UTIL.startMiniCluster(1, regionServerNum); + TEST_UTIL.startMiniCluster(regionServerNum); cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java ---------------------------------------------------------------------- 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 4403739..7e9e7cb 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 use default values for other options. + 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); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java ---------------------------------------------------------------------- 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 a732740..fe645bb 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); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(NUM_SLAVES).build(); + UTIL.startMiniHBaseCluster(option); // Make a new connection. table = UTIL.getConnection().getTable(desc.getTableName()); // Overwrite previous value http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java ---------------------------------------------------------------------- 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 2d57954..a419e22 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); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(2).numRegionServers(2).build(); + TEST_UTIL.startMiniHBaseCluster(option); } @After http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi2.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi2.java index 94528ea..22a09eb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi2.java @@ -63,7 +63,7 @@ public class TestAsyncClusterAdminApi2 extends TestAsyncAdminBase { @Before @Override public void setUp() throws Exception { - TEST_UTIL.startMiniCluster(1, 3); + TEST_UTIL.startMiniCluster(3); ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); admin = ASYNC_CONN.getAdmin(); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetScanPartialResult.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetScanPartialResult.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetScanPartialResult.java index 0925aee..e9295c4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetScanPartialResult.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestGetScanPartialResult.java @@ -52,7 +52,7 @@ public class TestGetScanPartialResult { @BeforeClass public static void setUp() throws Exception { - TEST_UTIL.startMiniCluster(1); + TEST_UTIL.startMiniCluster(); TEST_UTIL.createTable(TABLE, CF); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSeparateClientZKCluster.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSeparateClientZKCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSeparateClientZKCluster.java index 533af93..dce8e79 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSeparateClientZKCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSeparateClientZKCluster.java @@ -25,6 +25,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.master.HMaster; import org.apache.hadoop.hbase.master.NoSuchProcedureException; @@ -82,7 +83,9 @@ public class TestSeparateClientZKCluster { // reduce zk session timeout to easier trigger session expiration TEST_UTIL.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, ZK_SESSION_TIMEOUT); // Start a cluster with 2 masters and 3 regionservers. - TEST_UTIL.startMiniCluster(2, 3); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(2).numRegionServers(3).numDataNodes(3).build(); + TEST_UTIL.startMiniCluster(option); } @AfterClass http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java ---------------------------------------------------------------------- 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 408953a..e999f8c 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,10 @@ public class TestTableSnapshotScanner { public void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(NUM_REGION_SERVERS, true); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numRegionServers(NUM_REGION_SERVERS).numDataNodes(NUM_REGION_SERVERS) + .createRootDir(true).build(); + UTIL.startMiniCluster(option); rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); fs = rootDir.getFileSystem(UTIL.getConfiguration()); } http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestUpdateConfiguration.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestUpdateConfiguration.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestUpdateConfiguration.java index 09dc40c..eae56fd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestUpdateConfiguration.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestUpdateConfiguration.java @@ -28,6 +28,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -48,7 +49,9 @@ public class TestUpdateConfiguration { @BeforeClass public static void setup() throws Exception { - TEST_UTIL.startMiniCluster(2, 1); + // Set master number and use default values for other options. + StartMiniClusterOption option = StartMiniClusterOption.builder().numMasters(2).build(); + TEST_UTIL.startMiniCluster(option); } @Test http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java ---------------------------------------------------------------------- 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 5ef5ba4..ce2877c 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); + MiniHBaseCluster hbm = htu.startMiniHBaseCluster(); conf = hbm.getConfiguration(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java ---------------------------------------------------------------------- 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 937b5dd..ad2b2d4 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); + MiniHBaseCluster hbm = htu.startMiniHBaseCluster(); hbm.waitForActiveAndReadyMaster(); HRegionServer targetRs = LoadBalancer.isTablesOnMaster(hbm.getConf())? hbm.getMaster(): hbm.getRegionServer(0); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java ---------------------------------------------------------------------- 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 bc4d32c..f828926 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); + 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(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java index ddf2e83..5b27bf5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java @@ -45,7 +45,7 @@ public class TestGetInfoPort { @Before public void setUp() throws Exception { testUtil.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); - testUtil.startMiniCluster(1, 1); + testUtil.startMiniCluster(); } @After http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java index c930a1b..387ccf8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java @@ -66,7 +66,7 @@ public class TestGetLastFlushedSequenceId { @Before public void setUp() throws Exception { testUtil.getConfiguration().setInt("hbase.regionserver.msginterval", 1000); - testUtil.startMiniCluster(1, 1); + testUtil.startMiniCluster(); } @After http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java ---------------------------------------------------------------------- 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 836f4ff..bf72383 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 use default values for other options. + 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(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java index b93c015..a27936d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java @@ -27,6 +27,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.master.RegionState.State; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.testclassification.FlakeyTests; @@ -66,7 +67,9 @@ public class TestMasterFailover { // Start the cluster HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); try { - TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build(); + TEST_UTIL.startMiniCluster(option); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); // get all the master threads @@ -166,12 +169,9 @@ public class TestMasterFailover { */ @Test public void testMetaInTransitionWhenMasterFailover() throws Exception { - final int NUM_MASTERS = 1; - final int NUM_RS = 1; - // Start the cluster HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); + TEST_UTIL.startMiniCluster(); try { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Cluster started"); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java index 8678684..337cdfa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.MiniHBaseCluster; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; @@ -49,13 +50,12 @@ public class TestMasterFailoverBalancerPersistence { */ @Test public void testMasterFailoverBalancerPersistence() throws Exception { - final int NUM_MASTERS = 3; - final int NUM_RS = 1; - // Start the cluster HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(3).build(); + TEST_UTIL.startMiniCluster(option); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); assertTrue(cluster.waitForActiveAndReadyMaster()); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java ---------------------------------------------------------------------- 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 d8f400e..62e5b5b 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,7 +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.fs.HFileSystem; +import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.FSUtils; @@ -46,7 +46,8 @@ public class TestMasterFileSystemWithWALDir { @BeforeClass public static void setupTest() throws Exception { - UTIL.startMiniCluster(true); + // Set createWALDir to true and use default values for other options. + UTIL.startMiniCluster(StartMiniClusterOption.builder().createWALDir(true).build()); } @AfterClass http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java ---------------------------------------------------------------------- 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 91955f8..dec65c8 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 use default values for other options. + 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(); http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java index ccc6104..395095e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java @@ -50,7 +50,7 @@ public class TestMasterMetricsWrapper { @BeforeClass public static void setup() throws Exception { - TEST_UTIL.startMiniCluster(1, NUM_RS); + TEST_UTIL.startMiniCluster(NUM_RS); } @AfterClass http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java ---------------------------------------------------------------------- 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 f1a45e1..3f4590c 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); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .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 http://git-wip-us.apache.org/repos/asf/hbase/blob/a0cbfb8e/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java index 234d563..665e5c6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; 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.client.Admin; import org.apache.hadoop.hbase.client.RegionLocator; @@ -61,14 +62,15 @@ public class TestMasterRestartAfterDisablingTable { public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Exception { final int NUM_MASTERS = 2; - final int NUM_RS = 1; final int NUM_REGIONS_TO_CREATE = 4; // Start the cluster log("Starting cluster"); Configuration conf = HBaseConfiguration.create(); HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf); - TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); + StartMiniClusterOption option = StartMiniClusterOption.builder() + .numMasters(NUM_MASTERS).build(); + TEST_UTIL.startMiniCluster(option); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); log("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster();