Skip to content

Commit

Permalink
HBASE-26167 Allow users to not start zookeeper and dfs cluster when u…
Browse files Browse the repository at this point in the history
…sing TestingHBaseCluster (apache#4534)

Co-authored-by: Duo Zhang <[email protected]>
Signed-off-by: Yu Li <[email protected]>
(cherry picked from commit 7fc1674)

Conflicts:
	hbase-testing-util/src/main/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterImpl.java
  • Loading branch information
xicm authored and Apache9 committed Jun 15, 2022
1 parent 96693e8 commit 3b9491b
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 3 deletions.
29 changes: 29 additions & 0 deletions hbase-testing-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,38 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<type>test-jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-jobclient</artifactId>
<type>test-jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minikdc</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.kerby</groupId>
<artifactId>kerb-simplekdc</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.StartMiniClusterOption;
import org.apache.hadoop.hbase.client.RegionInfo;
Expand All @@ -46,6 +49,10 @@ class TestingHBaseClusterImpl implements TestingHBaseCluster {

private final StartMiniClusterOption option;

private final String externalDfsUri;

private final String externalZkConnectString;

private final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
.setNameFormat(getClass().getSuperclass() + "-%d").setDaemon(true).build());

Expand All @@ -56,6 +63,8 @@ class TestingHBaseClusterImpl implements TestingHBaseCluster {
TestingHBaseClusterImpl(TestingHBaseClusterOption option) {
this.util = new HBaseTestingUtility(option.conf());
this.option = option.convert();
this.externalDfsUri = option.getExternalDfsUri();
this.externalZkConnectString = option.getExternalZkConnectString();
}

@Override
Expand Down Expand Up @@ -137,7 +146,20 @@ public void startHBaseCluster() throws Exception {
@Override
public void start() throws Exception {
Preconditions.checkState(!miniClusterRunning, "Cluster has already been started");
util.startMiniCluster(option);
if (externalZkConnectString == null) {
util.startMiniZKCluster();
} else {
Configuration conf = util.getConfiguration();
conf.set(HConstants.ZOOKEEPER_QUORUM, externalZkConnectString);
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/" + UUID.randomUUID().toString());
}
if (externalDfsUri == null) {
util.startMiniDFSCluster(option.getNumDataNodes(), option.getDataNodeHosts());
} else {
Configuration conf = util.getConfiguration();
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, externalDfsUri);
}
util.startMiniHBaseCluster(option);
miniClusterRunning = true;
miniHBaseClusterRunning = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ public final class TestingHBaseClusterOption {
*/
private final boolean createWALDir;

private final String externalDfsUri;

private final String externalZkConnectString;

/**
* Private constructor. Use {@link Builder#build()}.
*/
private TestingHBaseClusterOption(Configuration conf, int numMasters, int numAlwaysStandByMasters,
int numRegionServers, List<Integer> rsPorts, int numDataNodes, String[] dataNodeHosts,
int numZkServers, boolean createRootDir, boolean createWALDir) {
int numZkServers, boolean createRootDir, boolean createWALDir, String externalDfsUri,
String externalZkConnectString) {
this.conf = conf;
this.numMasters = numMasters;
this.numAlwaysStandByMasters = numAlwaysStandByMasters;
Expand All @@ -114,6 +119,8 @@ private TestingHBaseClusterOption(Configuration conf, int numMasters, int numAlw
this.numZkServers = numZkServers;
this.createRootDir = createRootDir;
this.createWALDir = createWALDir;
this.externalDfsUri = externalDfsUri;
this.externalZkConnectString = externalZkConnectString;
}

public Configuration conf() {
Expand Down Expand Up @@ -156,6 +163,14 @@ public boolean isCreateWALDir() {
return createWALDir;
}

public String getExternalDfsUri() {
return externalDfsUri;
}

public String getExternalZkConnectString() {
return externalZkConnectString;
}

@Override
public String toString() {
return "StartMiniClusterOption{" + "numMasters=" + numMasters + ", numRegionServers="
Expand Down Expand Up @@ -197,6 +212,8 @@ public static final class Builder {
private int numZkServers = 1;
private boolean createRootDir = false;
private boolean createWALDir = false;
private String externalDfsUri = null;
private String externalZkConnectString = null;

private Builder() {
}
Expand All @@ -207,7 +224,7 @@ public TestingHBaseClusterOption build() {
}
return new TestingHBaseClusterOption(conf, numMasters, numAlwaysStandByMasters,
numRegionServers, rsPorts, numDataNodes, dataNodeHosts, numZkServers, createRootDir,
createWALDir);
createWALDir, externalDfsUri, externalZkConnectString);
}

public Builder conf(Configuration conf) {
Expand Down Expand Up @@ -259,5 +276,15 @@ public Builder createWALDir(boolean createWALDir) {
this.createWALDir = createWALDir;
return this;
}

public Builder useExternalDfs(String uri) {
this.externalDfsUri = uri;
return this;
}

public Builder useExternalZooKeeper(String connectString) {
this.externalZkConnectString = connectString;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.testing;

import static org.junit.Assert.assertNotEquals;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;

@Category({ MiscTests.class, LargeTests.class })
public class TestTestingHBaseClusterReplicationShareDfs
extends TestingHBaseClusterReplicationTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareDfs.class);

private HBaseTestingUtility util = new HBaseTestingUtility();

@Override
protected void startClusters() throws Exception {
util.startMiniDFSCluster(1);
String dfsUri = util.getDFSCluster().getFileSystem().getUri().toString();
sourceCluster = TestingHBaseCluster
.create(TestingHBaseClusterOption.builder().useExternalDfs(dfsUri).build());
sourceCluster.start();
peerCluster = TestingHBaseCluster
.create(TestingHBaseClusterOption.builder().useExternalDfs(dfsUri).build());
peerCluster.start();
assertNotEquals(sourceCluster.getConf().get(HConstants.HBASE_DIR),
peerCluster.getConf().get(HConstants.HBASE_DIR));
}

@Override
protected void stopClusters() throws Exception {
util.shutdownMiniDFSCluster();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.testing;

import static org.junit.Assert.assertNotEquals;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;

@Category({ MiscTests.class, LargeTests.class })
public class TestTestingHBaseClusterReplicationShareZk
extends TestingHBaseClusterReplicationTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZk.class);

private HBaseTestingUtility util = new HBaseTestingUtility();

@Override
protected void startClusters() throws Exception {
util.startMiniZKCluster();
String zkConnectString = util.getZkCluster().getAddress().toString();
sourceCluster = TestingHBaseCluster
.create(TestingHBaseClusterOption.builder().useExternalZooKeeper(zkConnectString).build());
sourceCluster.start();
peerCluster = TestingHBaseCluster
.create(TestingHBaseClusterOption.builder().useExternalZooKeeper(zkConnectString).build());
peerCluster.start();
assertNotEquals(sourceCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT),
peerCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
}

@Override
protected void stopClusters() throws Exception {
util.shutdownMiniZKCluster();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.testing;

import static org.junit.Assert.assertNotEquals;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;

@Category({ MiscTests.class, LargeTests.class })
public class TestTestingHBaseClusterReplicationShareZkDfs
extends TestingHBaseClusterReplicationTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZkDfs.class);

private HBaseTestingUtility util = new HBaseTestingUtility();

@Override
protected void startClusters() throws Exception {
util.startMiniZKCluster();
util.startMiniDFSCluster(1);
String zkConnectString = util.getZkCluster().getAddress().toString();
String dfsUri = util.getDFSCluster().getFileSystem().getUri().toString();
sourceCluster = TestingHBaseCluster.create(TestingHBaseClusterOption.builder()
.useExternalZooKeeper(zkConnectString).useExternalDfs(dfsUri).build());
sourceCluster.start();
peerCluster = TestingHBaseCluster.create(TestingHBaseClusterOption.builder()
.useExternalZooKeeper(zkConnectString).useExternalDfs(dfsUri).build());
peerCluster.start();
assertNotEquals(sourceCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT),
peerCluster.getConf().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
assertNotEquals(sourceCluster.getConf().get(HConstants.HBASE_DIR),
peerCluster.getConf().get(HConstants.HBASE_DIR));
}

@Override
protected void stopClusters() throws Exception {
util.shutdownMiniDFSCluster();
util.shutdownMiniZKCluster();
}
}
Loading

0 comments on commit 3b9491b

Please sign in to comment.