HDFS-10985. o.a.h.ha.TestZKFailoverController should not use fixed time sleep before assertions. Contributed by Mingliang Liu
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c874fa91 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c874fa91 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c874fa91 Branch: refs/heads/HDFS-7240 Commit: c874fa914dfbf07d1731f5e87398607366675879 Parents: b963818 Author: Mingliang Liu <lium...@apache.org> Authored: Fri Oct 7 17:03:08 2016 -0700 Committer: Mingliang Liu <lium...@apache.org> Committed: Mon Oct 10 13:33:07 2016 -0700 ---------------------------------------------------------------------- .../hadoop/ha/TestZKFailoverController.java | 34 ++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/c874fa91/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java index 164167c..846c8ae 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.security.NoSuchAlgorithmException; +import com.google.common.base.Supplier; import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; @@ -441,12 +442,16 @@ public class TestZKFailoverController extends ClientBaseWithFixes { cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover(); cluster.waitForActiveLockHolder(0); - Thread.sleep(10000); // allow to quiesce + GenericTestUtils.waitFor(new Supplier<Boolean>() { + @Override + public Boolean get() { + return cluster.getService(0).fenceCount == 0 && + cluster.getService(1).fenceCount == 0 && + cluster.getService(0).activeTransitionCount == 2 && + cluster.getService(1).activeTransitionCount == 1; + } + }, 100, 60 * 1000); - assertEquals(0, cluster.getService(0).fenceCount); - assertEquals(0, cluster.getService(1).fenceCount); - assertEquals(2, cluster.getService(0).activeTransitionCount); - assertEquals(1, cluster.getService(1).activeTransitionCount); } @Test @@ -590,14 +595,17 @@ public class TestZKFailoverController extends ClientBaseWithFixes { cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover(); cluster.waitForActiveLockHolder(0); - Thread.sleep(10000); // allow to quiesce - - assertEquals(0, cluster.getService(0).fenceCount); - assertEquals(0, cluster.getService(1).fenceCount); - assertEquals(0, cluster.getService(2).fenceCount); - assertEquals(2, cluster.getService(0).activeTransitionCount); - assertEquals(1, cluster.getService(1).activeTransitionCount); - assertEquals(1, cluster.getService(2).activeTransitionCount); + GenericTestUtils.waitFor(new Supplier<Boolean>() { + @Override + public Boolean get() { + return cluster.getService(0).fenceCount == 0 && + cluster.getService(1).fenceCount == 0 && + cluster.getService(2).fenceCount == 0 && + cluster.getService(0).activeTransitionCount == 2 && + cluster.getService(1).activeTransitionCount == 1 && + cluster.getService(2).activeTransitionCount == 1; + } + }, 100, 60 * 1000); } private int runFC(DummyHAService target, String ... args) throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org