Skip to content

Commit

Permalink
set timeout to all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Mar 16, 2016
1 parent 558ee42 commit c5dde75
Showing 1 changed file with 31 additions and 40 deletions.
Expand Up @@ -84,7 +84,6 @@ static public void classSetup() {
FileTestUtil.makeTestOutputDir();
}


void configure(File file) throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(loggerContext);
Expand All @@ -102,7 +101,7 @@ void gConfigure(File file) throws JoranException {
gc.run(file);
}

@Test
@Test(timeout = 4000L)
public void checkBasicLifecyle() throws JoranException, IOException, InterruptedException {
File file = new File(SCAN1_FILE_AS_STR);
configure(file);
Expand All @@ -112,7 +111,7 @@ public void checkBasicLifecyle() throws JoranException, IOException, Interrupted
checkThatTaskCanBeStopped();
}

@Test
@Test(timeout = 4000L)
public void checkBasicLifecyleWithGaffer() throws JoranException, IOException, InterruptedException {
File file = new File(G_SCAN1_FILE_AS_STR);
gConfigure(file);
Expand All @@ -129,10 +128,7 @@ private void checkThatTaskCanBeStopped() {
}

private void checkThatTaskHasRan() throws InterruptedException {
ReconfigureOnChangeTask roct = waitForReconfigureOnChangeTaskToRun();
CountDownLatch latch = new CountDownLatch(1);
roct.addListener(new RunMethodInvokedListener(latch));
latch.await();
waitForReconfigureOnChangeTaskToRun();
}

List<File> getConfigurationWatchList(LoggerContext context) {
Expand All @@ -145,7 +141,6 @@ public void scanWithFileInclusion() throws JoranException, IOException, Interrup
File topLevelFile = new File(INCLUSION_SCAN_TOPLEVEL0_AS_STR);
File innerFile = new File(INCLUSION_SCAN_INNER0_AS_STR);
configure(topLevelFile);
waitForReconfigureOnChangeTaskToRun();
List<File> fileList = getConfigurationWatchList(loggerContext);
assertThatListContainsFile(fileList, topLevelFile);
assertThatListContainsFile(fileList, innerFile);
Expand All @@ -164,14 +159,14 @@ public void scanWithResourceInclusion() throws JoranException, IOException, Inte
}

// See also http://jira.qos.ch/browse/LOGBACK-338
@Test
@Test(timeout = 4000L)
public void reconfigurationIsNotPossibleInTheAbsenceOfATopFile() throws IOException, JoranException, InterruptedException {
String configurationStr = "<configuration scan=\"true\" scanPeriod=\"50 millisecond\"><include resource=\"asResource/inner1.xml\"/></configuration>";
configure(new ByteArrayInputStream(configurationStr.getBytes("UTF-8")));

ConfigurationWatchList configurationWatchList = ConfigurationWatchListUtil.getConfigurationWatchList(loggerContext);
assertNull(configurationWatchList);
//assertNull(configurationWatchList.getMainURL());
// assertNull(configurationWatchList.getMainURL());

statusChecker.containsMatch(Status.WARN, "Due to missing top level");
StatusPrinter.print(loggerContext);
Expand All @@ -190,12 +185,12 @@ public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranExcepti
writeToFile(topLevelFile, "<configuration scan=\"true\" scanPeriod=\"5 millisecond\">\n" + " <root></configuration>");
ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask();
changeDetectedLatch.await();

statusChecker.assertContainsMatch(Status.WARN, FALLING_BACK_TO_SAFE_CONFIGURATION);
statusChecker.assertContainsMatch(Status.INFO, RE_REGISTERING_PREVIOUS_SAFE_CONFIGURATION);

loggerContext.getStatusManager().clear();

CountDownLatch secondDoneLatch = waitForTaskAndAttachReconfigDoneListener(oldRoct);
writeToFile(topLevelFile, "<configuration scan=\"true\" scanPeriod=\"5 millisecond\"><root level=\"ERROR\"/></configuration> ");
secondDoneLatch.await();
Expand All @@ -215,17 +210,17 @@ public void fallbackToSafeWithIncludedFile_FollowedByRecovery() throws IOExcepti
File innerFile = new File(innerFileAsStr);
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
configure(topLevelFile);

CountDownLatch doneLatch = waitForTaskAndAttachReconfigDoneListener(null);
writeToFile(innerFile, "<included>\n<root>\n</included>");
ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask();
doneLatch.await();

statusChecker.assertContainsMatch(Status.WARN, FALLING_BACK_TO_SAFE_CONFIGURATION);
statusChecker.assertContainsMatch(Status.INFO, RE_REGISTERING_PREVIOUS_SAFE_CONFIGURATION);

loggerContext.getStatusManager().clear();

CountDownLatch secondDoneLatch = waitForTaskAndAttachReconfigDoneListener(oldRoct);
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
secondDoneLatch.await();
Expand All @@ -234,14 +229,13 @@ public void fallbackToSafeWithIncludedFile_FollowedByRecovery() throws IOExcepti
statusChecker.containsMatch(DETECTED_CHANGE_IN_CONFIGURATION_FILES);
}


private ReconfigureOnChangeTask getRegisteredReconfigureTask() {
return (ReconfigureOnChangeTask) loggerContext.getObject(RECONFIGURE_ON_CHANGE_TASK);
}

class RunMethodInvokedListener extends ReconfigureOnChangeTaskListener {
CountDownLatch countDownLatch;

RunMethodInvokedListener(CountDownLatch countDownLatch) {
this.countDownLatch = countDownLatch;
}
Expand All @@ -254,7 +248,7 @@ public void enteredRunMethod() {

class ChangeDetectedListener extends ReconfigureOnChangeTaskListener {
CountDownLatch countDownLatch;

ChangeDetectedListener(CountDownLatch countDownLatch) {
this.countDownLatch = countDownLatch;
}
Expand All @@ -264,10 +258,10 @@ public void changeDetected() {
countDownLatch.countDown();
}
};

class ReconfigurationDoneListener extends ReconfigureOnChangeTaskListener {
CountDownLatch countDownLatch;

ReconfigurationDoneListener(CountDownLatch countDownLatch) {
this.countDownLatch = countDownLatch;
}
Expand All @@ -277,16 +271,14 @@ public void doneReconfiguring() {
countDownLatch.countDown();
}
};




private ReconfigureOnChangeTask waitForReconfigureOnChangeTaskToRun() throws InterruptedException {
ReconfigureOnChangeTask roct = null;
while(roct == null) {
while (roct == null) {
roct = getRegisteredReconfigureTask();
Thread.yield();
}

CountDownLatch countDownLatch = new CountDownLatch(1);
roct.addListener(new RunMethodInvokedListener(countDownLatch));
countDownLatch.await();
Expand All @@ -295,17 +287,17 @@ private ReconfigureOnChangeTask waitForReconfigureOnChangeTaskToRun() throws Int

private CountDownLatch waitForTaskAndAttachReconfigDoneListener(ReconfigureOnChangeTask oldTask) throws InterruptedException {
ReconfigureOnChangeTask roct = oldTask;
while(roct == oldTask) {
while (roct == oldTask) {
roct = getRegisteredReconfigureTask();
Thread.yield();
}

CountDownLatch countDownLatch = new CountDownLatch(1);
roct.addListener(new ReconfigurationDoneListener(countDownLatch));
System.out.println("added ReconfigurationDoneListener");
return countDownLatch;
}

private RunnableWithCounterAndDone[] buildRunnableArray(File configFile, UpdateType updateType) {
RunnableWithCounterAndDone[] rArray = new RunnableWithCounterAndDone[THREAD_COUNT];
rArray[0] = new Updater(configFile, updateType);
Expand All @@ -322,9 +314,9 @@ public void scan_LOGBACK_474() throws JoranException, IOException, InterruptedEx
File file = new File(SCAN_LOGBACK_474_FILE_AS_STR);
// StatusListenerConfigHelper.addOnConsoleListenerInstance(loggerContext, new OnConsoleStatusListener());
configure(file);
//ReconfigureOnChangeTask roct = waitForReconfigureOnChangeTaskToRun();

// ReconfigureOnChangeTask roct = waitForReconfigureOnChangeTaskToRun();

int expectedResets = 2;
Harness harness = new Harness(expectedResets);

Expand All @@ -347,14 +339,13 @@ private void checkResetCount(int expected) {

int effectiveResets = checker.matchCount(CoreConstants.RESET_MSG_PREFIX);
assertEquals(expected, effectiveResets);



// String failMsg = "effective=" + effectiveResets + ", expected=" + expected;
//
//
// there might be more effective resets than the expected amount
// since the harness may be sleeping while a reset occurs
//assertTrue(failMsg, expected <= effectiveResets && (expected + 2) >= effectiveResets);
// assertTrue(failMsg, expected <= effectiveResets && (expected + 2) >= effectiveResets);

}

void addInfo(String msg, Object o) {
Expand Down Expand Up @@ -384,7 +375,7 @@ public void waitUntilEndCondition() throws InterruptedException {
int changeCount = 0;
ReconfigureOnChangeTask lastRoct = null;
CountDownLatch countDownLatch = null;

while (changeCount < changeCountLimit) {
ReconfigureOnChangeTask roct = (ReconfigureOnChangeTask) loggerContext.getObject(RECONFIGURE_ON_CHANGE_TASK);
if (lastRoct != roct && roct != null) {
Expand Down Expand Up @@ -413,7 +404,7 @@ class Updater extends RunnableWithCounterAndDone {
// final static int DEFAULT_SLEEP_BETWEEN_UPDATES = 60;

int sleepBetweenUpdates = 100;

Updater(File configFile, UpdateType updateType) {
this.configFile = configFile;
this.updateType = updateType;
Expand Down

0 comments on commit c5dde75

Please sign in to comment.