YARN-6334. TestRMFailover#testAutomaticFailover always passes even when it 
should fail
(Contributed by Yufei Gu via Daniel Templeton)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/33815af4
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/33815af4
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/33815af4

Branch: refs/heads/HDFS-10467
Commit: 33815af4242ac8c6b119128730e63f13164fd763
Parents: d49d186
Author: Daniel Templeton <templ...@apache.org>
Authored: Fri Mar 24 11:42:54 2017 -0700
Committer: Daniel Templeton <templ...@apache.org>
Committed: Fri Mar 24 11:42:54 2017 -0700

----------------------------------------------------------------------
 .../hadoop/yarn/client/TestRMFailover.java      | 39 +++++++++++---------
 1 file changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/33815af4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
index 4bf6a78..d568d6a 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.concurrent.TimeoutException;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -40,6 +41,7 @@ import org.apache.hadoop.ha.ClientBaseWithFixes;
 import org.apache.hadoop.ha.HAServiceProtocol;
 import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
 import org.apache.hadoop.service.Service.STATE;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.ExitUtil;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.client.api.YarnClient;
@@ -59,6 +61,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.base.Supplier;
+
 public class TestRMFailover extends ClientBaseWithFixes {
   private static final Log LOG =
       LogFactory.getLog(TestRMFailover.class.getName());
@@ -159,6 +163,21 @@ public class TestRMFailover extends ClientBaseWithFixes {
     verifyConnections();
   }
 
+  private void verifyRMTransitionToStandby(ResourceManager rm)
+      throws InterruptedException {
+    try {
+      GenericTestUtils.waitFor(new Supplier<Boolean>() {
+        @Override
+        public Boolean get() {
+          return rm.getRMContext().getHAServiceState() ==
+              HAServiceState.STANDBY;
+        }
+      }, 100, 20000);
+    } catch (TimeoutException e) {
+      fail("RM didn't transition to Standby.");
+    }
+  }
+
   @Test
   public void testAutomaticFailover()
       throws YarnException, InterruptedException, IOException {
@@ -182,15 +201,7 @@ public class TestRMFailover extends ClientBaseWithFixes {
     ResourceManager rm = cluster.getResourceManager(
         cluster.getActiveRMIndex());
     rm.handleTransitionToStandByInNewThread();
-    int maxWaitingAttempts = 2000;
-    while (maxWaitingAttempts-- > 0 ) {
-      if (rm.getRMContext().getHAServiceState() == HAServiceState.STANDBY) {
-        break;
-      }
-      Thread.sleep(1);
-    }
-    Assert.assertFalse("RM didn't transition to Standby ",
-        maxWaitingAttempts == 0);
+    verifyRMTransitionToStandby(rm);
     verifyConnections();
   }
 
@@ -393,15 +404,7 @@ public class TestRMFailover extends ClientBaseWithFixes {
     testThread.start();
     testThread.join();
 
-    int maxWaitingAttempts = 2000;
-    while (maxWaitingAttempts-- > 0) {
-      if (resourceManager.getRMContext().getHAServiceState()
-          == HAServiceState.STANDBY) {
-        break;
-      }
-      Thread.sleep(1);
-    }
-    assertFalse("RM didn't transition to Standby ", maxWaitingAttempts < 0);
+    verifyRMTransitionToStandby(resourceManager);
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to