HBASE-19865 Add UT for sync replication peer in DA state

This commit is contained in:
zhangduo 2018-05-08 20:33:22 +08:00
parent ae6c90b4ec
commit 8a264dfc00
3 changed files with 76 additions and 12 deletions

View File

@ -1,5 +1,4 @@
/* /**
*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -28,6 +27,8 @@ import java.util.List;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.hadoop.conf.Configuration; 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.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
@ -58,6 +59,9 @@ import org.junit.BeforeClass;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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. * This class is only a base for other integration-level replication tests.
* Do not add tests here. * Do not add tests here.
@ -99,6 +103,10 @@ public class TestReplicationBase {
return false; return false;
} }
protected boolean isSyncPeer() {
return false;
}
protected final void cleanUp() throws IOException, InterruptedException { protected final void cleanUp() throws IOException, InterruptedException {
// Starting and stopping replication can make us miss new logs, // Starting and stopping replication can make us miss new logs,
// rolling like this makes sure the most recent one gets added to the queue // rolling like this makes sure the most recent one gets added to the queue
@ -245,9 +253,19 @@ public class TestReplicationBase {
@Before @Before
public void setUpBase() throws Exception { public void setUpBase() throws Exception {
if (!peerExist(PEER_ID2)) { if (!peerExist(PEER_ID2)) {
ReplicationPeerConfig rpc = ReplicationPeerConfig.newBuilder() ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder()
.setClusterKey(utility2.getClusterKey()).setSerial(isSerialPeer()).build(); .setClusterKey(utility2.getClusterKey()).setSerial(isSerialPeer());
hbaseAdmin.addReplicationPeer(PEER_ID2, rpc); 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());
} }
} }

View File

@ -62,22 +62,28 @@ public class TestReplicationChangingPeerRegionservers extends TestReplicationBas
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(TestReplicationChangingPeerRegionservers.class); LoggerFactory.getLogger(TestReplicationChangingPeerRegionservers.class);
@Parameter @Parameter(0)
public boolean serialPeer; public boolean serialPeer;
@Parameter(1)
public boolean syncPeer;
@Override @Override
protected boolean isSerialPeer() { protected boolean isSerialPeer() {
return serialPeer; return serialPeer;
} }
@Parameters(name = "{index}: serialPeer={0}") @Override
public static List<Boolean> parameters() { protected boolean isSyncPeer() {
return ImmutableList.of(true, false); 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 @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Starting and stopping replication can make us miss new logs, // Starting and stopping replication can make us miss new logs,

View File

@ -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;
}
}