Skip to content

Commit

Permalink
YARN-5005. TestRMWebServices#testDumpingSchedulerLogs fails randomly.…
Browse files Browse the repository at this point in the history
… Contributed by Bibin A Chundatt.
  • Loading branch information
rohithsharmaks committed May 27, 2016
1 parent 8c84a2a commit 0a544f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
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.*;
Expand All @@ -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) {
Expand Down Expand Up @@ -107,6 +109,11 @@ public void dumpLogs(String level, int timePeriod)
}
}

@VisibleForTesting
public static boolean getState() {
return logFlag;
}

class RestoreLogLevel extends TimerTask {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@

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;
Expand All @@ -62,6 +64,7 @@
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;
Expand Down Expand Up @@ -671,7 +674,7 @@ public void testDumpingSchedulerLogs() throws Exception {

// nothing should happen
webSvc.dumpSchedulerLogs("1", mockHsr);
Thread.sleep(1000);
waitforLogDump(50);
checkSchedulerLogFileAndCleanup();

conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
Expand Down Expand Up @@ -709,7 +712,7 @@ public String getName() {
}
});
webSvc.dumpSchedulerLogs("1", mockHsr);
Thread.sleep(1000);
waitforLogDump(50);
checkSchedulerLogFileAndCleanup();
}

Expand All @@ -727,4 +730,14 @@ private void checkSchedulerLogFileAndCleanup() {
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--;
}
}
}

0 comments on commit 0a544f8

Please sign in to comment.