http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java index d279660..48d2a10 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java @@ -1,97 +1,97 @@ -/* - * 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.action; - -import java.nio.file.attribute.FileTime; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the FileAgeFilter class. - */ -public class IfLastModifiedTest { - - @Test - public void testGetDurationReturnsConstructorValue() { - IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("P7D")); - assertEquals(0, filter.getAge().compareTo(Duration.parse("P7D"))); - } - - @Test - public void testAcceptsIfFileAgeEqualToDuration() { - IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); - DummyFileAttributes attrs = new DummyFileAttributes(); - final long age = 33 * 1000; - attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); - assertTrue(filter.accept(null, null, attrs)); - } - - @Test - public void testAcceptsIfFileAgeExceedsDuration() { - IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); - DummyFileAttributes attrs = new DummyFileAttributes(); - final long age = 33 * 1000 + 5; - attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); - assertTrue(filter.accept(null, null, attrs)); - } - - @Test - public void testDoesNotAcceptIfFileAgeLessThanDuration() { - IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); - DummyFileAttributes attrs = new DummyFileAttributes(); - final long age = 33 * 1000 - 5; - attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); - assertFalse(filter.accept(null, null, attrs)); - } - - @Test - public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { - final CountingCondition counter = new CountingCondition(true); - IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter); - DummyFileAttributes attrs = new DummyFileAttributes(); - final long oldEnough = 33 * 1000 + 5; - attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - oldEnough); - - assertTrue(filter.accept(null, null, attrs)); - assertEquals(1, counter.getAcceptCount()); - assertTrue(filter.accept(null, null, attrs)); - assertEquals(2, counter.getAcceptCount()); - assertTrue(filter.accept(null, null, attrs)); - assertEquals(3, counter.getAcceptCount()); - - final long tooYoung = 33 * 1000 - 5; - attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - tooYoung); - assertFalse(filter.accept(null, null, attrs)); - assertEquals(3, counter.getAcceptCount()); // no increase - assertFalse(filter.accept(null, null, attrs)); - assertEquals(3, counter.getAcceptCount()); - assertFalse(filter.accept(null, null, attrs)); - assertEquals(3, counter.getAcceptCount()); - } - - @Test - public void testBeforeTreeWalk() { - final CountingCondition counter = new CountingCondition(true); - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter, counter, - counter); - filter.beforeFileTreeWalk(); - assertEquals(3, counter.getBeforeFileTreeWalkCount()); - } -} +/* + * 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.action; + +import java.nio.file.attribute.FileTime; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the FileAgeFilter class. + */ +public class IfLastModifiedTest { + + @Test + public void testGetDurationReturnsConstructorValue() { + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("P7D")); + assertEquals(0, filter.getAge().compareTo(Duration.parse("P7D"))); + } + + @Test + public void testAcceptsIfFileAgeEqualToDuration() { + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final DummyFileAttributes attrs = new DummyFileAttributes(); + final long age = 33 * 1000; + attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); + assertTrue(filter.accept(null, null, attrs)); + } + + @Test + public void testAcceptsIfFileAgeExceedsDuration() { + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final DummyFileAttributes attrs = new DummyFileAttributes(); + final long age = 33 * 1000 + 5; + attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); + assertTrue(filter.accept(null, null, attrs)); + } + + @Test + public void testDoesNotAcceptIfFileAgeLessThanDuration() { + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final DummyFileAttributes attrs = new DummyFileAttributes(); + final long age = 33 * 1000 - 5; + attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); + assertFalse(filter.accept(null, null, attrs)); + } + + @Test + public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { + final CountingCondition counter = new CountingCondition(true); + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter); + final DummyFileAttributes attrs = new DummyFileAttributes(); + final long oldEnough = 33 * 1000 + 5; + attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - oldEnough); + + assertTrue(filter.accept(null, null, attrs)); + assertEquals(1, counter.getAcceptCount()); + assertTrue(filter.accept(null, null, attrs)); + assertEquals(2, counter.getAcceptCount()); + assertTrue(filter.accept(null, null, attrs)); + assertEquals(3, counter.getAcceptCount()); + + final long tooYoung = 33 * 1000 - 5; + attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - tooYoung); + assertFalse(filter.accept(null, null, attrs)); + assertEquals(3, counter.getAcceptCount()); // no increase + assertFalse(filter.accept(null, null, attrs)); + assertEquals(3, counter.getAcceptCount()); + assertFalse(filter.accept(null, null, attrs)); + assertEquals(3, counter.getAcceptCount()); + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter, counter, + counter); + filter.beforeFileTreeWalk(); + assertEquals(3, counter.getBeforeFileTreeWalkCount()); + } +}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java index dcd5ffd..255fec4 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTimeTest.java @@ -42,11 +42,11 @@ public class PathSortByModificationTimeTest { @Test public void testCompareRecentFirst() { - PathSorter sorter = PathSortByModificationTime.createSorter(true); - Path p1 = Paths.get("aaa"); - Path p2 = Paths.get("bbb"); - DummyFileAttributes a1 = new DummyFileAttributes(); - DummyFileAttributes a2 = new DummyFileAttributes(); + final PathSorter sorter = PathSortByModificationTime.createSorter(true); + final Path p1 = Paths.get("aaa"); + final Path p2 = Paths.get("bbb"); + final DummyFileAttributes a1 = new DummyFileAttributes(); + final DummyFileAttributes a2 = new DummyFileAttributes(); a1.lastModified = FileTime.fromMillis(100); a2.lastModified = FileTime.fromMillis(222); @@ -65,11 +65,11 @@ public class PathSortByModificationTimeTest { @Test public void testCompareRecentLast() { - PathSorter sorter = PathSortByModificationTime.createSorter(false); - Path p1 = Paths.get("aaa"); - Path p2 = Paths.get("bbb"); - DummyFileAttributes a1 = new DummyFileAttributes(); - DummyFileAttributes a2 = new DummyFileAttributes(); + final PathSorter sorter = PathSortByModificationTime.createSorter(false); + final Path p1 = Paths.get("aaa"); + final Path p2 = Paths.get("bbb"); + final DummyFileAttributes a1 = new DummyFileAttributes(); + final DummyFileAttributes a2 = new DummyFileAttributes(); a1.lastModified = FileTime.fromMillis(100); a2.lastModified = FileTime.fromMillis(222); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java index aadfac9..b3198ba 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptConditionTest.java @@ -1,130 +1,130 @@ -/* - * 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.action; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.DefaultConfiguration; -import org.apache.logging.log4j.core.script.Script; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the ScriptCondition class. - */ -public class ScriptConditionTest { - - @Test(expected = NullPointerException.class) - public void testConstructorDisallowsNullScript() { - new ScriptCondition(null, new DefaultConfiguration()); - } - - @Test(expected = NullPointerException.class) - public void testConstructorDisallowsNullConfig() { - new ScriptCondition(new Script("test", "js", "print('hi')"), null); - } - - @Test - public void testCreateConditionReturnsNullForNullScript() { - assertNull(ScriptCondition.createCondition(null, new DefaultConfiguration())); - } - - @Test(expected = NullPointerException.class) - public void testCreateConditionDisallowsNullConfig() { - ScriptCondition.createCondition(new Script("test", "js", "print('hi')"), null); - } - - @Test - public void testSelectFilesToDelete() { - Configuration config = new DefaultConfiguration(); - config.initialize(); // creates the ScriptManager - - Script script = new Script("test", "javascript", "pathList;"); // script that returns pathList - ScriptCondition condition = new ScriptCondition(script, config); - List<PathWithAttributes> pathList = new ArrayList<>(); - Path base = Paths.get("baseDirectory"); - List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); - assertSame(result, pathList); - } - - @Test - public void testSelectFilesToDelete2() { - Configuration config = new DefaultConfiguration(); - config.initialize(); // creates the ScriptManager - - List<PathWithAttributes> pathList = new ArrayList<>(); - pathList.add(new PathWithAttributes(Paths.get("/path/1"), new DummyFileAttributes())); - pathList.add(new PathWithAttributes(Paths.get("/path/2"), new DummyFileAttributes())); - pathList.add(new PathWithAttributes(Paths.get("/path/3"), new DummyFileAttributes())); - - String scriptText = "pathList.remove(1);" // - + "pathList;"; - Script script = new Script("test", "javascript", scriptText); - ScriptCondition condition = new ScriptCondition(script, config); - Path base = Paths.get("baseDirectory"); - List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); - assertSame(result, pathList); - assertEquals(2, result.size()); - assertEquals(Paths.get("/path/1"), result.get(0).getPath()); - assertEquals(Paths.get("/path/3"), result.get(1).getPath()); - } - - @Test - public void testSelectFilesToDelete3() { - Configuration config = new DefaultConfiguration(); - config.initialize(); // creates the ScriptManager - - List<PathWithAttributes> pathList = new ArrayList<>(); - pathList.add(new PathWithAttributes(Paths.get("/path/1/abc/a.txt"), new DummyFileAttributes())); - pathList.add(new PathWithAttributes(Paths.get("/path/2/abc/bbb.txt"), new DummyFileAttributes())); - pathList.add(new PathWithAttributes(Paths.get("/path/3/abc/c.txt"), new DummyFileAttributes())); - - String scriptText = "" // - + "import java.nio.file.*;" // - + "def pattern = ~/(\\d*)[\\/\\\\]abc[\\/\\\\].*\\.txt/;" // - + "assert pattern.getClass() == java.util.regex.Pattern;" // - + "def copy = pathList.collect{it};" - + "pathList.each { pathWithAttribs -> \n" // - + " def relative = basePath.relativize pathWithAttribs.path;" // - + " println 'relative path: ' + relative;" // - + " def str = relative.toString();" - + " def m = pattern.matcher(str);" // - + " if (m.find()) {" // - + " def index = m.group(1) as int;" // - + " println 'extracted index: ' + index;" // - + " def isOdd = (index % 2) == 1;" - + " println 'is odd: ' + isOdd;" // - + " if (isOdd) { copy.remove pathWithAttribs}" - + " }" // - + "}" // - + "println copy;" - + "copy;"; - Script script = new Script("test", "groovy", scriptText); - ScriptCondition condition = new ScriptCondition(script, config); - Path base = Paths.get("/path"); - List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); - assertEquals(1, result.size()); - assertEquals(Paths.get("/path/2/abc/bbb.txt"), result.get(0).getPath()); - } - -} +/* + * 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.action; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.apache.logging.log4j.core.script.Script; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the ScriptCondition class. + */ +public class ScriptConditionTest { + + @Test(expected = NullPointerException.class) + public void testConstructorDisallowsNullScript() { + new ScriptCondition(null, new DefaultConfiguration()); + } + + @Test(expected = NullPointerException.class) + public void testConstructorDisallowsNullConfig() { + new ScriptCondition(new Script("test", "js", "print('hi')"), null); + } + + @Test + public void testCreateConditionReturnsNullForNullScript() { + assertNull(ScriptCondition.createCondition(null, new DefaultConfiguration())); + } + + @Test(expected = NullPointerException.class) + public void testCreateConditionDisallowsNullConfig() { + ScriptCondition.createCondition(new Script("test", "js", "print('hi')"), null); + } + + @Test + public void testSelectFilesToDelete() { + final Configuration config = new DefaultConfiguration(); + config.initialize(); // creates the ScriptManager + + final Script script = new Script("test", "javascript", "pathList;"); // script that returns pathList + final ScriptCondition condition = new ScriptCondition(script, config); + final List<PathWithAttributes> pathList = new ArrayList<>(); + final Path base = Paths.get("baseDirectory"); + final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); + assertSame(result, pathList); + } + + @Test + public void testSelectFilesToDelete2() { + final Configuration config = new DefaultConfiguration(); + config.initialize(); // creates the ScriptManager + + final List<PathWithAttributes> pathList = new ArrayList<>(); + pathList.add(new PathWithAttributes(Paths.get("/path/1"), new DummyFileAttributes())); + pathList.add(new PathWithAttributes(Paths.get("/path/2"), new DummyFileAttributes())); + pathList.add(new PathWithAttributes(Paths.get("/path/3"), new DummyFileAttributes())); + + final String scriptText = "pathList.remove(1);" // + + "pathList;"; + final Script script = new Script("test", "javascript", scriptText); + final ScriptCondition condition = new ScriptCondition(script, config); + final Path base = Paths.get("baseDirectory"); + final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); + assertSame(result, pathList); + assertEquals(2, result.size()); + assertEquals(Paths.get("/path/1"), result.get(0).getPath()); + assertEquals(Paths.get("/path/3"), result.get(1).getPath()); + } + + @Test + public void testSelectFilesToDelete3() { + final Configuration config = new DefaultConfiguration(); + config.initialize(); // creates the ScriptManager + + final List<PathWithAttributes> pathList = new ArrayList<>(); + pathList.add(new PathWithAttributes(Paths.get("/path/1/abc/a.txt"), new DummyFileAttributes())); + pathList.add(new PathWithAttributes(Paths.get("/path/2/abc/bbb.txt"), new DummyFileAttributes())); + pathList.add(new PathWithAttributes(Paths.get("/path/3/abc/c.txt"), new DummyFileAttributes())); + + final String scriptText = "" // + + "import java.nio.file.*;" // + + "def pattern = ~/(\\d*)[\\/\\\\]abc[\\/\\\\].*\\.txt/;" // + + "assert pattern.getClass() == java.util.regex.Pattern;" // + + "def copy = pathList.collect{it};" + + "pathList.each { pathWithAttribs -> \n" // + + " def relative = basePath.relativize pathWithAttribs.path;" // + + " println 'relative path: ' + relative;" // + + " def str = relative.toString();" + + " def m = pattern.matcher(str);" // + + " if (m.find()) {" // + + " def index = m.group(1) as int;" // + + " println 'extracted index: ' + index;" // + + " def isOdd = (index % 2) == 1;" + + " println 'is odd: ' + isOdd;" // + + " if (isOdd) { copy.remove pathWithAttribs}" + + " }" // + + "}" // + + "println copy;" + + "copy;"; + final Script script = new Script("test", "groovy", scriptText); + final ScriptCondition condition = new ScriptCondition(script, config); + final Path base = Paths.get("/path"); + final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); + assertEquals(1, result.size()); + assertEquals(Paths.get("/path/2/abc/bbb.txt"), result.get(0).getPath()); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java index f5eac73..dd32a0c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java @@ -1,94 +1,94 @@ -/* - * 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.action; - -import java.nio.file.FileVisitOption; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.FileTime; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the SortingVisitor class. - */ -public class SortingVisitorTest { - - private Path base; - private Path aaa; - private Path bbb; - private Path ccc; - - @Before - public void setUp() throws Exception { - base = Files.createTempDirectory("tempDir", new FileAttribute<?>[0]); - aaa = Files.createTempFile(base, "aaa", null, new FileAttribute<?>[0]); - bbb = Files.createTempFile(base, "bbb", null, new FileAttribute<?>[0]); - ccc = Files.createTempFile(base, "ccc", null, new FileAttribute<?>[0]); - - // lastModified granularity is 1 sec(!) on some file systems... - final long now = System.currentTimeMillis(); - Files.setLastModifiedTime(aaa, FileTime.fromMillis(now)); - Files.setLastModifiedTime(bbb, FileTime.fromMillis(now + 1000)); - Files.setLastModifiedTime(ccc, FileTime.fromMillis(now + 2000)); - } - - @After - public void tearDown() throws Exception { - Files.deleteIfExists(ccc); - Files.deleteIfExists(bbb); - Files.deleteIfExists(aaa); - Files.deleteIfExists(base); - } - - @Test - public void testRecentFirst() throws Exception { - SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(true)); - Set<FileVisitOption> options = Collections.emptySet(); - Files.walkFileTree(base, options, 1, visitor); - - List<PathWithAttributes> found = visitor.getSortedPaths(); - assertNotNull(found); - assertEquals("file count", 3, found.size()); - assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0).getPath()); - assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); - assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2).getPath()); - } - - @Test - public void testRecentLast() throws Exception { - SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false)); - Set<FileVisitOption> options = Collections.emptySet(); - Files.walkFileTree(base, options, 1, visitor); - - List<PathWithAttributes> found = visitor.getSortedPaths(); - assertNotNull(found); - assertEquals("file count", 3, found.size()); - assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0).getPath()); - assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); - assertEquals("3rd: most recent sorted; list=" + found, ccc, found.get(2).getPath()); - } -} +/* + * 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.action; + +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileTime; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the SortingVisitor class. + */ +public class SortingVisitorTest { + + private Path base; + private Path aaa; + private Path bbb; + private Path ccc; + + @Before + public void setUp() throws Exception { + base = Files.createTempDirectory("tempDir", new FileAttribute<?>[0]); + aaa = Files.createTempFile(base, "aaa", null, new FileAttribute<?>[0]); + bbb = Files.createTempFile(base, "bbb", null, new FileAttribute<?>[0]); + ccc = Files.createTempFile(base, "ccc", null, new FileAttribute<?>[0]); + + // lastModified granularity is 1 sec(!) on some file systems... + final long now = System.currentTimeMillis(); + Files.setLastModifiedTime(aaa, FileTime.fromMillis(now)); + Files.setLastModifiedTime(bbb, FileTime.fromMillis(now + 1000)); + Files.setLastModifiedTime(ccc, FileTime.fromMillis(now + 2000)); + } + + @After + public void tearDown() throws Exception { + Files.deleteIfExists(ccc); + Files.deleteIfExists(bbb); + Files.deleteIfExists(aaa); + Files.deleteIfExists(base); + } + + @Test + public void testRecentFirst() throws Exception { + final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(true)); + final Set<FileVisitOption> options = Collections.emptySet(); + Files.walkFileTree(base, options, 1, visitor); + + final List<PathWithAttributes> found = visitor.getSortedPaths(); + assertNotNull(found); + assertEquals("file count", 3, found.size()); + assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0).getPath()); + assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); + assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2).getPath()); + } + + @Test + public void testRecentLast() throws Exception { + final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false)); + final Set<FileVisitOption> options = Collections.emptySet(); + Files.walkFileTree(base, options, 1, visitor); + + final List<PathWithAttributes> found = visitor.getSortedPaths(); + assertNotNull(found); + assertEquals("file count", 3, found.size()); + assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0).getPath()); + assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); + assertEquals("3rd: most recent sorted; list=" + found, ccc, found.get(2).getPath()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java index c6624ea..4e292ca 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderWithPurgingTest.java @@ -84,7 +84,7 @@ public class RoutingAppenderWithPurgingTest { EventLogger.logEvent(msg); msg = new StructuredDataMessage("3", "This is a test 3", "Service"); EventLogger.logEvent(msg); - String[] files = {IDLE_LOG_FILE1, IDLE_LOG_FILE2, IDLE_LOG_FILE3, MANUAL_LOG_FILE1, MANUAL_LOG_FILE2, MANUAL_LOG_FILE3}; + final String[] files = {IDLE_LOG_FILE1, IDLE_LOG_FILE2, IDLE_LOG_FILE3, MANUAL_LOG_FILE1, MANUAL_LOG_FILE2, MANUAL_LOG_FILE3}; assertFileExistance(files); assertEquals("Incorrect number of appenders with IdlePurgePolicy.", 3, routingAppenderIdle.getAppenders().size()); @@ -107,7 +107,7 @@ public class RoutingAppenderWithPurgingTest { } private void assertFileExistance(final String... files) { - for (String file : files) { + for (final String file : files) { assertTrue("File should exist - " + file + " file ", new File(file).exists()); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java index 591d08b..349db77 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestNanoTime.java @@ -84,7 +84,7 @@ public class AsyncLoggerTestNanoTime { final String[] line1Parts = line1.split(" AND "); assertEquals("Use actual System.nanoTime()", line1Parts[2]); assertEquals(line1Parts[0], line1Parts[1]); - long loggedNanoTime = Long.parseLong(line1Parts[0]); + final long loggedNanoTime = Long.parseLong(line1Parts[0]); assertTrue("used system nano time", loggedNanoTime - before < TimeUnit.SECONDS.toNanos(1)); final String[] line2Parts = line2.split(" AND "); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java index 305a5ee..2c9ed8a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java @@ -45,7 +45,7 @@ public class AsyncQueueFullPolicyFactoryTest { @Test public void testCreateReturnsDefaultRouterByDefault() throws Exception { - AsyncQueueFullPolicy router = AsyncQueueFullPolicyFactory.create(); + final AsyncQueueFullPolicy router = AsyncQueueFullPolicyFactory.create(); assertEquals(DefaultAsyncQueueFullPolicy.class, router.getClass()); } @@ -77,7 +77,7 @@ public class AsyncQueueFullPolicyFactoryTest { System.setProperty(AsyncQueueFullPolicyFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER, AsyncQueueFullPolicyFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER); - for (Level level : Level.values()) { + for (final Level level : Level.values()) { System.setProperty(AsyncQueueFullPolicyFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, level.name()); assertEquals(level, ((DiscardingAsyncQueueFullPolicy) AsyncQueueFullPolicyFactory.create()). http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java index 22489c2..b05313d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java @@ -36,14 +36,14 @@ public class DefaultAsyncQueueFullPolicyTest { @Test public void testGetRouteEnqueuesIfQueueFullAndCalledFromDifferentThread() throws Exception { - DefaultAsyncQueueFullPolicy router = new DefaultAsyncQueueFullPolicy(); + final DefaultAsyncQueueFullPolicy router = new DefaultAsyncQueueFullPolicy(); assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL)); assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF)); } @Test public void testGetRouteSynchronousIfQueueFullAndCalledFromSameThread() throws Exception { - DefaultAsyncQueueFullPolicy router = new DefaultAsyncQueueFullPolicy(); + final DefaultAsyncQueueFullPolicy router = new DefaultAsyncQueueFullPolicy(); assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL)); assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF)); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncQueueFullPolicyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncQueueFullPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncQueueFullPolicyTest.java index a979133..ff2350c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncQueueFullPolicyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncQueueFullPolicyTest.java @@ -49,9 +49,9 @@ public class DiscardingAsyncQueueFullPolicyTest { @Test public void testGetRouteDiscardsIfThresholdCapacityReachedAndLevelEqualOrLessSpecificThanThreshold() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); - for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { + for (final Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level)); assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); @@ -61,9 +61,9 @@ public class DiscardingAsyncQueueFullPolicyTest { @Test public void testGetRouteDiscardsIfQueueFullAndLevelEqualOrLessSpecificThanThreshold() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); - for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { + for (final Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) { assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level)); assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level)); } @@ -72,9 +72,9 @@ public class DiscardingAsyncQueueFullPolicyTest { @Test public void testGetRouteEnqueuesIfThresholdCapacityReachedButLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); - for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { + for (final Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level)); assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); @@ -84,25 +84,25 @@ public class DiscardingAsyncQueueFullPolicyTest { @Test public void testGetRouteEnqueuesIfOtherThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); - for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { + for (final Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level)); } } @Test public void testGetRouteSynchronousIfCurrentThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.WARN); - for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { + for (final Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) { assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level)); } } @Test public void testGetDiscardCount() throws Exception { - DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.INFO); + final DiscardingAsyncQueueFullPolicy router = new DiscardingAsyncQueueFullPolicy(Level.INFO); assertEquals("initially", 0, DiscardingAsyncQueueFullPolicy.getDiscardCount(router)); assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO)); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/ResponseTimeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/ResponseTimeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/ResponseTimeTest.java index 57140b5..c09c428 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/ResponseTimeTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/ResponseTimeTest.java @@ -133,8 +133,8 @@ public class ResponseTimeTest { // Warmup: run as many iterations of 50,000 calls to logger.log as we can in 1 minute final long WARMUP_DURATION_MILLIS = TimeUnit.MINUTES.toMillis(1); - List<Histogram> warmupServiceTmHistograms = new ArrayList<>(threadCount); - List<Histogram> warmupResponseTmHistograms = new ArrayList<>(threadCount); + final List<Histogram> warmupServiceTmHistograms = new ArrayList<>(threadCount); + final List<Histogram> warmupResponseTmHistograms = new ArrayList<>(threadCount); final int WARMUP_COUNT = 50000 / threadCount; runLatencyTest(logger, WARMUP_DURATION_MILLIS, WARMUP_COUNT, loadMessagesPerSec, idleStrategy, @@ -146,9 +146,9 @@ public class ResponseTimeTest { } System.out.println("-----------------Starting measured run. load=" + loadMessagesPerSec); - long start = System.currentTimeMillis(); - List<Histogram> serviceTmHistograms = new ArrayList<>(threadCount); - List<Histogram> responseTmHistograms = new ArrayList<>(threadCount); + final long start = System.currentTimeMillis(); + final List<Histogram> serviceTmHistograms = new ArrayList<>(threadCount); + final List<Histogram> responseTmHistograms = new ArrayList<>(threadCount); PrintingAsyncQueueFullPolicy.ringbufferFull.set(0); // Actual test: run as many iterations of 1,000,000 calls to logger.log as we can in 4 minutes. @@ -156,7 +156,7 @@ public class ResponseTimeTest { final int COUNT = (1000 * 1000) / threadCount; runLatencyTest(logger, TEST_DURATION_MILLIS, COUNT, loadMessagesPerSec, idleStrategy, serviceTmHistograms, responseTmHistograms, threadCount); - long end = System.currentTimeMillis(); + final long end = System.currentTimeMillis(); // ... and report the results final Histogram resultServiceTm = createResultHistogram(serviceTmHistograms, start, end); @@ -208,7 +208,7 @@ public class ResponseTimeTest { LATCH.countDown(); try { LATCH.await(); // wait until all threads are ready to go - } catch (InterruptedException e) { + } catch (final InterruptedException e) { interrupt(); return; } @@ -317,7 +317,7 @@ public class ResponseTimeTest { public long nsecToNextOperation() { - long now = System.nanoTime(); + final long now = System.nanoTime(); long nextStartTime = expectedNextOperationNanoTime(); @@ -337,7 +337,7 @@ public class ResponseTimeTest { } // Figure out if it's time to send, per catch up throughput: - long unitsCompletedSinceCatchUpStart = + final long unitsCompletedSinceCatchUpStart = unitsCompleted - unitsCompletedAtCatchUpStart; nextStartTime = catchUpStartTime + @@ -358,7 +358,7 @@ public class ResponseTimeTest { * @param unitCount */ public void acquire(final long unitCount) { - long nsecToNextOperation = nsecToNextOperation(); + final long nsecToNextOperation = nsecToNextOperation(); if (nsecToNextOperation > 0) { sleepNs(nsecToNextOperation); } @@ -367,7 +367,7 @@ public class ResponseTimeTest { private void sleepNs(final long ns) { long now = System.nanoTime(); - long deadline = now + ns; + final long deadline = now + ns; while ((now = System.nanoTime()) < deadline) { idleStrategy.idle(); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java index dacc1a5..dd4f82a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java @@ -41,7 +41,7 @@ public class SimplePerfTest { public static void main(final String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); - Logger logger = LogManager.getLogger(); + final Logger logger = LogManager.getLogger(); if (!(logger instanceof AsyncLogger)) { throw new IllegalStateException(); } @@ -58,8 +58,8 @@ public class SimplePerfTest { final long[] DURATIONS = new long[1024]; // warmup - long startMs = System.currentTimeMillis(); - long end = startMs + TimeUnit.SECONDS.toMillis(10); + final long startMs = System.currentTimeMillis(); + final long end = startMs + TimeUnit.SECONDS.toMillis(10); int warmupCount = 0; do { runTest(logger, runtimeMXBean, UPTIMES, DURATIONS, warmupCount); @@ -69,23 +69,23 @@ public class SimplePerfTest { final int COUNT = 10; for (int i = 0; i < COUNT; i++) { - int count = warmupCount + i; + final int count = warmupCount + i; runTest(logger, runtimeMXBean, UPTIMES, DURATIONS, count); // Thread.sleep(1000);// drain buffer } - double testDurationNanos = System.nanoTime() - testStartNanos; + final double testDurationNanos = System.nanoTime() - testStartNanos; System.out.println("Done. Calculating stats..."); printReport("Warmup", UPTIMES, DURATIONS, 0, warmupCount); printReport("Test", UPTIMES, DURATIONS, warmupCount, COUNT); - StringBuilder sb = new StringBuilder(512); + final StringBuilder sb = new StringBuilder(512); sb.append("Test took: ").append(testDurationNanos/(1000.0*1000.0*1000.0)).append(" sec"); System.out.println(sb); final List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (int i = 0; i < gcBeans.size(); i++) { - GarbageCollectorMXBean gcBean = gcBeans.get(i); + final GarbageCollectorMXBean gcBean = gcBeans.get(i); sb.setLength(0); sb.append("GC[").append(gcBean.getName()).append("] "); sb.append(gcBean.getCollectionCount()).append(" collections, collection time="); @@ -96,7 +96,7 @@ public class SimplePerfTest { private static void printReport(final String label, final long[] UPTIMES, final long[] DURATIONS, final int offset, final int length) { - StringBuilder sb = new StringBuilder(512); + final StringBuilder sb = new StringBuilder(512); long total = 0; for (int i = offset; i < offset + length; i++) { sb.setLength(0); @@ -117,9 +117,9 @@ public class SimplePerfTest { private static void runTest(final Logger logger, final RuntimeMXBean runtimeMXBean, final long[] UPTIMES, final long[] DURATIONS, final int index) { UPTIMES[index] = runtimeMXBean.getUptime(); - long startNanos = System.nanoTime(); + final long startNanos = System.nanoTime(); loop(logger, ITERATIONS); - long endNanos = System.nanoTime(); + final long endNanos = System.nanoTime(); DURATIONS[index] = endNanos - startNanos; } @@ -138,11 +138,11 @@ public class SimplePerfTest { private static void workAroundLog4j2_5Bug() { // use reflection so we can use the same test with older versions of log4j2 try { - Method setUseThreadLocals = + final Method setUseThreadLocals = AsyncLoggerContext.class.getDeclaredMethod("setUseThreadLocals", new Class[]{boolean.class}); - LoggerContext context = LogManager.getContext(false); + final LoggerContext context = LogManager.getContext(false); setUseThreadLocals.invoke(context, new Object[] {Boolean.TRUE}); - } catch (Throwable ignored) { + } catch (final Throwable ignored) { } } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java index 43d91cc..e5db9cc 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AbstractLog4j2_1100Test.java @@ -1,68 +1,68 @@ -/* - * 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.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.logging.log4j.core.appender.RollingFileAppender; -import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy; -import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy; -import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy; -import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy; -import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Rule; -import org.junit.Test; - -public abstract class AbstractLog4j2_1100Test { - - @Rule - public LoggerContextRule context = new LoggerContextRule(getConfigurationResource()); - - protected abstract String getConfigurationResource(); - - @Test - public void test() { - final Configuration configuration = context.getConfiguration(); - assertNotNull(configuration); - final RollingFileAppender appender = configuration.getAppender("File"); - assertNotNull(appender); - final CompositeTriggeringPolicy compositeTriggeringPolicy = appender.getTriggeringPolicy(); - assertNotNull(compositeTriggeringPolicy); - final TriggeringPolicy[] triggeringPolicies = compositeTriggeringPolicy.getTriggeringPolicies(); - SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = null; - TimeBasedTriggeringPolicy timeBasedTriggeringPolicy = null; - for (TriggeringPolicy triggeringPolicy : triggeringPolicies) { - if (triggeringPolicy instanceof TimeBasedTriggeringPolicy) { - timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicy; - assertEquals(7, timeBasedTriggeringPolicy.getInterval()); - } - if (triggeringPolicy instanceof SizeBasedTriggeringPolicy) { - sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicy; - assertEquals(100 * 1024 * 1024, sizeBasedTriggeringPolicy.getMaxFileSize()); - } - } - if (timeBasedTriggeringPolicy == null) { - fail("Missing TimeBasedTriggeringPolicy"); - } - if (sizeBasedTriggeringPolicy == null) { - fail("Missing SizeBasedTriggeringPolicy"); - } - } -} +/* + * 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.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.logging.log4j.core.appender.RollingFileAppender; +import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy; +import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy; +import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy; +import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Rule; +import org.junit.Test; + +public abstract class AbstractLog4j2_1100Test { + + @Rule + public LoggerContextRule context = new LoggerContextRule(getConfigurationResource()); + + protected abstract String getConfigurationResource(); + + @Test + public void test() { + final Configuration configuration = context.getConfiguration(); + assertNotNull(configuration); + final RollingFileAppender appender = configuration.getAppender("File"); + assertNotNull(appender); + final CompositeTriggeringPolicy compositeTriggeringPolicy = appender.getTriggeringPolicy(); + assertNotNull(compositeTriggeringPolicy); + final TriggeringPolicy[] triggeringPolicies = compositeTriggeringPolicy.getTriggeringPolicies(); + SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = null; + TimeBasedTriggeringPolicy timeBasedTriggeringPolicy = null; + for (final TriggeringPolicy triggeringPolicy : triggeringPolicies) { + if (triggeringPolicy instanceof TimeBasedTriggeringPolicy) { + timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicy; + assertEquals(7, timeBasedTriggeringPolicy.getInterval()); + } + if (triggeringPolicy instanceof SizeBasedTriggeringPolicy) { + sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicy; + assertEquals(100 * 1024 * 1024, sizeBasedTriggeringPolicy.getMaxFileSize()); + } + } + if (timeBasedTriggeringPolicy == null) { + fail("Missing TimeBasedTriggeringPolicy"); + } + if (sizeBasedTriggeringPolicy == null) { + fail("Missing SizeBasedTriggeringPolicy"); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AppenderControlArraySetTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AppenderControlArraySetTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AppenderControlArraySetTest.java index f742f04..58ac9ea 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AppenderControlArraySetTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/AppenderControlArraySetTest.java @@ -63,7 +63,7 @@ public class AppenderControlArraySetTest { final AppenderControlArraySet set = new AppenderControlArraySet(); final AppenderControl[] controls = new AppenderControl[] {createControl("A"), createControl("B"), createControl("B"), createControl("B"), createControl("A")}; - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { set.add(ctl); } assertEquals(2, set.get().length); @@ -118,7 +118,7 @@ public class AppenderControlArraySetTest { final AppenderControlArraySet set = new AppenderControlArraySet(); final AppenderControl[] controls = new AppenderControl[] {createControl("A"), createControl("B"), createControl("C"), createControl("D")}; - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { set.add(ctl); } assertEquals(controls.length, set.get().length); @@ -135,11 +135,11 @@ public class AppenderControlArraySetTest { final AppenderControlArraySet set = new AppenderControlArraySet(); final AppenderControl[] controls = new AppenderControl[] {createControl("A"), createControl("B"), createControl("C"), createControl("D")}; - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { set.add(ctl); } final Map<String, Appender> expected = new HashMap<>(); - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { expected.put(ctl.getAppenderName(), ctl.getAppender()); } assertEquals(expected, set.asMap()); @@ -162,7 +162,7 @@ public class AppenderControlArraySetTest { final AppenderControlArraySet set = new AppenderControlArraySet(); final AppenderControl[] controls = new AppenderControl[] {createControl("A"), createControl("B"), createControl("C")}; - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { set.add(ctl); } assertEquals(3, set.get().length); @@ -182,7 +182,7 @@ public class AppenderControlArraySetTest { final AppenderControlArraySet set = new AppenderControlArraySet(); final AppenderControl[] controls = new AppenderControl[] {createControl("A"), createControl("B"), createControl("C")}; - for (AppenderControl ctl : controls) { + for (final AppenderControl ctl : controls) { set.add(ctl); } assertEquals(3, set.get().length); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationTest.java index ecf57f0..d60c001 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationTest.java @@ -88,10 +88,10 @@ public class CompositeConfigurationTest { @Test public void compositeLogger() { final LoggerContextRule lcr = new LoggerContextRule("classpath:log4j-comp-logger.xml,log4j-comp-logger.json"); - Statement test = new Statement() { + final Statement test = new Statement() { @Override public void evaluate() throws Throwable { - CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); + final CompositeConfiguration config = (CompositeConfiguration) lcr.getConfiguration(); Map<String, Appender> appendersMap = config.getLogger("cat1").getAppenders(); assertEquals("Expected 2 Appender references for cat1 but got " + appendersMap.size(), 2, appendersMap.size()); @@ -169,7 +169,7 @@ public class CompositeConfigurationTest { rule.apply(statement, Description .createTestDescription(getClass(), Thread.currentThread().getStackTrace()[1].getMethodName())) .evaluate(); - } catch (Throwable throwable) { + } catch (final Throwable throwable) { throw new RuntimeException(throwable); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java index 94e7420..d73ca30 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java @@ -364,12 +364,12 @@ public class TestConfigurator { @Test public void testBuilder() throws Exception { - ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); + final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setStatusLevel(Level.ERROR); builder.setConfigurationName("BuilderTest"); builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL) .addAttribute("level", Level.DEBUG)); - AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", + final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); appenderBuilder.add(builder.newLayout("PatternLayout"). addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable")); @@ -389,7 +389,7 @@ public class TestConfigurator { @Test public void testRolling() throws Exception { - ConfigurationBuilder< BuiltConfiguration > builder = + final ConfigurationBuilder< BuiltConfiguration > builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setStatusLevel( Level.ERROR); @@ -401,9 +401,9 @@ public class TestConfigurator { addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable")); builder.add( appenderBuilder ); - LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout") + final LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout") .addAttribute("pattern", "%d [%t] %-5level: %msg%n"); - ComponentBuilder triggeringPolicy = builder.newComponent("Policies") + final ComponentBuilder triggeringPolicy = builder.newComponent("Policies") .addComponent(builder.newComponent("CronTriggeringPolicy").addAttribute("schedule", "0 0 0 * * ?")) .addComponent(builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size", "100M")); appenderBuilder = builder.newAppender("rolling", "RollingFile") @@ -420,30 +420,30 @@ public class TestConfigurator { builder.add( builder.newRootLogger( Level.DEBUG ) .add( builder.newAppenderRef( "rolling" ) ) ); - Configuration config = builder.build(); + final Configuration config = builder.build(); config.initialize(); assertNotNull("No rolling file appender", config.getAppender("rolling")); assertEquals("Unexpected Configuration", "RollingBuilder", config.getName()); // Initialize the new configuration - LoggerContext ctx = Configurator.initialize( config ); + final LoggerContext ctx = Configurator.initialize( config ); Configurator.shutdown(ctx); } @Test public void testBuilderWithScripts() throws Exception { - String script = "if (logEvent.getLoggerName().equals(\"NoLocation\")) {\n" + + final String script = "if (logEvent.getLoggerName().equals(\"NoLocation\")) {\n" + " return \"NoLocation\";\n" + " } else if (logEvent.getMarker() != null && logEvent.getMarker().isInstanceOf(\"FLOW\")) {\n" + " return \"Flow\";\n" + " } else {\n" + " return null;\n" + " }"; - ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); + final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setStatusLevel(Level.ERROR); builder.setConfigurationName("BuilderTest"); builder.add(builder.newScriptFile("filter.groovy", "target/test-classes/scripts/filter.groovy").addIsWatched(true)); - AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", + final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); appenderBuilder.add(builder.newLayout("PatternLayout"). addComponent(builder.newComponent("ScriptPatternSelector") http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java index ea2c954..99d7518 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/ConfigurationAssemblerTest.java @@ -48,7 +48,7 @@ public class ConfigurationAssemblerTest { public void testBuildConfiguration() throws Exception { final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); CustomConfigurationFactory.addTestFixtures("config name", builder); - Configuration configuration = builder.build(); + final Configuration configuration = builder.build(); Configurator.initialize(configuration); validate(configuration); } @@ -58,7 +58,7 @@ public class ConfigurationAssemblerTest { try { System.setProperty(ConfigurationFactory.CONFIGURATION_FACTORY_PROPERTY, "org.apache.logging.log4j.core.config.builder.CustomConfigurationFactory"); - Configuration config = ((LoggerContext) LogManager.getContext(false)).getConfiguration(); + final Configuration config = ((LoggerContext) LogManager.getContext(false)).getConfiguration(); validate(config); } finally { System.getProperties().remove(ConfigurationFactory.CONFIGURATION_FACTORY_PROPERTY); @@ -71,16 +71,16 @@ public class ConfigurationAssemblerTest { assertFalse(config.getName().isEmpty()); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); - Map<String, Appender> appenders = config.getAppenders(); + final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); - Map<String, LoggerConfig> loggers = config.getLoggers(); + final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); - Filter filter = config.getFilter(); + final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); - Logger logger = LogManager.getLogger(getClass()); + final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java index 659f163..cd65bfb 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java @@ -42,7 +42,7 @@ public class CustomConfigurationFactory extends ConfigurationFactory { builder.add(builder.newScriptFile("target/test-classes/scripts/filter.groovy").addIsWatched(true)); builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL) .addAttribute("level", Level.DEBUG)); - AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); + final AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); appenderBuilder.add(builder.newLayout("PatternLayout"). addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable")); appenderBuilder.add(builder.newFilter("MarkerFilter", Filter.Result.DENY, @@ -62,7 +62,7 @@ public class CustomConfigurationFactory extends ConfigurationFactory { @Override public Configuration getConfiguration(final String name, final URI configLocation) { - ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder(); + final ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder(); return addTestFixtures(name, builder); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java index 5a8be67..acc5220 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationRootLoggerOnlyTest.java @@ -42,19 +42,19 @@ public class PropertiesConfigurationRootLoggerOnlyTest { @Test public void testPropertiesConfiguration() { - Configuration config = context.getConfiguration(); + final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); - Map<String, Appender> appenders = config.getAppenders(); + final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); - Map<String, LoggerConfig> loggers = config.getLoggers(); + final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1); - Filter filter = config.getFilter(); + final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); - Logger logger = LogManager.getLogger(getClass()); + final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java index dfe24a5..0e3c2c1 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java @@ -42,19 +42,19 @@ public class PropertiesConfigurationTest { @Test public void testPropertiesConfiguration() { - Configuration config = context.getConfiguration(); + final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); - Map<String, Appender> appenders = config.getAppenders(); + final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1); - Map<String, LoggerConfig> loggers = config.getLoggers(); + final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); - Filter filter = config.getFilter(); + final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); - Logger logger = LogManager.getLogger(getClass()); + final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java index e216ff8..9baf89b 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/RollingFilePropertiesTest.java @@ -42,19 +42,19 @@ public class RollingFilePropertiesTest { @Test public void testPropertiesConfiguration() { - Configuration config = context.getConfiguration(); + final Configuration config = context.getConfiguration(); assertNotNull("No configuration created", config); assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED); - Map<String, Appender> appenders = config.getAppenders(); + final Map<String, Appender> appenders = config.getAppenders(); assertNotNull(appenders); assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3); - Map<String, LoggerConfig> loggers = config.getLoggers(); + final Map<String, LoggerConfig> loggers = config.getLoggers(); assertNotNull(loggers); assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2); - Filter filter = config.getFilter(); + final Filter filter = config.getFilter(); assertNotNull("No Filter", filter); assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter); - Logger logger = LogManager.getLogger(getClass()); + final Logger logger = LogManager.getLogger(getClass()); logger.info("Welcome to Log4j!"); } }