diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java index ebb82097aca..0bd4f3f6ef4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java @@ -92,6 +92,8 @@ public class TestRegionServerReportForDuty { master.start(); rs.start(); + waitForClusterOnline(master); + // Add a 2nd region server cluster.getConfiguration().set(HConstants.REGION_SERVER_IMPL, MyRegionServer.class.getName()); rs2 = cluster.addRegionServer(); @@ -101,7 +103,7 @@ public class TestRegionServerReportForDuty { LOG.debug("Starting 2nd region server: " + rs2.getRegionServer().getServerName()); rs2.start(); - waitForClusterOnline(master); + waitForSecondRsStarted(); // Stop the current master. master.getMaster().stop("Stopping master"); @@ -126,8 +128,7 @@ public class TestRegionServerReportForDuty { private void waitForClusterOnline(MasterThread master) throws InterruptedException { while (true) { - if (master.getMaster().isInitialized() - && ((MyRegionServer) rs2.getRegionServer()).getRpcStubCreatedFlag() == true) { + if (master.getMaster().isInitialized()) { break; } Thread.sleep(SLEEP_INTERVAL); @@ -136,6 +137,16 @@ public class TestRegionServerReportForDuty { rs.waitForServerOnline(); } + private void waitForSecondRsStarted() throws InterruptedException { + while (true) { + if (((MyRegionServer) rs2.getRegionServer()).getRpcStubCreatedFlag() == true) { + break; + } + Thread.sleep(SLEEP_INTERVAL); + LOG.debug("Waiting 2nd RS to be started ..."); + } + } + // Create a Region Server that provide a hook so that we can wait for the master switch over // before continuing reportForDuty to the mater. // The idea is that we get a RPC connection to the first active master, then we wait. @@ -170,6 +181,7 @@ public class TestRegionServerReportForDuty { try { Thread.sleep(SLEEP_INTERVAL); } catch (InterruptedException e) { + return null; } LOG.debug("Waiting for master switch over ... "); }