YARN-5005. TestRMWebServices#testDumpingSchedulerLogs fails randomly. Contributed by Bibin A Chundatt.

This commit is contained in:
Rohith Sharma K S 2016-05-27 10:44:35 +05:30
parent 8c84a2a93c
commit 0a544f8a3e
2 changed files with 23 additions and 3 deletions

View File

@ -26,6 +26,8 @@ import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.log4j.*;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.util.*;
@ -41,7 +43,7 @@ public class AdHocLogDumper {
private Map<String, Priority> appenderLevels;
private Level currentLogLevel;
public static final String AD_HOC_DUMPER_APPENDER = "ad-hoc-dumper-appender";
private static boolean logFlag = false;
private static volatile boolean logFlag = false;
private static final Object lock = new Object();
public AdHocLogDumper(String name, String targetFilename) {
@ -107,6 +109,11 @@ public class AdHocLogDumper {
}
}
@VisibleForTesting
public static boolean getState() {
return logFlag;
}
class RestoreLogLevel extends TimerTask {
@Override
public void run() {

View File

@ -41,7 +41,9 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.TwoDArrayWritable;
import org.apache.hadoop.service.Service.STATE;
import org.apache.hadoop.test.GenericTestUtils.SleepAnswer;
import org.apache.hadoop.util.VersionInfo;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
@ -62,6 +64,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedule
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo;
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
import org.apache.hadoop.yarn.util.AdHocLogDumper;
import org.apache.hadoop.yarn.util.YarnVersionInfo;
import org.apache.hadoop.yarn.webapp.ForbiddenException;
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
@ -671,7 +674,7 @@ public class TestRMWebServices extends JerseyTestBase {
// nothing should happen
webSvc.dumpSchedulerLogs("1", mockHsr);
Thread.sleep(1000);
waitforLogDump(50);
checkSchedulerLogFileAndCleanup();
conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
@ -709,7 +712,7 @@ public class TestRMWebServices extends JerseyTestBase {
}
});
webSvc.dumpSchedulerLogs("1", mockHsr);
Thread.sleep(1000);
waitforLogDump(50);
checkSchedulerLogFileAndCleanup();
}
@ -727,4 +730,14 @@ public class TestRMWebServices extends JerseyTestBase {
assertTrue("scheduler log file doesn't exist", logFile.exists());
FileUtils.deleteQuietly(logFile);
}
private void waitforLogDump(int tickcount) throws InterruptedException {
while (tickcount > 0) {
Thread.sleep(100);
if (!AdHocLogDumper.getState()) {
return;
}
tickcount--;
}
}
}