Skip to content

Commit 9874f06

Browse files
committed
test for top-file as a resource, introduced new module logback-classic-misc
Signed-off-by: ceki <[email protected]>
1 parent 5c8e5c3 commit 9874f06

6 files changed

Lines changed: 102 additions & 34 deletions

File tree

logback-classic-blackbox/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<groupId>ch.qos.logback</groupId>
2626
<artifactId>logback-classic</artifactId>
2727
</dependency>
28+
<dependency>
29+
<groupId>ch.qos.logback</groupId>
30+
<artifactId>logback-classic-misc</artifactId>
31+
</dependency>
2832

2933
<dependency>
3034
<groupId>org.eclipse.jetty</groupId>

logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/ReconfigureOnChangeTaskTest.java

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class ReconfigureOnChangeTaskTest extends ReconfigureTaskTestSupport {
7171

7272
private static final String SCAN_PERIOD_DEFAULT_FILE_AS_STR = JORAN_INPUT_PREFIX + "roct/scan_period_default.xml";
7373

74-
private static final String TOP_FILE_WITH_INCLUSION = "asResource/topWithFileInclusion.xml";
74+
private static final String TOP_FILE_WITH_INCLUSION = "misc/topWithFileInclusion.xml";
7575

7676
Logger logger = loggerContext.getLogger(this.getClass());
7777
StatusChecker statusChecker = new StatusChecker(loggerContext);
@@ -160,22 +160,22 @@ public void propertiesConfigurationTest() throws IOException, JoranException, In
160160
String propertiesFileStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "roct-" + diff + ".properties";
161161
File propertiesFile = new File(propertiesFileStr);
162162
String configurationStr = "<configuration debug=\"true\" scan=\"true\" scanPeriod=\"10 millisecond\"><propertiesConfigurator file=\"" + propertiesFileStr + "\"/></configuration>";
163-
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName+"=INFO");
163+
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName + "=INFO");
164164
configure(asBAIS(configurationStr));
165165
Logger abcLogger = loggerContext.getLogger(loggerName);
166166
assertEquals(Level.INFO, abcLogger.getLevel());
167167

168168
CountDownLatch changeDetectedLatch0 = registerChangeDetectedListener();
169169
CountDownLatch configurationDoneLatch0 = registerPartialConfigurationEndedSuccessfullyEventListener();
170170

171-
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName+"=WARN");
171+
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName + "=WARN");
172172
changeDetectedLatch0.await();
173173
configurationDoneLatch0.await();
174174
assertEquals(Level.WARN, abcLogger.getLevel());
175175

176176
CountDownLatch changeDetectedLatch1 = registerChangeDetectedListener();
177177
CountDownLatch configurationDoneLatch1 = registerPartialConfigurationEndedSuccessfullyEventListener();
178-
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName+"=ERROR");
178+
writeToFile(propertiesFile, PropertiesConfigurator.LOGBACK_LOGGER_PREFIX + loggerName + "=ERROR");
179179
changeDetectedLatch1.await();
180180
configurationDoneLatch1.await();
181181

@@ -268,7 +268,7 @@ public void fallbackToSafe_FollowedByRecovery() throws IOException, JoranExcepti
268268

