Skip to content

Commit 6291ab4

Browse files
committed
Replace counter with timestamp
1 parent a9edc05 commit 6291ab4

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDirectory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.concurrent.ConcurrentHashMap;
31-
import java.util.concurrent.atomic.AtomicInteger;
3231
import org.apache.logging.log4j.status.StatusLogger;
3332
import org.apache.logging.log4j.test.TestProperties;
3433
import org.junit.jupiter.api.extension.BeforeAllCallback;
@@ -46,8 +45,6 @@
4645

4746
public class TempLoggingDirectory implements BeforeAllCallback, BeforeEachCallback, ParameterResolver {
4847

49-
private final AtomicInteger counter = new AtomicInteger();
50-
5148
@Override
5249
public void beforeAll(ExtensionContext context) throws Exception {
5350
final List<Field> fields = AnnotationSupport.findAnnotatedFields(
@@ -155,8 +152,10 @@ private Path determinePerClassPath(ExtensionContext context) {
155152
// Create a temporary directory that uses the simple class name as prefix
156153
Path packagePath = basePath.resolve(dir);
157154
Files.createDirectories(packagePath);
155+
// Use a UNIX timestamp to (roughly) sort directories by execution time.
158156
return Files.createTempDirectory(
159-
packagePath, String.format("%s_%02d_", clazz.getSimpleName(), counter.incrementAndGet()));
157+
packagePath,
158+
String.format("%s_%08x_", clazz.getSimpleName(), System.currentTimeMillis() / 1000));
160159
} catch (final IOException e) {
161160
throw new ExtensionContextException("Failed to create temporary directory.", e);
162161
}

log4j-api-test/src/test/java/org/apache/logging/log4j/test/junit/TempLoggingDirectoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@UsingTestProperties
2828
public class TempLoggingDirectoryTest {
2929

30-
private static final Pattern PER_CLASS_PATH = Pattern.compile("TempLoggingDirectoryTest_\\d{2}_\\d+");
30+
private static final Pattern PER_CLASS_PATH = Pattern.compile("TempLoggingDirectoryTest_[0-9a-f]{8,}_\\d+");
3131
private static final Path PER_TEST_PATH = Paths.get("testInjectedFields");
3232

3333
@TempLoggingDir

0 commit comments

Comments
 (0)