Use a local temp directory in logging system tests

Previously, the tests for Boot’s various logging systems used the
JVM’s default temp directory as the location of the spring.log file.
It is suspected that this was causing intermittent CI failures when
multiple Boot builds were running in parallel and tests were checking
for the presence of the spring.log file in the shared temp directory.

This commit updates AbstractLoggingSystemTests to configure a local
temp directory for the duration of the tests, thereby hopefully
eliminating failures caused by concurrent builds sharing the same
directory.

The previous attempt at fixing the intermittent CI failures (504de8a)
has been removed as part of this commit as it did not fix the problem.

Closes gh-1864
This commit is contained in:
Andy Wilkinson 2014-11-11 13:30:11 +00:00
parent f9221e24ef
commit 215689bd4d
2 changed files with 21 additions and 16 deletions

View File

@ -19,16 +19,36 @@ package org.springframework.boot.logging;
import java.io.File;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.util.StringUtils;
/**
* Base for {@link LoggingSystem} tests.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public abstract class AbstractLoggingSystemTests {
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
private static String tempDir;
@BeforeClass
public static void configureTempdir() {
tempDir = System.getProperty(JAVA_IO_TMPDIR);
File newTempDir = new File("target/tmp");
newTempDir.mkdirs();
System.setProperty(JAVA_IO_TMPDIR, newTempDir.getAbsolutePath());
}
@AfterClass
public static void reinstateTempDir() {
System.setProperty(JAVA_IO_TMPDIR, tempDir);
}
@Before
public void deleteTempLog() {
new File(tmpDir() + "/spring.log").delete();
@ -41,7 +61,7 @@ public abstract class AbstractLoggingSystemTests {
}
protected final String tmpDir() {
String path = StringUtils.cleanPath(System.getProperty("java.io.tmpdir"));
String path = StringUtils.cleanPath(System.getProperty(JAVA_IO_TMPDIR));
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}

View File

@ -17,13 +17,9 @@
package org.springframework.boot.logging.log4j2;
import java.io.File;
import java.util.Map.Entry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
@ -59,17 +55,6 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
this.logger = LogManager.getLogger(getClass());
}
@After
public void flushAllOutputStreamAppenders() {
for (Entry<String, Appender> entry : ((org.apache.logging.log4j.core.Logger) this.logger)
.getAppenders().entrySet()) {
Appender appender = entry.getValue();
if (appender instanceof AbstractOutputStreamAppender) {
((AbstractOutputStreamAppender<?>) appender).getManager().flush();
}
}
}
@Test
public void noFile() throws Exception {
this.loggingSystem.beforeInitialize();