diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java index 612b7efda32..7855fc40370 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master.balancer; import static org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper.FAVORED_NODES_NUM; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.List; import java.util.Set; @@ -34,11 +35,13 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.favored.FavoredNodesManager; +import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.junit.After; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.slf4j.Logger; @@ -66,7 +69,6 @@ public class TestFavoredNodeTableImport { @After public void stopCluster() throws Exception { - UTIL.cleanupTestDir(); UTIL.shutdownMiniCluster(); } @@ -88,6 +90,7 @@ public class TestFavoredNodeTableImport { desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, Bytes.toBytes("a"), Bytes.toBytes("z"), REGION_NUM); UTIL.waitTableAvailable(desc.getTableName()); + admin.balancerSwitch(true, true); LOG.info("Shutting down cluster"); UTIL.shutdownMiniHBaseCluster(); @@ -97,18 +100,26 @@ public class TestFavoredNodeTableImport { UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, FavoredStochasticBalancer.class.getName()); UTIL.restartHBaseCluster(SLAVES); - while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { + HMaster master = UTIL.getMiniHBaseCluster().getMaster(); + while (!master.isInitialized()) { Threads.sleep(1); } - admin = UTIL.getAdmin(); - UTIL.waitTableAvailable(desc.getTableName()); + UTIL.waitUntilNoRegionsInTransition(10000); + assertTrue(master.isBalancerOn()); - FavoredNodesManager fnm = UTIL.getHBaseCluster().getMaster().getFavoredNodesManager(); + FavoredNodesManager fnm = master.getFavoredNodesManager(); + assertNotNull(fnm); + admin = UTIL.getAdmin(); List regionsOfTable = admin.getRegions(TableName.valueOf(tableName)); for (RegionInfo rInfo : regionsOfTable) { - Set favNodes = Sets.newHashSet(fnm.getFavoredNodes(rInfo)); + assertNotNull(rInfo); + assertNotNull(fnm); + List fns = fnm.getFavoredNodes(rInfo); + LOG.info("FNS {} {}", rInfo, fns); + assertNotNull(rInfo.toString(), fns); + Set favNodes = Sets.newHashSet(fns); assertNotNull(favNodes); assertEquals("Required no of favored nodes not found.", FAVORED_NODES_NUM, favNodes.size()); for (ServerName fn : favNodes) {