You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2020/08/01 22:39:22 UTC
[logging-log4j2] branch master updated: LOG4J2-2883 - Add unit test
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new c0487ad LOG4J2-2883 - Add unit test
c0487ad is described below
commit c0487ad694fd98f047b48fb7d43a74af99bbba28
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Aug 1 15:39:07 2020 -0700
LOG4J2-2883 - Add unit test
---
.../rolling/RollingDirectTimeNewDirectoryTest.java | 73 ++++++++++++++++++++++
.../test/resources/log4j-rolling-folder-direct.xml | 39 ++++++++++++
2 files changed, 112 insertions(+)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java
new file mode 100644
index 0000000..8372a7e
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.Logger;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+
+import java.io.File;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests
+ */
+public class RollingDirectTimeNewDirectoryTest {
+ private static final String CONFIG = "log4j-rolling-folder-direct.xml";
+
+ private static final String DIR = "target/rolling-folder-direct";
+
+ public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG);
+
+ @Rule
+ public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR);
+
+ private Logger logger;
+
+ @Before
+ public void setUp() throws Exception {
+ this.logger = loggerContextRule.getLogger(RollingDirectTimeNewDirectoryTest.class.getName());
+ }
+
+
+ @Test
+ public void streamClosedError() throws Exception {
+ for (int i = 0; i < 1000; i++) {
+ logger.info("nHq6p9kgfvWfjzDRYbZp");
+ }
+ Thread.sleep(1500);
+ for (int i = 0; i < 1000; i++) {
+ logger.info("nHq6p9kgfvWfjzDRYbZp");
+ }
+
+ File tempDirectoryAsFile = new File(DIR);
+ File[] loggingFolders = tempDirectoryAsFile.listFiles();
+ assertNotNull(loggingFolders);
+ // Check if two folders were created
+ assertTrue("Not enough directories created", loggingFolders.length >= 2);
+ for (File dir : loggingFolders) {
+ File[] files = dir.listFiles();
+ assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0);
+ }
+ }
+}
diff --git a/log4j-core/src/test/resources/log4j-rolling-folder-direct.xml b/log4j-core/src/test/resources/log4j-rolling-folder-direct.xml
new file mode 100644
index 0000000..9ded6a3
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-folder-direct.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="WARN" name="XMLConfigTest">
+ <Properties>
+ <Property name="logDir">target/rolling-folder-direct</Property>
+ </Properties>
+ <Appenders>
+ <RollingFile name="RollingFile" filePattern="${logDir}/%d{MM-dd-yy-HH-mm-ss}/processor.log">
+ <PatternLayout>
+ <Pattern>%d} %p %C{1.} [%t] %m%n</Pattern>
+ </PatternLayout>
+ <TimeBasedTriggeringPolicy />
+ <DirectWriteRolloverStrategy/>
+ </RollingFile>
+ </Appenders>
+
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="RollingFile"/>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file