You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/12/15 22:56:32 UTC

logging-log4j2 git commit: Forgot to commit tests for [LOG4J2-1474], doh.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 1fbd43d73 -> 1a470d62d


Forgot to commit tests for [LOG4J2-1474], doh.

CronTriggeringPolicy raise exception and fail to rollover log file when
evaluateOnStartup is true.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1a470d62
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1a470d62
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1a470d62

Branch: refs/heads/master
Commit: 1a470d62dcf4e8cd747a7dc05b151f878af18408
Parents: 1fbd43d
Author: ggregory <gg...@US-L-GG02.rocketsoftware.com>
Authored: Thu Dec 15 14:56:26 2016 -0800
Committer: ggregory <gg...@US-L-GG02.rocketsoftware.com>
Committed: Thu Dec 15 14:56:26 2016 -0800

----------------------------------------------------------------------
 .../rolling/CronTriggeringPolicyTest.java       | 89 ++++++++++++++++++++
 1 file changed, 89 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1a470d62/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java
new file mode 100644
index 0000000..d910ccd
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.appender.rolling;
+
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.NullConfiguration;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CronTriggeringPolicyTest {
+
+    private static final NullConfiguration NULL_CONFIGURATION = new NullConfiguration();
+
+    private CronTriggeringPolicy createPolicy() {
+        return CronTriggeringPolicy.createPolicy(NULL_CONFIGURATION, Boolean.TRUE.toString(), "0 0 0 * * ?");
+    }
+
+    private DefaultRolloverStrategy createStrategy() {
+        return DefaultRolloverStrategy.createStrategy("7", "1", "max", null, null, false, NULL_CONFIGURATION);
+    }
+
+    /**
+     * Tests LOG4J2-1474 CronTriggeringPolicy raise exception and fail to rollover log file when evaluateOnStartup is
+     * true.
+     */
+    @Test
+    public void testBuilder() {
+        testBuilder(NULL_CONFIGURATION);
+    }
+
+    public void testBuilder(final Configuration configuration) {
+        // @formatter:off
+        final RollingFileAppender raf = RollingFileAppender.newBuilder()
+            .withName("test")
+            .withFileName("testcmd.log")
+            .withFilePattern("testcmd.log.%d{yyyy-MM-dd}")
+            .withPolicy(createPolicy())
+            .withStrategy(createStrategy())
+            .setConfiguration(configuration)
+            .build();
+        // @formatter:on
+        Assert.assertNotNull(raf);
+    }
+
+    /**
+     * Tests LOG4J2-1474 CronTriggeringPolicy raise exception and fail to rollover log file when evaluateOnStartup is
+     * true.
+     */
+    @Test
+    public void testBuilderSequence() {
+        testBuilder(NULL_CONFIGURATION);
+        testBuilder(NULL_CONFIGURATION);
+    }
+
+    /**
+     * Tests LOG4J2-1474 CronTriggeringPolicy raise exception and fail to rollover log file when evaluateOnStartup is
+     * true.
+     */
+    @Test
+    public void testFactoryMethod() {
+        final CronTriggeringPolicy triggerPolicy = createPolicy();
+        final DefaultRolloverStrategy rolloverStrategy = createStrategy();
+
+        try (RollingFileManager fileManager = RollingFileManager.getFileManager("testcmd.log",
+                "testcmd.log.%d{yyyy-MM-dd}", true, true, triggerPolicy, rolloverStrategy, null,
+                PatternLayout.createDefaultLayout(), 0, true, false, null)) {
+            // trigger rollover
+            fileManager.initialize();
+            fileManager.rollover();
+        }
+    }
+}