YARN-6334. TestRMFailover#testAutomaticFailover always passes even when it should fail

(Contributed by Yufei Gu via Daniel Templeton)
This commit is contained in:
Daniel Templeton 2017-03-24 14:01:11 -07:00
parent 100b8ce05b
commit 6209e4c913
1 changed files with 21 additions and 18 deletions

View File

@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeoutException;
import javax.servlet.http.HttpServletResponse; 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;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.service.Service.STATE; import org.apache.hadoop.service.Service.STATE;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.ExitUtil; import org.apache.hadoop.util.ExitUtil;
import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.client.api.YarnClient; import org.apache.hadoop.yarn.client.api.YarnClient;
@ -59,6 +61,8 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.google.common.base.Supplier;
public class TestRMFailover extends ClientBaseWithFixes { public class TestRMFailover extends ClientBaseWithFixes {
private static final Log LOG = private static final Log LOG =
LogFactory.getLog(TestRMFailover.class.getName()); LogFactory.getLog(TestRMFailover.class.getName());
@ -159,6 +163,21 @@ public class TestRMFailover extends ClientBaseWithFixes {
verifyConnections(); verifyConnections();
} }
private void verifyRMTransitionToStandby(final 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 @Test
public void testAutomaticFailover() public void testAutomaticFailover()
throws YarnException, InterruptedException, IOException { throws YarnException, InterruptedException, IOException {
@ -182,15 +201,7 @@ public class TestRMFailover extends ClientBaseWithFixes {
ResourceManager rm = cluster.getResourceManager( ResourceManager rm = cluster.getResourceManager(
cluster.getActiveRMIndex()); cluster.getActiveRMIndex());
rm.handleTransitionToStandByInNewThread(); rm.handleTransitionToStandByInNewThread();
int maxWaitingAttempts = 2000; verifyRMTransitionToStandby(rm);
while (maxWaitingAttempts-- > 0 ) {
if (rm.getRMContext().getHAServiceState() == HAServiceState.STANDBY) {
break;
}
Thread.sleep(1);
}
Assert.assertFalse("RM didn't transition to Standby ",
maxWaitingAttempts == 0);
verifyConnections(); verifyConnections();
} }
@ -393,15 +404,7 @@ public class TestRMFailover extends ClientBaseWithFixes {
testThread.start(); testThread.start();
testThread.join(); testThread.join();
int maxWaitingAttempts = 2000; verifyRMTransitionToStandby(resourceManager);
while (maxWaitingAttempts-- > 0) {
if (resourceManager.getRMContext().getHAServiceState()
== HAServiceState.STANDBY) {
break;
}
Thread.sleep(1);
}
assertFalse("RM didn't transition to Standby ", maxWaitingAttempts < 0);
} }
/** /**