LOG4J2-435 fixed broken integration test; prevent unconditional deletion Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9075473b Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9075473b Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9075473b
Branch: refs/heads/master Commit: 9075473bd1eedf830a47c7dd71d798b291bba5ee Parents: bc807a8 Author: rpopma <[email protected]> Authored: Fri Nov 27 01:34:14 2015 +0900 Committer: rpopma <[email protected]> Committed: Fri Nov 27 01:34:14 2015 +0900 ---------------------------------------------------------------------- .../log4j/core/appender/rolling/action/DeleteAction.java | 10 +++++++--- .../rolling/RollingAppenderCustomDeleteActionTest.java | 7 ++++--- .../test/resources/log4j-rolling-with-custom-delete.xml | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9075473b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java index 3abaae7..4cb6b9f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java @@ -48,13 +48,17 @@ public class DeleteAction extends AbstractPathAction { * means that only the starting file is visited, unless denied by the security manager. A value of * MAX_VALUE may be used to indicate that all levels should be visited. * @param sorter sorts - * @param pathFilters an array of path filters (if more than one, they all need to accept a path before it is + * @param pathConditions an array of path filters (if more than one, they all need to accept a path before it is * deleted). */ DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, final PathSorter sorter, - final PathCondition[] pathFilters, final StrSubstitutor subst) { - super(basePath, followSymbolicLinks, maxDepth, pathFilters, subst); + final PathCondition[] pathConditions, final StrSubstitutor subst) { + super(basePath, followSymbolicLinks, maxDepth, pathConditions, subst); this.pathSorter = Objects.requireNonNull(sorter, "sorter"); + if (pathConditions == null || pathConditions.length == 0) { + LOGGER.error("Missing Delete conditions: unconditional Delete not supported"); + throw new IllegalArgumentException("Unconditional Delete not supported"); + } } /* http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9075473b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java index fab8e07..294d7c7 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java @@ -58,7 +58,8 @@ public class RollingAppenderCustomDeleteActionTest { Thread.sleep(100); // Allow time for rollover to complete final File dir = new File(DIR); - assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0); + assertTrue("Dir " + DIR + " should exist", dir.exists()); + assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final int MAX_TRIES = 20; for (int i = 0; i < MAX_TRIES; i++) { @@ -68,8 +69,8 @@ public class RollingAppenderCustomDeleteActionTest { } if (files.length == 3) { for (File file : files) { - assertTrue("test-4.log.gz should have been deleted", - Arrays.asList("test-1.log.gz", "test-2.log.gz", "test-3.log.gz").contains(file.getName())); + assertTrue("test-4.log should have been deleted", + Arrays.asList("test-1.log", "test-2.log", "test-3.log").contains(file.getName())); } return; // test succeeded } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9075473b/log4j-core/src/test/resources/log4j-rolling-with-custom-delete.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j-rolling-with-custom-delete.xml b/log4j-core/src/test/resources/log4j-rolling-with-custom-delete.xml index b93484d..869e2e6 100644 --- a/log4j-core/src/test/resources/log4j-rolling-with-custom-delete.xml +++ b/log4j-core/src/test/resources/log4j-rolling-with-custom-delete.xml @@ -27,17 +27,17 @@ </Console> <RollingFile name="RollingFile" fileName="${base}/rollingtest.log" - filePattern="${base}/test/test-%i.log.gz"> + filePattern="${base}/test/test-%i.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> <Policies> <SizeBasedTriggeringPolicy size="50" /> </Policies> - <DefaultRolloverStrategy stopCustomActionsOnError="true"> + <DefaultRolloverStrategy max="100" stopCustomActionsOnError="true"> <!-- custom action executed asynchronously after the rollover --> <Delete basePath="${base}/test" maxDepth="2" followLinks="false"> - <IfFileName path="test-4.log.gz" /> <!-- only keep files 1, 2 and 3 --> + <IfFileName glob="test-4.log" /> <!-- only keep files 1, 2 and 3 --> </Delete> </DefaultRolloverStrategy> </RollingFile>
