From commits-return-65080-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Thu Jan 11 06:51:59 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 4DA23180787 for ; Thu, 11 Jan 2018 06:51:59 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3DB0C160C4B; Thu, 11 Jan 2018 05:51:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7C212160C45 for ; Thu, 11 Jan 2018 06:51:58 +0100 (CET) Received: (qmail 29652 invoked by uid 500); 11 Jan 2018 05:51:56 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 25908 invoked by uid 99); 11 Jan 2018 05:51:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jan 2018 05:51:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 88C76F32E3; Thu, 11 Jan 2018 05:51:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhangduo@apache.org To: commits@hbase.apache.org Date: Thu, 11 Jan 2018 05:52:24 -0000 Message-Id: <3bb07c833b504c32be28b6b897c41ef5@git.apache.org> In-Reply-To: <9b6619582a44414c9528267d0d4addee@git.apache.org> References: <9b6619582a44414c9528267d0d4addee@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [34/41] hbase git commit: HBASE-19544 Add UTs for testing concurrent modifications on replication peer HBASE-19544 Add UTs for testing concurrent modifications on replication peer Signed-off-by: zhangduo Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b9c44b07 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b9c44b07 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b9c44b07 Branch: refs/heads/HBASE-19397-branch-2 Commit: b9c44b070ee4c823a12e0cb1508565e3df47bcf3 Parents: 34d04b6 Author: Guanghao Zhang Authored: Tue Jan 2 17:07:41 2018 +0800 Committer: zhangduo Committed: Thu Jan 11 13:50:16 2018 +0800 ---------------------------------------------------------------------- .../replication/TestReplicationAdmin.java | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/b9c44b07/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java index 9b71595..89cf393 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java @@ -31,6 +31,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; import java.util.regex.Pattern; import org.apache.hadoop.conf.Configuration; @@ -55,6 +56,8 @@ 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; /** * Unit testing of ReplicationAdmin @@ -62,6 +65,8 @@ import org.junit.rules.TestName; @Category({MediumTests.class, ClientTests.class}) public class TestReplicationAdmin { + private static final Logger LOG = LoggerFactory.getLogger(TestReplicationAdmin.class); + private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -111,6 +116,70 @@ public class TestReplicationAdmin { } @Test + public void testConcurrentPeerOperations() throws Exception { + int threadNum = 5; + AtomicLong successCount = new AtomicLong(0); + + // Test concurrent add peer operation + Thread[] addPeers = new Thread[threadNum]; + for (int i = 0; i < threadNum; i++) { + addPeers[i] = new Thread(() -> { + try { + hbaseAdmin.addReplicationPeer(ID_ONE, + ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE).build()); + successCount.incrementAndGet(); + } catch (Exception e) { + LOG.debug("Got exception when add replication peer", e); + } + }); + addPeers[i].start(); + } + for (Thread addPeer : addPeers) { + addPeer.join(); + } + assertEquals(1, successCount.get()); + + // Test concurrent remove peer operation + successCount.set(0); + Thread[] removePeers = new Thread[threadNum]; + for (int i = 0; i < threadNum; i++) { + removePeers[i] = new Thread(() -> { + try { + hbaseAdmin.removeReplicationPeer(ID_ONE); + successCount.incrementAndGet(); + } catch (Exception e) { + LOG.debug("Got exception when remove replication peer", e); + } + }); + removePeers[i].start(); + } + for (Thread removePeer : removePeers) { + removePeer.join(); + } + assertEquals(1, successCount.get()); + + // Test concurrent add peer operation again + successCount.set(0); + addPeers = new Thread[threadNum]; + for (int i = 0; i < threadNum; i++) { + addPeers[i] = new Thread(() -> { + try { + hbaseAdmin.addReplicationPeer(ID_ONE, + ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE).build()); + successCount.incrementAndGet(); + } catch (Exception e) { + LOG.debug("Got exception when add replication peer", e); + } + }); + addPeers[i].start(); + } + for (Thread addPeer : addPeers) { + addPeer.join(); + } + assertEquals(1, successCount.get()); + } + + @Test public void testAddInvalidPeer() { ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder(); builder.setClusterKey(KEY_ONE);