From d69f06890ec8e085a6674cc081ece0a6f76d51ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Tue, 6 Feb 2024 22:15:45 +0100 Subject: [PATCH] Repair or remove ineffective tests --- .../apache/log4j/defaultInit/TestCase1.java | 50 ------ .../apache/log4j/defaultInit/TestCase2.java | 55 ------ .../apache/log4j/defaultInit/TestCase3.java | 50 ------ .../apache/log4j/defaultInit/TestCase4.java | 56 ------ .../helpers/OptionConverterTestCase.java | 169 ------------------ .../log4j/helpers/PatternParserTestCase.java | 129 ------------- .../input/defaultInit3.properties | 23 --- .../status/StatusLoggerSerializationTest.java | 37 ---- ...gRandomAccessFileAppenderRolloverTest.java | 107 ----------- .../XmlCompactFileAppenderValidationTest.java | 104 ----------- ...ompactFileAsyncAppenderValidationTest.java | 80 --------- .../XmlRandomAccessFileAppenderTest.java | 88 --------- ...ndomAccessFileManagerHeaderFooterTest.java | 110 ------------ ... AsyncLoggerArgumentFreedOnErrorTest.java} | 2 +- .../core/async/AsyncLoggerConfigTest3.java | 71 -------- .../core/async/AsyncLoggerConfigTest4.java | 87 --------- ...Time.java => AsyncLoggerNanoTimeTest.java} | 2 +- .../async/QueueFullAsyncAppenderTest2.java | 34 ---- ...cLoggerConfigLoggingFromToStringTest2.java | 37 ---- .../QueueFullAsyncLoggerConfigTest2.java | 36 ---- ...llAsyncLoggerLoggingFromToStringTest2.java | 44 ----- .../core/async/QueueFullAsyncLoggerTest2.java | 37 ---- .../core/async/QueueFullAsyncLoggerTest3.java | 117 ------------ ...nfigurator.java => Configurator1Test.java} | 2 +- ...uratorTest.java => Configurator2Test.java} | 2 +- ...rError.java => ConfiguratorErrorTest.java} | 6 +- ...Language.java => MissingLanguageTest.java} | 4 +- ...tNoLanguages.java => NoLanguagesTest.java} | 7 +- .../core/pattern/PatternParserTest2.java | 91 ---------- .../XmlCompactFileAppenderValidationTest.xml | 30 ---- ...CompactFileAsyncAppenderValidationTest.xml | 30 ---- .../XmlRandomAccessFileAppenderTest.xml | 30 ---- 32 files changed, 13 insertions(+), 1714 deletions(-) delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase1.java delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase2.java delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase3.java delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase4.java delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/helpers/OptionConverterTestCase.java delete mode 100644 log4j-1.2-api/src/test/java/org/apache/log4j/helpers/PatternParserTestCase.java delete mode 100644 log4j-1.2-api/src/test/resources/log4j1-1.2.17/input/defaultInit3.properties delete mode 100644 log4j-api-test/src/test/java/org/apache/logging/log4j/status/StatusLoggerSerializationTest.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderRolloverTest.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAsyncAppenderValidationTest.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerHeaderFooterTest.java rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/{AsyncLoggerTestArgumentFreedOnError.java => AsyncLoggerArgumentFreedOnErrorTest.java} (98%) delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest4.java rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/{AsyncLoggerTestNanoTime.java => AsyncLoggerNanoTimeTest.java} (99%) delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest2.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest2.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/{TestConfigurator.java => Configurator1Test.java} (99%) rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/{ConfiguratorTest.java => Configurator2Test.java} (99%) rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/{TestConfiguratorError.java => ConfiguratorErrorTest.java} (92%) rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/{TestMissingLanguage.java => MissingLanguageTest.java} (98%) rename log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/{TestNoLanguages.java => NoLanguagesTest.java} (97%) delete mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest2.java delete mode 100644 log4j-core-test/src/test/resources/XmlCompactFileAppenderValidationTest.xml delete mode 100644 log4j-core-test/src/test/resources/XmlCompactFileAsyncAppenderValidationTest.xml delete mode 100644 log4j-core-test/src/test/resources/XmlRandomAccessFileAppenderTest.xml diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase1.java b/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase1.java deleted file mode 100644 index 30aeafeb7a3..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase1.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.log4j.defaultInit; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.junit.Ignore; - -@Ignore -public class TestCase1 extends TestCase { - - public TestCase1(final String name) { - super(name); - } - - public void setUp() {} - - public void tearDown() { - LogManager.shutdown(); - } - - public void noneTest() { - final Logger root = Logger.getRootLogger(); - final boolean rootIsConfigured = root.getAllAppenders().hasMoreElements(); - assertTrue(!rootIsConfigured); - } - - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(new TestCase1("noneTest")); - return suite; - } -} diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase2.java b/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase2.java deleted file mode 100644 index c41634fb1e9..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase2.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.log4j.defaultInit; - -import java.util.Enumeration; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.log4j.Appender; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.junit.Ignore; - -@Ignore -public class TestCase2 extends TestCase { - - public TestCase2(final String name) { - super(name); - } - - public void setUp() {} - - public void tearDown() { - LogManager.shutdown(); - } - - public void xmlTest() { - final Logger root = Logger.getRootLogger(); - final boolean rootIsConfigured = root.getAllAppenders().hasMoreElements(); - assertTrue(rootIsConfigured); - final Enumeration e = root.getAllAppenders(); - final Appender appender = (Appender) e.nextElement(); - assertEquals(appender.getName(), "D1"); - } - - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(new TestCase2("xmlTest")); - return suite; - } -} diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase3.java b/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase3.java deleted file mode 100644 index 6978b7223a7..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase3.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.log4j.defaultInit; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.Enumeration; -import org.apache.log4j.Appender; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.config.TestConfigurator; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@Disabled -public class TestCase3 { - - @AfterAll - public static void tearDown() { - LogManager.shutdown(); - } - - @Test - public void propertiesTest() throws IOException { - TestConfigurator.configure("src/test/resources/log4j1-1.2.17/input/defaultInit3.properties"); - final Logger root = Logger.getRootLogger(); - final boolean rootIsConfigured = root.getAllAppenders().hasMoreElements(); - assertTrue(rootIsConfigured); - final Enumeration e = root.getAllAppenders(); - final Appender appender = (Appender) e.nextElement(); - assertEquals(appender.getName(), "D3"); - } -} diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase4.java b/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase4.java deleted file mode 100644 index 7bf4364faa3..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/defaultInit/TestCase4.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.log4j.defaultInit; - -import java.util.Enumeration; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.log4j.Appender; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.junit.Ignore; - -@Ignore -public class TestCase4 extends TestCase { - - public TestCase4(final String name) { - super(name); - } - - public void setUp() {} - - public void tearDown() { - LogManager.shutdown(); - } - - public void combinedTest() { - final Logger root = Logger.getRootLogger(); - final boolean rootIsConfigured = root.getAllAppenders().hasMoreElements(); - assertTrue(rootIsConfigured); - final Enumeration e = root.getAllAppenders(); - final Appender appender = (Appender) e.nextElement(); - assertEquals(appender.getName(), "D1"); - assertEquals(e.hasMoreElements(), false); - } - - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(new TestCase4("combinedTest")); - return suite; - } -} diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/OptionConverterTestCase.java b/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/OptionConverterTestCase.java deleted file mode 100644 index c2e29b7824f..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/OptionConverterTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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.log4j.helpers; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.PropertyConfiguratorTest; -import org.apache.log4j.xml.XLevel; -import org.junit.Ignore; - -/** - * Test variable substitution code. - * - * @since 1.0 - */ -@Ignore("WIP") -public class OptionConverterTestCase extends TestCase { - - Properties props; - - public OptionConverterTestCase(final String name) { - super(name); - } - - public void setUp() { - props = new Properties(); - props.put("TOTO", "wonderful"); - props.put("key1", "value1"); - props.put("key2", "value2"); - // Log4J will NPE without this: - props.put("line.separator", System.getProperty("line.separator")); - // Log4J will throw an Error without this: - props.put("java.home", System.getProperty("java.home")); - System.setProperties(props); - } - - public void tearDown() { - props = null; - LogManager.resetConfiguration(); - } - - public void varSubstTest1() { - String r; - - r = OptionConverter.substVars("hello world.", null); - assertEquals("hello world.", r); - - r = OptionConverter.substVars("hello ${TOTO} world.", null); - - assertEquals("hello wonderful world.", r); - } - - public void varSubstTest2() { - String r; - - r = OptionConverter.substVars("Test2 ${key1} mid ${key2} end.", null); - assertEquals("Test2 value1 mid value2 end.", r); - } - - public void varSubstTest3() { - String r; - - r = OptionConverter.substVars("Test3 ${unset} mid ${key1} end.", null); - assertEquals("Test3 mid value1 end.", r); - } - - public void varSubstTest4() { - final String val = "Test4 ${incomplete "; - try { - OptionConverter.substVars(val, null); - } catch (IllegalArgumentException e) { - final String errorMsg = e.getMessage(); - // System.out.println('['+errorMsg+']'); - assertEquals('"' + val + "\" has no closing brace. Opening brace at position 6.", errorMsg); - } - } - - public void varSubstTest5() { - final Properties props = new Properties(); - props.put("p1", "x1"); - props.put("p2", "${p1}"); - final String res = OptionConverter.substVars("${p2}", props); - System.out.println("Result is [" + res + "]."); - assertEquals(res, "x1"); - } - - /** - * Tests configuring Log4J from an InputStream. - * - * @since 1.2.17 - */ - public void testInputStream() throws IOException { - final File file = new File("src/test/resources/log4j1-1.2.17/input/filter1.properties"); - assertTrue(file.exists()); - try (final FileInputStream inputStream = new FileInputStream(file)) { - OptionConverter.selectAndConfigure(inputStream, null, LogManager.getLoggerRepository()); - } - new PropertyConfiguratorTest().validateNested(); - } - - public void toLevelTest1() { - final String val = "INFO"; - final Level p = OptionConverter.toLevel(val, null); - assertEquals(p, Level.INFO); - } - - public void toLevelTest2() { - final String val = "INFO#org.apache.log4j.xml.XLevel"; - final Level p = OptionConverter.toLevel(val, null); - assertEquals(p, Level.INFO); - } - - public void toLevelTest3() { - final String val = "TRACE#org.apache.log4j.xml.XLevel"; - final Level p = OptionConverter.toLevel(val, null); - assertEquals(p, XLevel.TRACE); - } - - public void toLevelTest4() { - final String val = "TR#org.apache.log4j.xml.XLevel"; - final Level p = OptionConverter.toLevel(val, null); - assertEquals(p, null); - } - - public void toLevelTest5() { - final String val = "INFO#org.apache.log4j.xml.TOTO"; - final Level p = OptionConverter.toLevel(val, null); - assertEquals(p, null); - } - - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(new OptionConverterTestCase("varSubstTest5")); - suite.addTest(new OptionConverterTestCase("varSubstTest1")); - suite.addTest(new OptionConverterTestCase("varSubstTest2")); - suite.addTest(new OptionConverterTestCase("varSubstTest3")); - suite.addTest(new OptionConverterTestCase("varSubstTest4")); - - suite.addTest(new OptionConverterTestCase("testInputStream")); - - suite.addTest(new OptionConverterTestCase("toLevelTest1")); - suite.addTest(new OptionConverterTestCase("toLevelTest2")); - suite.addTest(new OptionConverterTestCase("toLevelTest3")); - suite.addTest(new OptionConverterTestCase("toLevelTest4")); - suite.addTest(new OptionConverterTestCase("toLevelTest5")); - return suite; - } -} diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/PatternParserTestCase.java b/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/PatternParserTestCase.java deleted file mode 100644 index 83587139e3b..00000000000 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/helpers/PatternParserTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.log4j.helpers; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.log4j.Appender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.util.Compare; -import org.junit.Ignore; - -/** - * Test case for helpers/PatternParser.java. Tests the various conversion patterns supported by PatternParser. This test - * class tests PatternParser via the PatternLayout class which uses it. - */ -@Ignore("WIP") -public class PatternParserTestCase extends TestCase { - - static String OUTPUT_FILE = "target/PatternParser"; - static String WITNESS_FILE = "target/witness/PatternParser"; - - static String msgPattern = "%m%n"; - - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(new PatternParserTestCase("mdcPattern")); - return suite; - } - - Logger root; - - Logger logger; - - public PatternParserTestCase(final String name) { - super(name); - } - - /** - * Test case for MDC conversion pattern. - */ - public void mdcPattern() throws Exception { - - final String mdcMsgPattern1 = "%m : %X%n"; - final String mdcMsgPattern2 = "%m : %X{key1}%n"; - final String mdcMsgPattern3 = "%m : %X{key2}%n"; - final String mdcMsgPattern4 = "%m : %X{key3}%n"; - final String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n"; - - // set up appender - final PatternLayout layout = new PatternLayout(msgPattern); - final Appender appender = new FileAppender(layout, OUTPUT_FILE + "_mdc", false); - - // set appender on root and set level to debug - root.addAppender(appender); - root.setLevel(Level.DEBUG); - - // output starting message - root.debug("starting mdc pattern test"); - - layout.setConversionPattern(mdcMsgPattern1); - root.debug("empty mdc, no key specified in pattern"); - - layout.setConversionPattern(mdcMsgPattern2); - root.debug("empty mdc, key1 in pattern"); - - layout.setConversionPattern(mdcMsgPattern3); - root.debug("empty mdc, key2 in pattern"); - - layout.setConversionPattern(mdcMsgPattern4); - root.debug("empty mdc, key3 in pattern"); - - layout.setConversionPattern(mdcMsgPattern5); - root.debug("empty mdc, key1, key2, and key3 in pattern"); - - MDC.put("key1", "value1"); - MDC.put("key2", "value2"); - - layout.setConversionPattern(mdcMsgPattern1); - root.debug("filled mdc, no key specified in pattern"); - - layout.setConversionPattern(mdcMsgPattern2); - root.debug("filled mdc, key1 in pattern"); - - layout.setConversionPattern(mdcMsgPattern3); - root.debug("filled mdc, key2 in pattern"); - - layout.setConversionPattern(mdcMsgPattern4); - root.debug("filled mdc, key3 in pattern"); - - layout.setConversionPattern(mdcMsgPattern5); - root.debug("filled mdc, key1, key2, and key3 in pattern"); - - MDC.remove("key1"); - MDC.remove("key2"); - - layout.setConversionPattern(msgPattern); - root.debug("finished mdc pattern test"); - - assertTrue(Compare.compare(OUTPUT_FILE + "_mdc", WITNESS_FILE + "_mdc")); - } - - public void setUp() { - root = Logger.getRootLogger(); - root.removeAllAppenders(); - } - - public void tearDown() { - root.getLoggerRepository().resetConfiguration(); - } -} diff --git a/log4j-1.2-api/src/test/resources/log4j1-1.2.17/input/defaultInit3.properties b/log4j-1.2-api/src/test/resources/log4j1-1.2.17/input/defaultInit3.properties deleted file mode 100644 index d9191bea106..00000000000 --- a/log4j-1.2-api/src/test/resources/log4j1-1.2.17/input/defaultInit3.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# 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. -# - -log4j.rootCategory=DEBUG, D3 -log4j.appender.D3=org.apache.log4j.FileAppender -log4j.appender.D3.File=output/temp -log4j.appender.D3.Append=false -log4j.appender.D3.layout=org.apache.log4j.PatternLayout -log4j.appender.D3.layout.ConversionPattern=%d [%t] %-5p %.16c - %m%n diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/status/StatusLoggerSerializationTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/status/StatusLoggerSerializationTest.java deleted file mode 100644 index d6e050d408a..00000000000 --- a/log4j-api-test/src/test/java/org/apache/logging/log4j/status/StatusLoggerSerializationTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.status; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; -import org.apache.logging.log4j.test.AbstractSerializationTest; -import org.junit.Ignore; -import org.junit.runners.Parameterized.Parameters; - -@Ignore -public class StatusLoggerSerializationTest extends AbstractSerializationTest { - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] {{StatusLogger.getLogger()}}); - } - - public StatusLoggerSerializationTest(final Serializable serializable) { - super(serializable); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderRolloverTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderRolloverTest.java deleted file mode 100644 index 741ca37cdae..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppenderRolloverTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.test.CoreLoggerContexts; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -public class RollingRandomAccessFileAppenderRolloverTest { - - @BeforeClass - public static void beforeClass() { - System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "RollingRandomAccessFileAppenderTest.xml"); - } - - @Test - @Ignore - public void testRollover() throws Exception { - final File file = new File("target", "RollingRandomAccessFileAppenderTest.log"); - // System.out.println(f.getAbsolutePath()); - final File after1 = new File("target", "afterRollover-1.log"); - file.delete(); - after1.delete(); - - final Logger log = LogManager.getLogger("com.foo.Bar"); - final String msg = "First a short message that does not trigger rollover"; - log.info(msg); - Thread.sleep(50); - - BufferedReader reader = new BufferedReader(new FileReader(file)); - final String line1 = reader.readLine(); - assertTrue(line1.contains(msg)); - reader.close(); - - assertFalse("afterRollover-1.log not created yet", after1.exists()); - - String exceed = "Long message that exceeds rollover size... "; - final char[] padding = new char[250]; - Arrays.fill(padding, 'X'); - exceed += new String(padding); - log.warn(exceed); - assertFalse("exceeded size but afterRollover-1.log not created yet", after1.exists()); - - final String trigger = "This message triggers rollover."; - log.warn(trigger); - Thread.sleep(100); - log.warn(trigger); - - CoreLoggerContexts.stopLoggerContext(); // stop async thread - CoreLoggerContexts.stopLoggerContext(false); // stop async thread - - final int MAX_ATTEMPTS = 50; - int count = 0; - while (!after1.exists() && count++ < MAX_ATTEMPTS) { - Thread.sleep(50); - } - - assertTrue("afterRollover-1.log created", after1.exists()); - - reader = new BufferedReader(new FileReader(file)); - final String new1 = reader.readLine(); - assertTrue("after rollover only new msg", new1.contains(trigger)); - assertNull("No more lines", reader.readLine()); - reader.close(); - file.delete(); - - reader = new BufferedReader(new FileReader(after1)); - final String old1 = reader.readLine(); - assertTrue("renamed file line 1", old1.contains(msg)); - final String old2 = reader.readLine(); - assertTrue("renamed file line 2", old2.contains(exceed)); - String line = reader.readLine(); - if (line != null) { - assertTrue("strange...", line.contains("This message triggers rollover.")); - line = reader.readLine(); - } - assertNull("No more lines", line); - reader.close(); - after1.delete(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java deleted file mode 100644 index 070debf51c1..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import javax.xml.XMLConstants; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.config.Configurator; -import org.apache.logging.log4j.core.test.categories.Layouts; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.xml.sax.SAXException; - -/** - * Tests XML validation for a "compact" XML file, no extra spaces or end of lines. - */ -@Ignore -@Category(Layouts.Xml.class) -public class XmlCompactFileAppenderValidationTest { - - private LoggerContext loggerContext; - - @Before - public void before() { - this.loggerContext = Configurator.initialize( - XmlCompactFileAppenderValidationTest.class.getName(), - "target/test-classes/XmlCompactFileAppenderValidationTest.xml"); - } - - @After - public void after() { - // Just in case, an @Test blew up - Configurator.shutdown(this.loggerContext); - } - - @Test - public void validateXmlSchemaThrowable() throws Exception { - final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml"); - file.delete(); - final Logger log = LogManager.getLogger("com.foo.Bar"); - try { - throw new IllegalArgumentException("IAE"); - } catch (final IllegalArgumentException e) { - log.warn("Message 1", e); - } - Configurator.shutdown(this.loggerContext); - this.validateXmlSchema(file); - } - - @Test - public void validateXmlSchema() throws Exception { - final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml"); - file.delete(); - final Logger log = LogManager.getLogger("com.foo.Bar"); - log.warn("Message 1"); - log.info("Message 2"); - log.debug("Message 3"); - Configurator.shutdown(this.loggerContext); - this.validateXmlSchema(file); - } - - @Test - public void validateXmlNoEvents() throws Exception { - final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml"); - file.delete(); - Configurator.shutdown(this.loggerContext); - this.validateXmlSchema(file); - } - - private void validateXmlSchema(final File file) throws SAXException, IOException { - final URL schemaFile = this.getClass().getClassLoader().getResource("Log4j-events.xsd"); - final Source xmlFile = new StreamSource(file); - final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - final Schema schema = schemaFactory.newSchema(schemaFile); - final Validator validator = schema.newValidator(); - validator.validate(xmlFile); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAsyncAppenderValidationTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAsyncAppenderValidationTest.java deleted file mode 100644 index 290b6af6a0f..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAsyncAppenderValidationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import javax.xml.XMLConstants; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.test.CoreLoggerContexts; -import org.apache.logging.log4j.core.test.categories.Layouts; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.xml.sax.SAXException; - -/** - * Tests XML validation for a "compact" XML file, no extra spaces or end of lines. - */ -@Ignore -@Category(Layouts.Xml.class) -public class XmlCompactFileAsyncAppenderValidationTest { - - @BeforeClass - public static void beforeClass() { - System.setProperty( - ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "XmlCompactFileAsyncAppenderValidationTest.xml"); - } - - @Test - public void validateXmlSchemaSimple() throws Exception { - final File file = new File("target", "XmlCompactFileAsyncAppenderValidationTest.log.xml"); - file.delete(); - final Logger log = LogManager.getLogger("com.foo.Bar"); - log.warn("Message 1"); - log.info("Message 2"); - log.debug("Message 3"); - CoreLoggerContexts.stopLoggerContext(file); // stop async thread - this.validateXmlSchema(file); - } - - @Test - public void validateXmlSchemaNoEvents() throws Exception { - final File file = new File("target", "XmlCompactFileAsyncAppenderValidationTest.log.xml"); - file.delete(); - CoreLoggerContexts.stopLoggerContext(file); // stop async thread - this.validateXmlSchema(file); - } - - private void validateXmlSchema(final File file) throws SAXException, IOException { - final URL schemaFile = this.getClass().getClassLoader().getResource("Log4j-events.xsd"); - final Source xmlFile = new StreamSource(file); - final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - final Schema schema = schemaFactory.newSchema(schemaFile); - final Validator validator = schema.newValidator(); - validator.validate(xmlFile); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java deleted file mode 100644 index 6c0e82bd05e..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlRandomAccessFileAppenderTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.test.CoreLoggerContexts; -import org.apache.logging.log4j.core.test.categories.Layouts; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -/** - * Tests a "complete" XML file a.k.a. a well-formed XML file. - */ -@Category(Layouts.Xml.class) -public class XmlRandomAccessFileAppenderTest { - - @BeforeClass - public static void beforeClass() { - System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "XmlRandomAccessFileAppenderTest.xml"); - } - - @Test - @Ignore - public void testFlushAtEndOfBatch() throws Exception { - final File file = new File("target", "XmlRandomAccessFileAppenderTest.log"); - // System.out.println(f.getAbsolutePath()); - file.delete(); - final Logger log = LogManager.getLogger("com.foo.Bar"); - final String logMsg = "Message flushed with immediate flush=false"; - log.info(logMsg); - CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread - - String line1; - String line2; - String line3; - String line4; - try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { - line1 = reader.readLine(); - line2 = reader.readLine(); - line3 = reader.readLine(); - line4 = reader.readLine(); - } finally { - file.delete(); - } - assertNotNull("line1", line1); - final String msg1 = ""; - assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + ']', line1.equals(msg1)); - - assertNotNull("line2", line2); - final String msg2 = ""; - assertTrue("line2 incorrect: [" + line2 + "], does not contain: [" + msg2 + ']', line2.equals(msg2)); - - assertNotNull("line3", line3); - final String msg3 = " 0); - final File[] files = dir.listFiles(); - assertNotNull(files); - for (final File file : files) { - assertHeader(file); - assertFooter(file); - } - final File logFile = new File(LOGFILE); - assertTrue("Expected logfile to exist: " + LOGFILE, logFile.exists()); - assertHeader(logFile); - } - - private void assertHeader(final File file) throws Exception { - final HtmlLayout layout = HtmlLayout.createDefaultLayout(); - final String header = new String(layout.getHeader(), Charset.defaultCharset()); - final String withoutTimestamp = header.substring(0, 435); - final String contents = new String(slurp(file), Charset.defaultCharset()); - final String contentsInitialChunk = contents.substring(0, 435); - assertEquals(file.getName(), withoutTimestamp, contentsInitialChunk); - } - - private void assertFooter(final File file) throws Exception { - final HtmlLayout layout = HtmlLayout.createDefaultLayout(); - final String footer = new String(layout.getFooter(), Charset.defaultCharset()); - final String contents = new String(slurp(file), Charset.defaultCharset()); - assertTrue(file.getName(), contents.endsWith(footer)); - } - - private byte[] slurp(final File file) throws Exception { - FileInputStream in = null; - try { - in = new FileInputStream(file); - final byte[] result = new byte[(int) file.length()]; - int pos = 0; - int length = in.read(result); - while (length > 0) { - pos += length; - length = in.read(result, pos, result.length - pos); - } - return result; - } finally { - Closer.closeSilently(in); - } - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnError.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerArgumentFreedOnErrorTest.java similarity index 98% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnError.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerArgumentFreedOnErrorTest.java index c8eb51ec638..cd0b998c921 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnError.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerArgumentFreedOnErrorTest.java @@ -33,7 +33,7 @@ import org.junit.experimental.categories.Category; @Category(AsyncLoggers.class) -public class AsyncLoggerTestArgumentFreedOnError { +public class AsyncLoggerArgumentFreedOnErrorTest { @BeforeClass public static void beforeClass() { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java deleted file mode 100644 index 7fd51ee7ca3..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.async; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.impl.Log4jLogEvent; -import org.apache.logging.log4j.core.test.categories.AsyncLoggers; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.message.ParameterizedMessage; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Category(AsyncLoggers.class) -public class AsyncLoggerConfigTest3 { - - @Test - public void testNoConcurrentModificationException() throws Exception { - System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerConfigTest2.xml"); - final File file = new File("target", "AsyncLoggerConfigTest2.log"); - assertTrue("Deleted old file before test", !file.exists() || file.delete()); - - final Logger log = LogManager.getLogger("com.foo.Bar"); - log.info("initial message"); - Thread.sleep(500); - - final Map map = new HashMap<>(); - for (int j = 0; j < 3000; j++) { - map.put(String.valueOf(j), String.valueOf(System.nanoTime())); - } - - final Message msg = new ParameterizedMessage("{}", map); - final Log4jLogEvent event = Log4jLogEvent.newBuilder() - .setLevel(Level.WARN) - .setLoggerName(getClass().getName()) - .setMessage(msg) - .setTimeMillis(0) - .build(); - - for (int i = 0; i < 100; i++) { - ((AsyncLoggerConfig) ((org.apache.logging.log4j.core.Logger) log).get()).callAppenders(event); - for (int j = 0; j < 3000; j++) { - map.remove(String.valueOf(j)); - } - for (int j = 0; j < 3000; j++) { - map.put(String.valueOf(j), String.valueOf(System.nanoTime())); - } - } - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest4.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest4.java deleted file mode 100644 index 09ebf67eb80..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest4.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.async; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.test.CoreLoggerContexts; -import org.apache.logging.log4j.core.test.categories.AsyncLoggers; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Category(AsyncLoggers.class) -public class AsyncLoggerConfigTest4 { - - @BeforeClass - public static void beforeClass() { - System.setProperty("log4j2.is.webapp", "false"); - System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerConfigTest4.xml"); - } - - @AfterClass - public static void afterClass() { - System.clearProperty("log4j2.is.webapp"); - } - - @Test - public void testParameters() throws Exception { - final File file = new File("target", "AsyncLoggerConfigTest4.log"); - assertTrue("Deleted old file before test", !file.exists() || file.delete()); - - final Logger log = LogManager.getLogger("com.foo.Bar"); - log.info("Additive logging: {} for the price of {}!", 2, 1); - CoreLoggerContexts.stopLoggerContext(file); // stop async thread - - final BufferedReader reader = new BufferedReader(new FileReader(file)); - final String line1 = reader.readLine(); - final String line2 = reader.readLine(); - final String line3 = reader.readLine(); - final String line4 = reader.readLine(); - final String line5 = reader.readLine(); - reader.close(); - file.delete(); - - assertThat( - line1, - containsString( - "Additive logging: {} for the price of {}! [2,1] Additive logging: 2 for the price of 1!")); - assertThat( - line2, - containsString( - "Additive logging: {} for the price of {}! [2,1] Additive logging: 2 for the price of 1!")); - assertThat( - line3, - containsString( - "Additive logging: {} for the price of {}! [2,1] Additive logging: 2 for the price of 1!")); - assertThat( - line4, - containsString( - "Additive logging: {} for the price of {}! [2,1] Additive logging: 2 for the price of 1!")); - assertNull("Expected only two lines to be logged", line5); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java similarity index 99% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java index a27ea86a28d..617090804e9 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java @@ -38,7 +38,7 @@ import org.junit.experimental.categories.Category; @Category(AsyncLoggers.class) -public class AsyncLoggerTestNanoTime { +public class AsyncLoggerNanoTimeTest { @BeforeClass public static void beforeClass() { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest2.java deleted file mode 100644 index d3886818c8f..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest2.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.test.junit.SetTestProperty; - -/** - * Needs to be a separate class since {@link org.apache.logging.log4j.core.util.Constants#FORMAT_MESSAGES_IN_BACKGROUND} - * is immutable. - */ -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -public class QueueFullAsyncAppenderTest2 extends QueueFullAsyncAppenderTest { - - @Override - protected void checkConfig(final LoggerContext ctx) { - super.checkConfig(ctx); - assertFormatMessagesInBackground(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java deleted file mode 100644 index 54e5a78a97f..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.test.junit.Tags; -import org.apache.logging.log4j.test.junit.SetTestProperty; -import org.junit.jupiter.api.Tag; - -/** - * Tests queue full scenarios with AsyncLoggers in configuration. - */ -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -@Tag(Tags.ASYNC_LOGGERS) -public class QueueFullAsyncLoggerConfigLoggingFromToStringTest2 - extends QueueFullAsyncLoggerConfigLoggingFromToStringTest { - - @Override - protected void checkConfig(final LoggerContext ctx) throws ReflectiveOperationException { - super.checkConfig(ctx); - assertFormatMessagesInBackground(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java deleted file mode 100644 index 4c56595a405..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.test.junit.Tags; -import org.apache.logging.log4j.test.junit.SetTestProperty; -import org.junit.jupiter.api.Tag; - -/** - * Tests queue full scenarios with AsyncLoggers in configuration. - */ -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -@Tag(Tags.ASYNC_LOGGERS) -public class QueueFullAsyncLoggerConfigTest2 extends QueueFullAsyncLoggerConfigTest { - - @Override - protected void checkConfig(final LoggerContext ctx) throws ReflectiveOperationException { - super.checkConfig(ctx); - assertFormatMessagesInBackground(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest2.java deleted file mode 100644 index a75977e2f31..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest2.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.test.junit.Tags; -import org.apache.logging.log4j.test.junit.SetTestProperty; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; - -/** - * Tests queue full scenarios with pure AsyncLoggers (all loggers async). - */ -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -@Tag(Tags.ASYNC_LOGGERS) -public class QueueFullAsyncLoggerLoggingFromToStringTest2 extends QueueFullAsyncLoggerLoggingFromToStringTest { - - @Override - @Disabled("Causes deadlocks") - public void testLoggingFromToStringCausesOutOfOrderMessages(LoggerContext ctx, BlockingAppender blockingAppender) - throws Exception { - super.testLoggingFromToStringCausesOutOfOrderMessages(ctx, blockingAppender); - } - - @Override - protected void checkConfig(final LoggerContext ctx) { - super.checkConfig(ctx); - assertFormatMessagesInBackground(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java deleted file mode 100644 index 6271849278f..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.test.junit.Tags; -import org.apache.logging.log4j.test.junit.SetTestProperty; -import org.junit.jupiter.api.Tag; - -/** - * Needs to be a separate class since {@link org.apache.logging.log4j.core.util.Constants#FORMAT_MESSAGES_IN_BACKGROUND} - * is immutable. - */ -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -@Tag(Tags.ASYNC_LOGGERS) -public class QueueFullAsyncLoggerTest2 extends QueueFullAsyncLoggerTest { - - @Override - protected void checkConfig(final LoggerContext ctx) { - super.checkConfig(ctx); - assertFormatMessagesInBackground(); - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java deleted file mode 100644 index 7a048091d26..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.async; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.CountDownLatch; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.GarbageCollectionHelper; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.test.junit.LoggerContextSource; -import org.apache.logging.log4j.core.test.junit.Named; -import org.apache.logging.log4j.core.test.junit.Tags; -import org.apache.logging.log4j.core.util.Constants; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.test.junit.SetTestProperty; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; - -/** - * Tests queue full scenarios with pure AsyncLoggers (all loggers async). - */ -@SetTestProperty( - key = Constants.LOG4J_CONTEXT_SELECTOR, - value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector") -@SetTestProperty(key = "log4j2.asyncLoggerRingBufferSize", value = "128") -@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true") -@SetTestProperty(key = "log4j2.asyncQueueFullPolicy", value = "Discard") -@Tag(Tags.ASYNC_LOGGERS) -public class QueueFullAsyncLoggerTest3 extends QueueFullAbstractTest { - - @Override - protected void checkConfig(final LoggerContext ctx) { - assertAsyncLogger(ctx, 128); - assertFormatMessagesInBackground(); - assertThat(AsyncQueueFullPolicyFactory.create()).isInstanceOf(DiscardingAsyncQueueFullPolicy.class); - } - - @Test - @Timeout(value = 15, unit = SECONDS) - @LoggerContextSource - public void discardedMessagesShouldBeGarbageCollected( - final LoggerContext ctx, final @Named(APPENDER_NAME) BlockingAppender blockingAppender) - throws InterruptedException { - checkConfig(ctx); - final Logger logger = ctx.getLogger(getClass()); - - blockingAppender.logEvents = null; - blockingAppender.countDownLatch = new CountDownLatch(1); - final int count = 200; - final CountDownLatch garbageCollectionLatch = new CountDownLatch(count); - for (int i = 0; i < count; i++) { - logger.info(new CountdownOnGarbageCollectMessage(garbageCollectionLatch)); - } - blockingAppender.countDownLatch.countDown(); - - final GarbageCollectionHelper gcHelper = new GarbageCollectionHelper(); - gcHelper.run(); - try { - assertTrue("Parameter should have been garbage collected", garbageCollectionLatch.await(30, SECONDS)); - } finally { - gcHelper.close(); - } - } - - private static final class CountdownOnGarbageCollectMessage implements Message { - - private final CountDownLatch latch; - - CountdownOnGarbageCollectMessage(final CountDownLatch latch) { - this.latch = latch; - } - - @Override - public String getFormattedMessage() { - return "formatted"; - } - - @Override - public String getFormat() { - return null; - } - - @Override - public Object[] getParameters() { - return org.apache.logging.log4j.util.Constants.EMPTY_OBJECT_ARRAY; - } - - @Override - public Throwable getThrowable() { - return null; - } - - @Override - protected void finalize() throws Throwable { - latch.countDown(); - super.finalize(); - } - } -} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator1Test.java similarity index 99% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator1Test.java index 91b6af950d5..be2c6fd1993 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator1Test.java @@ -66,7 +66,7 @@ @SetSystemProperty(key = Constants.SCRIPT_LANGUAGES, value = "beanshell, Groovy, Javascript") @Tag("functional") -public class TestConfigurator { +public class Configurator1Test { private static final String CONFIG_NAME = "TestConfigurator"; diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator2Test.java similarity index 99% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator2Test.java index 39fd82c8908..d1459aea782 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/Configurator2Test.java @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test; @Tag("functional") -public class ConfiguratorTest { +public class Configurator2Test { @Test public void testInitializeFromAbsoluteFilePath() { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorErrorTest.java similarity index 92% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorErrorTest.java index 0ea37226944..a558e4992dc 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestConfiguratorError.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorErrorTest.java @@ -26,21 +26,21 @@ import org.junit.jupiter.api.parallel.ResourceLock; @ResourceLock("log4j2.LoggerContextFactory") -public class TestConfiguratorError { +public class ConfiguratorErrorTest { @RegisterExtension static final LoggerContextFactoryExtension EXTENSION = new LoggerContextFactoryExtension(SimpleLoggerContextFactory.INSTANCE); @Test - public void testErrorNoClassLoader() throws Exception { + public void testErrorNoClassLoader() { try (final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-config.xml")) { assertNull(ctx, "No LoggerContext should have been returned"); } } @Test - public void testErrorNullClassLoader() throws Exception { + public void testErrorNullClassLoader() { try (final LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-config.xml")) { assertNull(ctx, "No LoggerContext should have been returned"); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestMissingLanguage.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/MissingLanguageTest.java similarity index 98% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestMissingLanguage.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/MissingLanguageTest.java index 7525007b84a..9018c42acb0 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestMissingLanguage.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/MissingLanguageTest.java @@ -34,7 +34,7 @@ @SetSystemProperty(key = Constants.SCRIPT_LANGUAGES, value = "beanshell, Javascript") @Tag("functional") -public class TestMissingLanguage { +public class MissingLanguageTest { private LoggerContext ctx = null; @@ -48,7 +48,7 @@ public void cleanup() { } @org.junit.jupiter.api.Test - public void testBuilderWithScripts() throws Exception { + public void testBuilderWithScripts() { final String script = "if (logEvent.getLoggerName().equals(\"NoLocation\")) {\n" + " return \"NoLocation\";\n" + " } else if (logEvent.getMarker() != null && logEvent.getMarker().isInstanceOf(\"FLOW\")) {\n" diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestNoLanguages.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NoLanguagesTest.java similarity index 97% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestNoLanguages.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NoLanguagesTest.java index e111df8e3f7..b7bf58961e1 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/TestNoLanguages.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NoLanguagesTest.java @@ -28,9 +28,10 @@ import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; @Tag("functional") -public class TestNoLanguages { +public class NoLanguagesTest { private LoggerContext ctx = null; @@ -43,8 +44,8 @@ public void cleanup() { } } - @org.junit.jupiter.api.Test - public void testBuilderWithScripts() throws Exception { + @Test + public void testBuilderWithScripts() { final String script = "if (logEvent.getLoggerName().equals(\"NoLocation\")) {\n" + " return \"NoLocation\";\n" + " } else if (logEvent.getMarker() != null && logEvent.getMarker().isInstanceOf(\"FLOW\")) {\n" diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest2.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest2.java deleted file mode 100644 index 29bcb4ca043..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest2.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.pattern; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import org.junit.jupiter.api.Test; - -public class PatternParserTest2 { - - @Test - public void testParseConvertBackslashes() { - final boolean convert = true; - final StringBuilder buf = new StringBuilder(); - final String pattern = "%d{HH-mm-ss} \\t ..."; - - final Calendar cal = Calendar.getInstance(); - cal.set(Calendar.HOUR_OF_DAY, 23); - cal.set(Calendar.MINUTE, 53); - cal.set(Calendar.SECOND, 01); - parse(pattern, convert, buf, cal.getTime(), 123); - - assertEquals("23-53-01 \t ...", buf.toString()); - } - - @Test - public void testParseDontConvertBackslashes() { - final boolean convert = false; - final StringBuilder buf = new StringBuilder(); - final String pattern = "%d{HH-mm-ss} \\t---"; - - final Calendar cal = Calendar.getInstance(); - cal.set(Calendar.HOUR_OF_DAY, 13); - cal.set(Calendar.MINUTE, 24); - cal.set(Calendar.SECOND, 59); - parse(pattern, convert, buf, cal.getTime(), 3); - - assertEquals("13-24-59 \\t---", buf.toString()); - } - - private void parse( - final String pattern, final boolean convert, final StringBuilder buf, final Date date, final int i) { - final PatternParser parser0 = new PatternParser(null, "Converter", null); - final List converters = new ArrayList<>(); - final List fields = new ArrayList<>(); - parser0.parse(pattern, converters, fields, false, false, convert); - final FormattingInfo[] patternFields = fields.toArray(FormattingInfo.EMPTY_ARRAY); - final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()]; - final ArrayPatternConverter[] patternConverters = converters.toArray(converterArray); - formatFileName(patternConverters, patternFields, buf, date, i); - } - - /** - * Format file name. - * - * @param buf string buffer to which formatted file name is appended, may not be null. - * @param objects objects to be evaluated in formatting, may not be null. - */ - protected final void formatFileName( - final ArrayPatternConverter[] patternConverters, - final FormattingInfo[] patternFields, - final StringBuilder buf, - final Object... objects) { - for (int i = 0; i < patternConverters.length; i++) { - final int fieldStart = buf.length(); - patternConverters[i].format(buf, objects); - - if (patternFields[i] != null) { - patternFields[i].format(fieldStart, buf); - } - } - } -} diff --git a/log4j-core-test/src/test/resources/XmlCompactFileAppenderValidationTest.xml b/log4j-core-test/src/test/resources/XmlCompactFileAppenderValidationTest.xml deleted file mode 100644 index 059c54c154c..00000000000 --- a/log4j-core-test/src/test/resources/XmlCompactFileAppenderValidationTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/log4j-core-test/src/test/resources/XmlCompactFileAsyncAppenderValidationTest.xml b/log4j-core-test/src/test/resources/XmlCompactFileAsyncAppenderValidationTest.xml deleted file mode 100644 index 3bf389e4b35..00000000000 --- a/log4j-core-test/src/test/resources/XmlCompactFileAsyncAppenderValidationTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/log4j-core-test/src/test/resources/XmlRandomAccessFileAppenderTest.xml b/log4j-core-test/src/test/resources/XmlRandomAccessFileAppenderTest.xml deleted file mode 100644 index c687144c5dd..00000000000 --- a/log4j-core-test/src/test/resources/XmlRandomAccessFileAppenderTest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - -