From d3621d24ded796dc0f50ca4cccfec400837a9e51 Mon Sep 17 00:00:00 2001 From: stack Date: Mon, 16 Feb 2015 21:00:00 -0800 Subject: [PATCH] HBASE-13041 TestEnableTableHandler should not call AssignmentManager#assign concurrently with master (Andrey Stepachev) --- .../handler/TestEnableTableHandler.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java index d3d62394485..6a60fc0fd86 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java @@ -18,8 +18,13 @@ */ package org.apache.hadoop.hbase.master.handler; +import java.util.ArrayList; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.HConstants; @@ -81,7 +86,6 @@ public class TestEnableTableHandler { admin.enableTable(tableName); TEST_UTIL.waitTableEnabled(tableName); - // disable once more admin.disableTable(tableName); @@ -91,21 +95,36 @@ public class TestEnableTableHandler { rs.getRegionServer().stop("stop"); cluster.waitForRegionServerToStop(rs.getRegionServer().getServerName(), 10000); - EnableTableHandler handler = - new EnableTableHandler(m, tableName, m.getAssignmentManager(), m.getTableLockManager(), - true); - handler.prepare(); - handler.process(); + LOG.debug("Now enabling table " + tableName); + admin.enableTable(tableName); assertTrue(admin.isTableEnabled(tableName)); JVMClusterUtil.RegionServerThread rs2 = cluster.startRegionServer(); - m.getAssignmentManager().assign(admin.getTableRegions(tableName)); + cluster.waitForRegionServerToStart(rs2.getRegionServer().getServerName().getHostname(), + rs2.getRegionServer().getServerName().getPort(), 60000); + + List regions = TEST_UTIL.getHBaseAdmin().getTableRegions(tableName); + assertEquals(1, regions.size()); + for (HRegionInfo region : regions) { + TEST_UTIL.getHBaseAdmin().assign(region.getEncodedNameAsBytes()); + } + LOG.debug("Waiting for table assigned " + tableName); TEST_UTIL.waitUntilAllRegionsAssigned(tableName); List onlineRegions = admin.getOnlineRegions( rs2.getRegionServer().getServerName()); - assertEquals(1, onlineRegions.size()); - assertEquals(tableName, onlineRegions.get(0).getTable()); + ArrayList tableRegions = filterTableRegions(tableName, onlineRegions); + assertEquals(1, tableRegions.size()); + } + + private ArrayList filterTableRegions(final TableName tableName, + List onlineRegions) { + return Lists.newArrayList(Iterables.filter(onlineRegions, new Predicate() { + @Override + public boolean apply(HRegionInfo input) { + return input.getTable().equals(tableName); + } + })); } /**