amahussein commented on a change in pull request #2461:
URL: https://github.com/apache/hadoop/pull/2461#discussion_r522314779
##########
File path:
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java
##########
@@ -1161,43 +1165,34 @@ protected NodeStatusUpdater
createNodeStatusUpdater(Context context,
Assert.assertTrue("last service is NOT the node status updater",
lastService instanceof NodeStatusUpdater);
- new Thread() {
- public void run() {
- try {
- nm.start();
- } catch (Throwable e) {
- TestNodeStatusUpdater.this.nmStartError = e;
- throw new YarnRuntimeException(e);
- }
+ Thread starterThread = new Thread(() -> {
+ try {
+ nm.start();
+ } catch (Throwable e) {
+ TestNodeStatusUpdater.this.nmStartError = e;
+ throw new YarnRuntimeException(e);
}
- }.start();
+ });
+ starterThread.start();
- System.out.println(" ----- thread already started.."
- + nm.getServiceState());
+ LOG.info(" ----- thread already started..{}", nm.getServiceState());
- int waitCount = 0;
- while (nm.getServiceState() == STATE.INITED && waitCount++ != 50) {
- LOG.info("Waiting for NM to start..");
- if (nmStartError != null) {
- LOG.error("Error during startup. ", nmStartError);
- Assert.fail(nmStartError.getCause().getMessage());
- }
- Thread.sleep(2000);
- }
- if (nm.getServiceState() != STATE.STARTED) {
- // NM could have failed.
- Assert.fail("NodeManager failed to start");
+ starterThread.join(100000);
+
+ if (nmStartError != null) {
+ LOG.error("Error during startup. ", nmStartError);
+ Assert.fail(nmStartError.getCause().getMessage());
}
- waitCount = 0;
- while (heartBeatID <= 3 && waitCount++ != 200) {
- Thread.sleep(1000);
+ int waitCount = 0;
+ while (nm.getServiceState() == STATE.STARTED
Review comment:
Thanks @goiri, I added the `nm.getServiceState() == STATE.STARTED`
because I found that the Unit test could keep waiting for the heartBeatID even
after the nm fails.
The loop can be replaced with `waitFor()` but the conditions has to be
rewritten in a way that may be confusing a little bit.
```java
// we should not be waiting once the service stops running
GenericTestUtils.waitFor( () -> (nm.getServiceState() != STATE.STARTED) ||
heartBeatID > 3), 50, 1000);
```
If you are fine with the above version, I can replace all the loops with
`WaitFor()`
##########
File path:
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java
##########
@@ -1529,19 +1518,27 @@ public void testApplicationKeepAlive() throws Exception
{
nm.init(conf);
nm.start();
// HB 2 -> app cancelled by RM.
- while (heartBeatID < 12) {
- Thread.sleep(1000l);
+ GenericTestUtils.waitFor(() -> nm.getServiceState() == STATE.STARTED,
+ 20, 10000);
+ int waitCount = 0;
+ while (nm.getServiceState() == STATE.STARTED && heartBeatID < 12
+ && waitCount++ < 60000000) {
+ Thread.sleep(100l);
}
+ Assert.assertTrue(heartBeatID >= 12);
MyResourceTracker3 rt =
(MyResourceTracker3) nm.getNodeStatusUpdater().getRMClient();
rt.context.getApplications().remove(rt.appId);
Assert.assertEquals(1, rt.keepAliveRequests.size());
int numKeepAliveRequests = rt.keepAliveRequests.get(rt.appId).size();
LOG.info("Number of Keep Alive Requests: [" + numKeepAliveRequests +
"]");
Assert.assertTrue(numKeepAliveRequests == 2 || numKeepAliveRequests ==
3);
- while (heartBeatID < 20) {
- Thread.sleep(1000l);
+ waitCount = 0;
+ while (nm.getServiceState() == STATE.STARTED && heartBeatID < 20
Review comment:
same as above
##########
File path:
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java
##########
@@ -1529,19 +1518,27 @@ public void testApplicationKeepAlive() throws Exception
{
nm.init(conf);
nm.start();
// HB 2 -> app cancelled by RM.
- while (heartBeatID < 12) {
- Thread.sleep(1000l);
+ GenericTestUtils.waitFor(() -> nm.getServiceState() == STATE.STARTED,
+ 20, 10000);
+ int waitCount = 0;
+ while (nm.getServiceState() == STATE.STARTED && heartBeatID < 12
Review comment:
Same as above
##########
File path:
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java
##########
@@ -1712,27 +1704,14 @@ protected ContainerManagerImpl
createContainerManager(Context context,
YarnConfiguration conf = createNMConfig();
nm.init(conf);
nm.start();
-
- System.out.println(" ----- thread already started.."
- + nm.getServiceState());
+ GenericTestUtils.waitFor(() -> nm.getServiceState() == STATE.STARTED,
+ 20, 20000);
int waitCount = 0;
- while (nm.getServiceState() == STATE.INITED && waitCount++ != 20) {
- LOG.info("Waiting for NM to start..");
- if (nmStartError != null) {
- LOG.error("Error during startup. ", nmStartError);
- Assert.fail(nmStartError.getCause().getMessage());
- }
- Thread.sleep(1000);
- }
- if (nm.getServiceState() != STATE.STARTED) {
- // NM could have failed.
- Assert.fail("NodeManager failed to start");
- }
- waitCount = 0;
- while (heartBeatID <= 3 && waitCount++ != 20) {
- Thread.sleep(500);
+ while (nm.getServiceState() == STATE.STARTED
Review comment:
same as above
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]