269269
private void addResetResistantOnConsoleStatusListener() {
270270
// enable when debugging
271-
if(1!=1)
271+
if (1 == 1)
272272
return;
273273
OnConsoleStatusListener ocs = new OnConsoleStatusListener();
274274
ocs.setContext(loggerContext);
@@ -279,38 +279,40 @@ private void addResetResistantOnConsoleStatusListener() {
279279

280280
@Test
281281
@Timeout(value = 2, unit = TimeUnit.SECONDS)
282-
public void XXXscanWithIncludedFileCreatedLater() throws IOException, JoranException, InterruptedException {
283-
ReconfigurationTaskRegisteredConfigEventListener roctRegisteredListener = new ReconfigurationTaskRegisteredConfigEventListener();
284-
loggerContext.addConfigurationEventListener(roctRegisteredListener);
285-
addResetResistantOnConsoleStatusListener();
286-
String innerFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "scanWithIncludedFileCreatedLater-" + diff + ".xml";
287-
System.setProperty("fileCreatedLater", innerFileAsStr);
288-
configureAsResource(TOP_FILE_WITH_INCLUSION);
282+
public void scanWithIncludedFileCreatedLater() throws IOException, JoranException, InterruptedException {
289283

290-
File innerFile = new File(innerFileAsStr);
284+
try {
285+
ReconfigurationTaskRegisteredConfigEventListener roctRegisteredListener = new ReconfigurationTaskRegisteredConfigEventListener();
286+
loggerContext.addConfigurationEventListener(roctRegisteredListener);
287+
addResetResistantOnConsoleStatusListener();
288+
String innerFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "scanWithIncludedFileCreatedLater-" + diff + ".xml";
289+
System.setProperty("fileCreatedLater", innerFileAsStr);
290+
configureAsResource(TOP_FILE_WITH_INCLUSION);
291+
292+
if(isSurefire()) {
293+
statusChecker.assertContainsMatch("URL \\[.*\\] is not of type file");
294+
}
291295

292-
List<File> fileList = getConfigurationWatchList(loggerContext);
293-
assertThatListContainsFile(fileList, innerFile);
296+
File innerFile = new File(innerFileAsStr);
294297

295-
// capture reference to ReconfigureOnChangeTask
296-
//ReconfigureOnChangeTask roct = roctRegisteredListener.reconfigureOnChangeTask;
297-
//assertNotNull(roct);
298+
List<File> fileList = getConfigurationWatchList(loggerContext);
299+
assertThatListContainsFile(fileList, innerFile);
298300

299-
CountDownLatch changeDetectedLatch = registerChangeDetectedListener();
300-
CountDownLatch configurationDoneLatch = registerNewReconfigurationDoneSuccessfullyListener();
301+
CountDownLatch changeDetectedLatch = registerChangeDetectedListener();
302+
CountDownLatch configurationDoneLatch = registerNewReconfigurationDoneSuccessfullyListener();
301303

304+
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
305+
changeDetectedLatch.await();
306+
configurationDoneLatch.await();
302307

303-
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
304-
changeDetectedLatch.await();
305-
configurationDoneLatch.await();
306-
307-
//Thread.sleep(1000);
308-
//waitForReconfigureOnChangeTaskToRun();
309-
310-
//statusPrinter2.print(loggerContext);
311-
Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
312-
assertEquals(Level.ERROR, root.getLevel());
308+
//statusPrinter2.print(loggerContext);
309+
Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
310+
assertEquals(Level.ERROR, root.getLevel());
313311

312+
//System.getProperties().forEach((k,v)->System.out.println(k+"="+v));
313+
} finally {
314+
System.getProperties().remove("fileCreatedLater");
315+
}
314316
}
315317

316318

@@ -321,7 +323,7 @@ public void fallbackToSafeWithIncludedFile_FollowedByRecovery() throws IOExcepti
321323
String innerFileAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + "reconfigureOnChangeConfig_inner-" + diff + ".xml";
322324
File topLevelFile = new File(topLevelFileAsStr);
323325
writeToFile(topLevelFile,
324-
"<configuration xdebug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\"><include file=\"" + innerFileAsStr + "\"/></configuration> ");
326+
"<configuration xdebug=\"true\" scan=\"true\" scanPeriod=\"5 millisecond\"><include file=\"" + innerFileAsStr + "\"/></configuration> ");
325327

326328
File innerFile = new File(innerFileAsStr);
327329
writeToFile(innerFile, "<included><root level=\"ERROR\"/></included> ");
@@ -330,6 +332,7 @@ public void fallbackToSafeWithIncludedFile_FollowedByRecovery() throws IOExcepti
330332
configure(topLevelFile);
331333

332334

335+
333336
CountDownLatch changeDetectedLatch = registerChangeDetectedListener();
334337
CountDownLatch configurationDoneLatch = registerNewReconfigurationDoneSuccessfullyListener();
335338

@@ -362,6 +365,16 @@ CountDownLatch registerNewReconfigurationDoneSuccessfullyListener() {
362365
return latch;
363366
}
364367

368+
boolean isSurefire() {
369+
if(System.getProperty("surefire.test.class.path") != null) {
370+
return true;
371+
}
372+
if(System.getProperty("surefire.real.class.path") != null) {
373+
return true;
374+
}
375+
return false;
376+
}
377+
365378
static class RunMethodInvokedListener implements ConfigurationEventListener {
366379
CountDownLatch countDownLatch;
367380
ReconfigureOnChangeTask reconfigureOnChangeTask;

logback-classic-misc/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>ch.qos.logback</groupId>
10+
<artifactId>logback-parent</artifactId>
11+
<version>1.5.30-SNAPSHOT</version>
12+
</parent>
13+
14+
<artifactId>logback-classic-misc</artifactId>
15+
<packaging>jar</packaging>
16+
<name>Logback Classic Miscellaneous Module</name>
17+
<description>logback-classic-misc module</description>
18+
19+
20+
<dependencies>
21+
22+
</dependencies>
23+
24+
<build>
25+
<resources>
26+
<resource>
27+
<directory>src/main/resources/</directory>
28+
</resource>
29+
</resources>
30+
31+
<plugins>
32+
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-jar-plugin</artifactId>
36+
<configuration>
37+
<archive>
38+
<manifestEntries>
39+
</manifestEntries>
40+
</archive>
41+
</configuration>
42+
</plugin>
43+
44+
</plugins>
45+
</build>
46+
47+
</project>

logback-classic-blackbox/src/test/resources/asResource/topWithFileInclusion.xml renamed to logback-classic-misc/src/main/resources/misc/topWithFileInclusion.xml

File renamed without changes.

logback-core/src/main/java/ch/qos/logback/core/model/processor/IncludeModelHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ protected Class<IncludeModel> getSupportedModelClass() {
6262
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
6363
IncludeModel includeModel = (IncludeModel) model;
6464

65-
System.out.println("==============================IncludeModelHandler.handle");
66-
6765
URL topURL = mic.getTopURL();
6866
Boolean topScan = mic.getTopScanBoolean();
6967
Model modelFromIncludedFile = buildModelFromIncludedFile(mic, topURL, topScan, includeModel);

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<module>logback-core</module>
4444
<module>logback-core-blackbox</module>
4545
<module>logback-classic</module>
46+
<module>logback-classic-misc</module>
4647
<module>logback-classic-blackbox</module>
4748
<module>logback-access</module>
4849
<module>logback-examples</module>
@@ -177,6 +178,11 @@
177178
<artifactId>logback-classic</artifactId>
178179
<version>${project.version}</version>
179180
</dependency>
181+
<dependency>
182+
<groupId>ch.qos.logback</groupId>
183+
<artifactId>logback-classic-misc</artifactId>
184+
<version>${project.version}</version>
185+
</dependency>
180186
<dependency>
181187
<groupId>org.slf4j</groupId>
182188
<artifactId>slf4j-api</artifactId>
@@ -460,7 +466,7 @@
460466
<extensions>true</extensions>
461467
<configuration>
462468
<publishingServerId>central</publishingServerId>
463-
<excludeArtifacts>logback-core-blackbox,logback-classic-blackbox,logback-examples</excludeArtifacts>
469+
<excludeArtifacts>logback-core-blackbox,logback-classic-misc,logback-classic-blackbox,logback-examples</excludeArtifacts>
464470
</configuration>
465471
</plugin>
466472

0 commit comments

Comments
 (0)