Bullet proofing. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9972ee5f Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9972ee5f Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9972ee5f
Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure Commit: 9972ee5f8bef6086b284e023203ac0a7389b65bf Parents: d4dca3f Author: Gary Gregory <ggreg...@apache.org> Authored: Mon Aug 8 19:33:07 2016 -0700 Committer: Gary Gregory <ggreg...@apache.org> Committed: Mon Aug 8 19:33:07 2016 -0700 ---------------------------------------------------------------------- .../rolling/OnStartupTriggeringPolicyTest.java | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9972ee5f/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java index c809ddb..eacf7c6 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java @@ -16,29 +16,35 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Arrays; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.core.util.datetime.FastDateFormat; -import org.junit.Ignore; +import org.junit.Assert; import org.junit.Test; /** - * + * Tests {@link OnStartupTriggeringPolicy}. */ +//@Ignore public class OnStartupTriggeringPolicyTest { - private static final String TARGET_FILE = "target/rollOnStartup/testfile"; - private static final String TARGET_PATTERN = "target/rollOnStartup/test1-%d{MM-dd-yyyy}-%i.log"; - private static final String ROLLED_FILE_PREFIX = "target/rollOnStartup/test1-"; + private static final String TARGET_FOLDER = "target/rollOnStartup"; + private static final String TARGET_FILE = TARGET_FOLDER + "/testfile"; + private static final String TARGET_PATTERN = TARGET_FOLDER + "/test1-%d{MM-dd-yyyy}-%i.log"; + private static final String ROLLED_FILE_PREFIX = TARGET_FOLDER + "/test1-"; private static final String ROLLED_FILE_SUFFIX = "-1.log"; private static final String TEST_DATA = "Hello world!"; private static final FastDateFormat formatter = FastDateFormat.getInstance("MM-dd-yyyy"); @@ -55,13 +61,15 @@ public class OnStartupTriggeringPolicyTest { final String expectedDate = formatter.format(timeStamp); final String rolledFileName = ROLLED_FILE_PREFIX + expectedDate + ROLLED_FILE_SUFFIX; final Path rolled = Paths.get(rolledFileName); + final long copied; try (final InputStream is = new ByteArrayInputStream(TEST_DATA.getBytes("UTF-8"))) { - Files.copy(is, target); + copied = Files.copy(is, target, StandardCopyOption.REPLACE_EXISTING); } final long size = Files.size(target); assertTrue(size > 0); + assertEquals(copied, size); - target.toFile().setLastModified(timeStamp); + Assert.assertTrue(target.toFile().setLastModified(timeStamp)); final PatternLayout layout = PatternLayout.newBuilder().withPattern("%msg").withConfiguration(configuration) .build(); final RolloverStrategy strategy = DefaultRolloverStrategy.createStrategy(null, null, null, "0", null, true, @@ -71,10 +79,11 @@ public class OnStartupTriggeringPolicyTest { policy, strategy, null, layout, 8192, true); try { manager.initialize(); - assertTrue(Files.exists(target)); - assertTrue(Files.size(target) == 0); - assertTrue(Files.exists(rolled)); - assertTrue(Files.size(rolled) == size); + String files = Arrays.toString(new File(TARGET_FOLDER).listFiles()); + assertTrue(target.toString() + ", files = " + files, Files.exists(target)); + assertEquals(target.toString(), 0, Files.size(target)); + assertTrue(rolled.toString() + ", files = " + files, Files.exists(rolled)); + assertEquals(rolled.toString(), size, Files.size(rolled)); } finally { manager.release(); }