diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestBadReplicationPeer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestBadReplicationPeer.java new file mode 100644 index 0000000000..8173a9436f --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestBadReplicationPeer.java @@ -0,0 +1,76 @@ +package org.apache.hadoop.hbase.client.replication; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.ReplicationPeerNotFoundException; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; +import org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; + +@Category({ MediumTests.class, ClientTests.class}) +public class TestBadReplicationPeer { + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestBadReplicationPeer.class); + private static final Logger LOG = LoggerFactory.getLogger(TestBadReplicationPeer.class); + private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private static Admin hbaseAdmin; + private static Configuration conf; + + @Rule + public TestName name = new TestName(); + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); + TEST_UTIL.getConfiguration().setBoolean("replication.source.regionserver.abort", false); + + TEST_UTIL.startMiniCluster(); + conf = TEST_UTIL.getConfiguration(); + hbaseAdmin = TEST_UTIL.getAdmin(); + } + + @Test + public void testWrongReplicationEndpoint() throws IOException { + String peerId = "dummypeer_1"; + try (Connection connection = ConnectionFactory.createConnection(conf); Admin admin = connection.getAdmin()){ + ReplicationPeerConfigBuilder rpcBuilder = ReplicationPeerConfig.newBuilder(); + String quorum = TEST_UTIL.getHBaseCluster().getMaster().getZooKeeper().getQuorum(); + rpcBuilder.setClusterKey(quorum + ":/1"); + ReplicationPeerConfig rpc = rpcBuilder.build(); + admin.addReplicationPeer(peerId, rpc); + } finally { + cleanPeer(peerId); + } + } + + private static void cleanPeer(String peerId) throws IOException { + try (Connection connection = ConnectionFactory.createConnection(conf); Admin admin = connection.getAdmin()){ + try { + admin.removeReplicationPeer(peerId); + } catch (ReplicationPeerNotFoundException rpnfe) { + // Ignore + } catch (IllegalArgumentException re) { + LOG.warn("Couldn't clean up peers created in ReplicateServiceTest -- did we not create them?", re); + } + } + } +}