From b9319496bce4985e7a7a9743e7d6cf42fdff3dbc Mon Sep 17 00:00:00 2001 From: tedyu Date: Thu, 17 Nov 2016 07:48:52 -0800 Subject: [PATCH] HBASE-17120 TestAssignmentListener#testAssignmentListener fails (ChiaPing Tsai) --- .../hbase/master/TestAssignmentListener.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentListener.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentListener.java index 9a52c706233..f7f9abd4e5d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentListener.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentListener.java @@ -264,12 +264,19 @@ public class TestAssignmentListener { listener.reset(); List regions = admin.getTableRegions(TABLE_NAME); assertEquals(2, regions.size()); + boolean sameServer = areAllRegionsLocatedOnSameServer(TABLE_NAME); + // If the regions are located by different server, we need to move + // regions to same server before merging. So the expected modifications + // will increaes to 5. (open + close) + final int expectedModifications = sameServer ? 3 : 5; + final int expectedLoadCount = sameServer ? 1 : 2; + final int expectedCloseCount = sameServer ? 2 : 3; admin.mergeRegionsAsync(regions.get(0).getEncodedNameAsBytes(), regions.get(1).getEncodedNameAsBytes(), true); - listener.awaitModifications(3); + listener.awaitModifications(expectedModifications); assertEquals(1, admin.getTableRegions(TABLE_NAME).size()); - assertEquals(1, listener.getLoadCount()); // new merged region added - assertEquals(2, listener.getCloseCount()); // daughters removed + assertEquals(expectedLoadCount, listener.getLoadCount()); // new merged region added + assertEquals(expectedCloseCount, listener.getCloseCount()); // daughters removed // Delete the table LOG.info("Drop Table"); @@ -283,6 +290,20 @@ public class TestAssignmentListener { } } + private boolean areAllRegionsLocatedOnSameServer(TableName TABLE_NAME) { + MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster(); + int serverCount = 0; + for (JVMClusterUtil.RegionServerThread regionThread: miniCluster.getRegionServerThreads()) { + if (!regionThread.getRegionServer().getOnlineRegions(TABLE_NAME).isEmpty()) { + ++serverCount; + } + if (serverCount > 1) { + return false; + } + } + return serverCount == 1; + } + @Test public void testAddNewServerThatExistsInDraining() throws Exception { // Under certain circumstances, such as when we failover to the Backup