HDFS-10985. o.a.h.ha.TestZKFailoverController should not use fixed time sleep before assertions. Contributed by Mingliang Liu

This commit is contained in:
Mingliang Liu 2016-10-07 17:03:08 -07:00
parent b963818621
commit c874fa914d

View File

@ -21,6 +21,7 @@
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import com.google.common.base.Supplier;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
@ -441,12 +442,16 @@ public void testGracefulFailover() throws Exception {
cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover(); cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover();
cluster.waitForActiveLockHolder(0); 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 @Test
@ -590,14 +595,17 @@ public void testGracefulFailoverMultipleZKfcs() throws Exception {
cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover(); cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover();
cluster.waitForActiveLockHolder(0); cluster.waitForActiveLockHolder(0);
Thread.sleep(10000); // allow to quiesce GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
assertEquals(0, cluster.getService(0).fenceCount); public Boolean get() {
assertEquals(0, cluster.getService(1).fenceCount); return cluster.getService(0).fenceCount == 0 &&
assertEquals(0, cluster.getService(2).fenceCount); cluster.getService(1).fenceCount == 0 &&
assertEquals(2, cluster.getService(0).activeTransitionCount); cluster.getService(2).fenceCount == 0 &&
assertEquals(1, cluster.getService(1).activeTransitionCount); cluster.getService(0).activeTransitionCount == 2 &&
assertEquals(1, cluster.getService(2).activeTransitionCount); cluster.getService(1).activeTransitionCount == 1 &&
cluster.getService(2).activeTransitionCount == 1;
}
}, 100, 60 * 1000);
} }
private int runFC(DummyHAService target, String ... args) throws Exception { private int runFC(DummyHAService target, String ... args) throws Exception {