HBASE-26098 Support passing a customized Configuration object when creating TestingHBaseCluster (#3540)

Signed-off-by: Yulin Niu <niuyulin@apache.org>
This commit is contained in:
Duo Zhang 2021-07-31 14:34:17 +08:00 committed by GitHub
parent 8fbc2d2400
commit 90f23d4743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -35,7 +35,7 @@ import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFacto
@InterfaceAudience.Private
class TestingHBaseClusterImpl implements TestingHBaseCluster {
private final HBaseTestingUtil util = new HBaseTestingUtil();
private final HBaseTestingUtil util;
private final StartTestingClusterOption option;
@ -47,6 +47,7 @@ class TestingHBaseClusterImpl implements TestingHBaseCluster {
private boolean miniHBaseClusterRunning = false;
TestingHBaseClusterImpl(TestingHBaseClusterOption option) {
this.util = new HBaseTestingUtil(option.conf());
this.option = option.convert();
}

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.testing;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.StartTestingClusterOption;
import org.apache.yetus.audience.InterfaceAudience;
@ -39,6 +40,11 @@ import org.apache.yetus.audience.InterfaceAudience;
@InterfaceAudience.Public
public final class TestingHBaseClusterOption {
/**
* Configuration for this testing cluster. Can be {@code null}.
*/
private final Configuration conf;
/**
* Number of masters to start up. We'll start this many hbase masters.
*/
@ -95,9 +101,10 @@ public final class TestingHBaseClusterOption {
/**
* Private constructor. Use {@link Builder#build()}.
*/
private TestingHBaseClusterOption(int numMasters, int numAlwaysStandByMasters,
private TestingHBaseClusterOption(Configuration conf, int numMasters, int numAlwaysStandByMasters,
int numRegionServers, List<Integer> rsPorts, int numDataNodes, String[] dataNodeHosts,
int numZkServers, boolean createRootDir, boolean createWALDir) {
this.conf = conf;
this.numMasters = numMasters;
this.numAlwaysStandByMasters = numAlwaysStandByMasters;
this.numRegionServers = numRegionServers;
@ -109,6 +116,10 @@ public final class TestingHBaseClusterOption {
this.createWALDir = createWALDir;
}
public Configuration conf() {
return conf;
}
public int getNumMasters() {
return numMasters;
}
@ -176,6 +187,7 @@ public final class TestingHBaseClusterOption {
* tests fail.
*/
public static final class Builder {
private Configuration conf;
private int numMasters = 1;
private int numAlwaysStandByMasters = 0;
private int numRegionServers = 1;
@ -193,8 +205,14 @@ public final class TestingHBaseClusterOption {
if (dataNodeHosts != null && dataNodeHosts.length != 0) {
numDataNodes = dataNodeHosts.length;
}
return new TestingHBaseClusterOption(numMasters, numAlwaysStandByMasters, numRegionServers,
rsPorts, numDataNodes, dataNodeHosts, numZkServers, createRootDir, createWALDir);
return new TestingHBaseClusterOption(conf, numMasters, numAlwaysStandByMasters,
numRegionServers, rsPorts, numDataNodes, dataNodeHosts, numZkServers, createRootDir,
createWALDir);
}
public Builder conf(Configuration conf) {
this.conf = conf;
return this;
}
public Builder numMasters(int numMasters) {