From 90f23d47437498a1821c6bb1582c4f19a2a2ce62 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Sat, 31 Jul 2021 14:34:17 +0800 Subject: [PATCH] HBASE-26098 Support passing a customized Configuration object when creating TestingHBaseCluster (#3540) Signed-off-by: Yulin Niu --- .../testing/TestingHBaseClusterImpl.java | 3 ++- .../testing/TestingHBaseClusterOption.java | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java b/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java index e2c42616091..5128b907820 100644 --- a/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java +++ b/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java @@ -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(); } diff --git a/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterOption.java b/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterOption.java index 6ca36e8b63b..87d6e2a07de 100644 --- a/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterOption.java +++ b/hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterOption.java @@ -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 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) {