Skip to content

Commit 3b9491b

Browse files
xicmApache9
authored andcommitted
HBASE-26167 Allow users to not start zookeeper and dfs cluster when using TestingHBaseCluster (#4534)
Co-authored-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Yu Li <liyu@apache.org> (cherry picked from commit 7fc1674) Conflicts: hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java
1 parent 96693e8 commit 3b9491b

8 files changed

+422
-3
lines changed

hbase-testing-util/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,38 @@
307307
</exclusion>
308308
</exclusions>
309309
</dependency>
310+
<dependency>
311+
<groupId>org.apache.hadoop</groupId>
312+
<artifactId>hadoop-hdfs</artifactId>
313+
<type>test-jar</type>
314+
<scope>compile</scope>
315+
</dependency>
316+
<dependency>
317+
<groupId>org.apache.hadoop</groupId>
318+
<artifactId>hadoop-mapreduce-client-jobclient</artifactId>
319+
<type>test-jar</type>
320+
<scope>compile</scope>
321+
</dependency>
310322
<dependency>
311323
<groupId>org.apache.hadoop</groupId>
312324
<artifactId>hadoop-minikdc</artifactId>
325+
<scope>compile</scope>
326+
<exclusions>
327+
<exclusion>
328+
<groupId>bouncycastle</groupId>
329+
<artifactId>bcprov-jdk15</artifactId>
330+
</exclusion>
331+
</exclusions>
332+
</dependency>
333+
<dependency>
334+
<groupId>org.apache.kerby</groupId>
335+
<artifactId>kerb-client</artifactId>
336+
<scope>compile</scope>
337+
</dependency>
338+
<dependency>
339+
<groupId>org.apache.kerby</groupId>
340+
<artifactId>kerb-simplekdc</artifactId>
341+
<scope>compile</scope>
313342
</dependency>
314343
</dependencies>
315344
</profile>

hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
import java.util.List;
2121
import java.util.Optional;
22+
import java.util.UUID;
2223
import java.util.concurrent.CompletableFuture;
2324
import java.util.concurrent.ExecutorService;
2425
import java.util.concurrent.Executors;
2526
import java.util.stream.Collectors;
2627
import org.apache.hadoop.conf.Configuration;
28+
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
2729
import org.apache.hadoop.hbase.HBaseTestingUtility;
30+
import org.apache.hadoop.hbase.HConstants;
2831
import org.apache.hadoop.hbase.ServerName;
2932
import org.apache.hadoop.hbase.StartMiniClusterOption;
3033
import org.apache.hadoop.hbase.client.RegionInfo;
@@ -46,6 +49,10 @@ class TestingHBaseClusterImpl implements TestingHBaseCluster {
4649

4750
private final StartMiniClusterOption option;
4851

52+
private final String externalDfsUri;
53+
54+
private final String externalZkConnectString;
55+
4956
private final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
5057
.setNameFormat(getClass().getSuperclass() + "-%d").setDaemon(true).build());
5158

@@ -56,6 +63,8 @@ class TestingHBaseClusterImpl implements TestingHBaseCluster {
5663
TestingHBaseClusterImpl(TestingHBaseClusterOption option) {
5764
this.util = new HBaseTestingUtility(option.conf());
5865
this.option = option.convert();
66+
this.externalDfsUri = option.getExternalDfsUri();
67+
this.externalZkConnectString = option.getExternalZkConnectString();
5968
}
6069

6170
@Override
@@ -137,7 +146,20 @@ public void startHBaseCluster() throws Exception {
137146
@Override
138147
public void start() throws Exception {
139148
Preconditions.checkState(!miniClusterRunning, "Cluster has already been started");
140-
util.startMiniCluster(option);
149+
if (externalZkConnectString == null) {
150+
util.startMiniZKCluster();
151+
} else {
152+
Configuration conf = util.getConfiguration();
153+
conf.set(HConstants.ZOOKEEPER_QUORUM, externalZkConnectString);
154+
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/" + UUID.randomUUID().toString());
155+
}
156+
if (externalDfsUri == null) {
157+
util.startMiniDFSCluster(option.getNumDataNodes(), option.getDataNodeHosts());
158+
} else {
159+
Configuration conf = util.getConfiguration();
160+
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, externalDfsUri);
161+
}
162+
util.startMiniHBaseCluster(option);
141163
miniClusterRunning = true;
142164
miniHBaseClusterRunning = true;
143165
}

hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterOption.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ public final class TestingHBaseClusterOption {
9898
*/
9999
private final boolean createWALDir;
100100

101+
private final String externalDfsUri;
102+
103+
private final String externalZkConnectString;
104+
101105
/**
102106
* Private constructor. Use {@link Builder#build()}.
103107
*/
104108
private TestingHBaseClusterOption(Configuration conf, int numMasters, int numAlwaysStandByMasters,
105109
int numRegionServers, List<Integer> rsPorts, int numDataNodes, String[] dataNodeHosts,
106-
int numZkServers, boolean createRootDir, boolean createWALDir) {
110+
int numZkServers, boolean createRootDir, boolean createWALDir, String externalDfsUri,
111+
String externalZkConnectString) {
107112
this.conf = conf;
108113
this.numMasters = numMasters;
109114
this.numAlwaysStandByMasters = numAlwaysStandByMasters;
@@ -114,6 +119,8 @@ private TestingHBaseClusterOption(Configuration conf, int numMasters, int numAlw
114119
this.numZkServers = numZkServers;
115120
this.createRootDir = createRootDir;
116121
this.createWALDir = createWALDir;
122+
this.externalDfsUri = externalDfsUri;
123+
this.externalZkConnectString = externalZkConnectString;
117124
}
118125

119126
public Configuration conf() {
@@ -156,6 +163,14 @@ public boolean isCreateWALDir() {
156163
return createWALDir;
157164
}
158165

166+
public String getExternalDfsUri() {
167+
return externalDfsUri;
168+
}
169+
170+
public String getExternalZkConnectString() {
171+
return externalZkConnectString;
172+
}
173+
159174
@Override
160175
public String toString() {
161176
return "StartMiniClusterOption{" + "numMasters=" + numMasters + ", numRegionServers="
@@ -197,6 +212,8 @@ public static final class Builder {
197212
private int numZkServers = 1;
198213
private boolean createRootDir = false;
199214
private boolean createWALDir = false;
215+
private String externalDfsUri = null;
216+
private String externalZkConnectString = null;
200217

201218
private Builder() {
202219
}
@@ -207,7 +224,7 @@ public TestingHBaseClusterOption build() {
207224
}
208225
return new TestingHBaseClusterOption(conf, numMasters, numAlwaysStandByMasters,
209226
numRegionServers, rsPorts, numDataNodes, dataNodeHosts, numZkServers, createRootDir,
210-
createWALDir);
227+
createWALDir, externalDfsUri, externalZkConnectString);
211228
}
212229

213230
public Builder conf(Configuration conf) {
@@ -259,5 +276,15 @@ public Builder createWALDir(boolean createWALDir) {
259276
this.createWALDir = createWALDir;
260277
return this;
261278
}
279+
280+
public Builder useExternalDfs(String uri) {
281+
this.externalDfsUri = uri;
282+
return this;
283+
}
284+
285+
public Builder useExternalZooKeeper(String connectString) {
286+
this.externalZkConnectString = connectString;
287+
return this;
288+
}
262289
}
263290
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.testing;
19+
20+
import static org.junit.Assert.assertNotEquals;
21+
22+
import org.apache.hadoop.hbase.HBaseClassTestRule;
23+
import org.apache.hadoop.hbase.HBaseTestingUtility;
24+
import org.apache.hadoop.hbase.HConstants;
25+
import org.apache.hadoop.hbase.testclassification.LargeTests;
26+
import org.apache.hadoop.hbase.testclassification.MiscTests;
27+
import org.junit.ClassRule;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({ MiscTests.class, LargeTests.class })
31+
public class TestTestingHBaseClusterReplicationShareDfs
32+
extends TestingHBaseClusterReplicationTestBase {
33+
34+
@ClassRule
35+
public static final HBaseClassTestRule CLASS_RULE =
36+
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareDfs.class);
37+
38+
private HBaseTestingUtility util = new HBaseTestingUtility();
39+
40+
@Override
41+
protected void startClusters() throws Exception {
42+
util.startMiniDFSCluster(1);
43+
String dfsUri = util.getDFSCluster().getFileSystem().getUri().toString();
44+
sourceCluster = TestingHBaseCluster
45+
.create(TestingHBaseClusterOption.builder().useExternalDfs(dfsUri).build());
46+
sourceCluster.start();
47+
peerCluster = TestingHBaseCluster
48+
.create(TestingHBaseClusterOption.builder().useExternalDfs(dfsUri).build());
49+
peerCluster.start();
50+
assertNotEquals(sourceCluster.getConf().get(HConstants.HBASE_DIR),
51+
peerCluster.getConf().get(HConstants.HBASE_DIR));
52+
}
53+
54+
@Override
55+
protected void stopClusters() throws Exception {
56+
util.shutdownMiniDFSCluster();
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.testing;
19+
20+
import static org.junit.Assert.assertNotEquals;
21+
22+
import org.apache.hadoop.hbase.HBaseClassTestRule;
23+
import org.apache.hadoop.hbase.HBaseTestingUtility;
24+
import org.apache.hadoop.hbase.HConstants;
25+
import org.apache.hadoop.hbase.testclassification.LargeTests;
26+
import org.apache.hadoop.hbase.testclassification.MiscTests;
27+
import org.junit.ClassRule;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({ MiscTests.class, LargeTests.class })
31+
public class TestTestingHBaseClusterReplicationShareZk
32+
extends TestingHBaseClusterReplicationTestBase {
33+
34+
@ClassRule
35+
public static final HBaseClassTestRule CLASS_RULE =
36+
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZk.class);
37+
38+
private HBaseTestingUtility util = new HBaseTestingUtility();
39+
40+
@Override
41+
protected void startClusters() throws Exception {
42+
util.startMiniZKCluster();
43+
String zkConnectString = util.getZkCluster().getAddress().toString();
44+
sourceCluster = TestingHBaseCluster
45+
.create(TestingHBaseClusterOption.builder().useExternalZooKeeper(zkConnectString).build());
46+
sourceCluster.start();
47+
peerCluster = TestingHBaseCluster
48+
.create(TestingHBaseClusterOption.builder().useExternalZooKeeper(zkConnectString).build());
49+
peerCluster.start();
50+
assertNotEquals(sourceCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT),
51+
peerCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
52+
}
53+
54+
@Override
55+
protected void stopClusters() throws Exception {
56+
util.shutdownMiniZKCluster();
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.testing;
19+
20+
import static org.junit.Assert.assertNotEquals;
21+
22+
import org.apache.hadoop.hbase.HBaseClassTestRule;
23+
import org.apache.hadoop.hbase.HBaseTestingUtility;
24+
import org.apache.hadoop.hbase.HConstants;
25+
import org.apache.hadoop.hbase.testclassification.LargeTests;
26+
import org.apache.hadoop.hbase.testclassification.MiscTests;
27+
import org.junit.ClassRule;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({ MiscTests.class, LargeTests.class })
31+
public class TestTestingHBaseClusterReplicationShareZkDfs
32+
extends TestingHBaseClusterReplicationTestBase {
33+
34+
@ClassRule
35+
public static final HBaseClassTestRule CLASS_RULE =
36+
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZkDfs.class);
37+
38+
private HBaseTestingUtility util = new HBaseTestingUtility();
39+
40+
@Override
41+
protected void startClusters() throws Exception {
42+
util.startMiniZKCluster();
43+
util.startMiniDFSCluster(1);
44+
String zkConnectString = util.getZkCluster().getAddress().toString();
45+
String dfsUri = util.getDFSCluster().getFileSystem().getUri().toString();
46+
sourceCluster = TestingHBaseCluster.create(TestingHBaseClusterOption.builder()
47+
.useExternalZooKeeper(zkConnectString).useExternalDfs(dfsUri).build());
48+
sourceCluster.start();
49+
peerCluster = TestingHBaseCluster.create(TestingHBaseClusterOption.builder()
50+
.useExternalZooKeeper(zkConnectString).useExternalDfs(dfsUri).build());
51+
peerCluster.start();
52+
assertNotEquals(sourceCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT),
53+
peerCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
54+
assertNotEquals(sourceCluster.getConf().get(HConstants.HBASE_DIR),
55+
peerCluster.getConf().get(HConstants.HBASE_DIR));
56+
}
57+
58+
@Override
59+
protected void stopClusters() throws Exception {
60+
util.shutdownMiniDFSCluster();
61+
util.shutdownMiniZKCluster();
62+
}
63+
}

0 commit comments

Comments
 (0)