YARN-5903. Fix race condition in TestResourceManagerAdministrationProtocolPBClientImpl beforeclass setup method (Haibo Chen via Varun Saxena)
This commit is contained in:
parent
56a13a6a59
commit
38e66d4d64
|
@ -19,11 +19,15 @@ package org.apache.hadoop.yarn.client;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.service.Service;
|
||||
import org.apache.hadoop.service.Service.STATE;
|
||||
import org.apache.hadoop.service.ServiceStateChangeListener;
|
||||
import org.apache.hadoop.yarn.api.records.DecommissionType;
|
||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||
import org.apache.hadoop.yarn.factories.RecordFactory;
|
||||
|
@ -46,6 +50,7 @@ import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceReque
|
|||
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceResponse;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -77,22 +82,30 @@ public class TestResourceManagerAdministrationProtocolPBClientImpl {
|
|||
protected void doSecureLogin() throws IOException {
|
||||
}
|
||||
};
|
||||
|
||||
// a reliable way to wait for resource manager to fully start
|
||||
final CountDownLatch rmStartedSignal = new CountDownLatch(1);
|
||||
ServiceStateChangeListener rmStateChangeListener =
|
||||
new ServiceStateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(Service service) {
|
||||
if (service.getServiceState() == STATE.STARTED) {
|
||||
rmStartedSignal.countDown();
|
||||
}
|
||||
}
|
||||
};
|
||||
resourceManager.registerServiceListener(rmStateChangeListener);
|
||||
|
||||
resourceManager.init(configuration);
|
||||
new Thread() {
|
||||
public void run() {
|
||||
resourceManager.start();
|
||||
}
|
||||
}.start();
|
||||
int waitCount = 0;
|
||||
while (resourceManager.getServiceState() == STATE.INITED
|
||||
&& waitCount++ < 10) {
|
||||
LOG.info("Waiting for RM to start...");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
if (resourceManager.getServiceState() != STATE.STARTED) {
|
||||
throw new IOException("ResourceManager failed to start. Final state is "
|
||||
+ resourceManager.getServiceState());
|
||||
}
|
||||
|
||||
boolean rmStarted = rmStartedSignal.await(60000L, TimeUnit.MILLISECONDS);
|
||||
Assert.assertTrue("ResourceManager failed to start up.", rmStarted);
|
||||
|
||||
LOG.info("ResourceManager RMAdmin address: "
|
||||
+ configuration.get(YarnConfiguration.RM_ADMIN_ADDRESS));
|
||||
|
||||
|
|
Loading…
Reference in New Issue