HBASE-19865 Add UT for sync replication peer in DA state
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3f08903e Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3f08903e Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3f08903e Branch: refs/heads/HBASE-19064 Commit: 3f08903e8bf3019aa7344e949ae4984cfc049c6d Parents: d6fdd7e Author: zhangduo <zhang...@apache.org> Authored: Tue May 8 20:33:22 2018 +0800 Committer: zhangduo <zhang...@apache.org> Committed: Wed May 9 17:38:23 2018 +0800 ---------------------------------------------------------------------- .../hbase/replication/TestReplicationBase.java | 28 +++++++++++--- ...estReplicationChangingPeerRegionservers.java | 20 ++++++---- .../TestReplicationSmallTestsSync.java | 40 ++++++++++++++++++++ 3 files changed, 76 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/3f08903e/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java index b2c5aef..4a4b358 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java @@ -1,5 +1,4 @@ -/* - * +/** * 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 @@ -28,6 +27,8 @@ import java.util.List; import java.util.NavigableMap; import java.util.TreeMap; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -58,6 +59,9 @@ import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; +import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; + /** * This class is only a base for other integration-level replication tests. * Do not add tests here. @@ -99,6 +103,10 @@ public class TestReplicationBase { return false; } + protected boolean isSyncPeer() { + return false; + } + protected final void cleanUp() throws IOException, InterruptedException { // Starting and stopping replication can make us miss new logs, // rolling like this makes sure the most recent one gets added to the queue @@ -245,9 +253,19 @@ public class TestReplicationBase { @Before public void setUpBase() throws IOException { if (!peerExist(PEER_ID2)) { - ReplicationPeerConfig rpc = ReplicationPeerConfig.newBuilder() - .setClusterKey(utility2.getClusterKey()).setSerial(isSerialPeer()).build(); - hbaseAdmin.addReplicationPeer(PEER_ID2, rpc); + ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder() + .setClusterKey(utility2.getClusterKey()).setSerial(isSerialPeer()); + if (isSyncPeer()) { + FileSystem fs2 = utility2.getTestFileSystem(); + // The remote wal dir is not important as we do not use it in DA state, here we only need to + // confirm that a sync peer in DA state can still replicate data to remote cluster + // asynchronously. + builder.setReplicateAllUserTables(false) + .setTableCFsMap(ImmutableMap.of(tableName, ImmutableList.of())) + .setRemoteWALDir(new Path("/RemoteWAL") + .makeQualified(fs2.getUri(), fs2.getWorkingDirectory()).toUri().toString()); + } + hbaseAdmin.addReplicationPeer(PEER_ID2, builder.build()); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/3f08903e/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationChangingPeerRegionservers.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationChangingPeerRegionservers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationChangingPeerRegionservers.java index b94b443..5c96742 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationChangingPeerRegionservers.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationChangingPeerRegionservers.java @@ -62,22 +62,28 @@ public class TestReplicationChangingPeerRegionservers extends TestReplicationBas private static final Logger LOG = LoggerFactory.getLogger(TestReplicationChangingPeerRegionservers.class); - @Parameter + @Parameter(0) public boolean serialPeer; + @Parameter(1) + public boolean syncPeer; + @Override protected boolean isSerialPeer() { return serialPeer; } - @Parameters(name = "{index}: serialPeer={0}") - public static List<Boolean> parameters() { - return ImmutableList.of(true, false); + @Override + protected boolean isSyncPeer() { + return syncPeer; + } + + @Parameters(name = "{index}: serialPeer={0}, syncPeer={1}") + public static List<Object[]> parameters() { + return ImmutableList.of(new Object[] { false, false }, new Object[] { false, true }, + new Object[] { true, false }, new Object[] { true, true }); } - /** - * @throws java.lang.Exception - */ @Before public void setUp() throws Exception { // Starting and stopping replication can make us miss new logs, http://git-wip-us.apache.org/repos/asf/hbase/blob/3f08903e/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTestsSync.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTestsSync.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTestsSync.java new file mode 100644 index 0000000..9ca0044 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSmallTestsSync.java @@ -0,0 +1,40 @@ +/** + * 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.replication; + +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.ReplicationTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +@Category({ ReplicationTests.class, LargeTests.class }) +public class TestReplicationSmallTestsSync extends TestReplicationSmallTests { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestReplicationSmallTestsSync.class); + + @Override + protected boolean isSyncPeer() { + return true; + } +}