Skip to content

Commit

Permalink
minor refactoring in /ReconfigureOnChangeTaskTest
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Aug 9, 2022
1 parent 51436f5 commit a7eb9bc
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -99,6 +101,11 @@ void configure(InputStream is) throws JoranException {
jc.doConfigure(is);
}


@Before
public void before() {
System.out.println(this.getClass().getName()+"#before");
}
// void gConfigure(File file) throws JoranException {
// GafferConfigurator gc = new GafferConfigurator(loggerContext);
// gc.run(file);
Expand Down Expand Up @@ -179,7 +186,7 @@ public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranExcepti
"<configuration scan=\"true\" scanPeriod=\"5 millisecond\"><root level=\"ERROR\"/></configuration> ");
configure(topLevelFile);
StatusPrinter.print(loggerContext);
CountDownLatch changeDetectedLatch = waitForReconfigurationToBeDone(null);
CountDownLatch changeDetectedLatch = registerNewReconfigurationDoneListener_WithNewROCT(null);
ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask();

addInfo("registered ReconfigureOnChangeTask ", oldRoct);
Expand All @@ -199,7 +206,7 @@ public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranExcepti
loggerContext.getStatusManager().clear();

addInfo("after loggerContext.getStatusManager().clear() oldRoct="+ oldRoct, this);
CountDownLatch secondDoneLatch = waitForReconfigurationToBeDone(oldRoct);
CountDownLatch secondDoneLatch = registerNewReconfigurationDoneListener_WithNewROCT(oldRoct);
writeToFile(topLevelFile,
"<configuration scan=\"true\" scanPeriod=\"5 millisecond\"><root level=\"ERROR\"/></configuration> ");

Expand All @@ -213,7 +220,7 @@ public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranExcepti
}
}

@Test(timeout = 4000L)
@Test(timeout = 3000L)
public void fallbackToSafeWithIncludedFile_FollowedByRecovery()
throws IOException, JoranException, InterruptedException, ExecutionException {
String topLevelFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "reconfigureOnChangeConfig_top-" + diff
Expand All @@ -229,20 +236,20 @@ public void fallbackToSafeWithIncludedFile_FollowedByRecovery()
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
configure(topLevelFile);

CountDownLatch doneLatch = waitForReconfigurationToBeDone(null);
CountDownLatch doneLatch = registerNewReconfigurationDoneListener_WithNewROCT(null);
ReconfigureOnChangeTask oldRoct = getRegisteredReconfigureTask();
assertNotNull(oldRoct);

writeToFile(innerFile, "<included>\n<root>\n</included>");
doneLatch.await();
doneLatch.await(2000, TimeUnit.MILLISECONDS);

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

loggerContext.getStatusManager().clear();

try {
CountDownLatch secondDoneLatch = waitForReconfigurationToBeDone(oldRoct);
CountDownLatch secondDoneLatch = registerNewReconfigurationDoneListener_WithNewROCT(oldRoct);
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
secondDoneLatch.await();

Expand Down Expand Up @@ -311,7 +318,7 @@ private ReconfigureOnChangeTask waitForReconfigureOnChangeTaskToRun() throws Int
return roct;
}

private CountDownLatch waitForReconfigurationToBeDone(ReconfigureOnChangeTask oldTask) throws InterruptedException {
private CountDownLatch registerNewReconfigurationDoneListener_WithNewROCT(ReconfigureOnChangeTask oldTask) throws InterruptedException {

addInfo("waitForReconfigurationToBeDone oldTask=" + oldTask, this);
ReconfigureOnChangeTask roct = oldTask;
Expand Down

0 comments on commit a7eb9bc

Please sign in to comment.