http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java index a74a35b..0e22b3e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java @@ -34,7 +34,7 @@ public class GcFreeAsynchronousLoggingTest { /** * This code runs in a separate process, instrumented with the Google Allocation Instrumenter. */ - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeAsynchronousLoggingTest.class); }
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java index ead935e..af12699 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java @@ -70,7 +70,7 @@ public class GcFreeLoggingTestUtil { final AtomicBoolean samplingEnabled = new AtomicBoolean(true); final Sampler sampler = new Sampler() { @Override - public void sampleAllocation(int count, String desc, Object newObj, long size) { + public void sampleAllocation(final int count, final String desc, final Object newObj, final long size) { if (!samplingEnabled.get()) { return; } @@ -108,7 +108,7 @@ public class GcFreeLoggingTestUtil { Thread.sleep(100); } - public static void runTest(Class<?> cls) throws Exception { + public static void runTest(final Class<?> cls) throws Exception { final String javaHome = System.getProperty("java.home"); final String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; final String classpath = System.getProperty("java.class.path"); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java index c18861b..90a0dc5 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java @@ -34,7 +34,7 @@ public class GcFreeMixedSyncAyncLoggingTest { /** * This code runs in a separate process, instrumented with the Google Allocation Instrumenter. */ - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { System.setProperty("AsyncLoggerConfig.RingBufferSize", "128"); // minimum ringbuffer size GcFreeLoggingTestUtil.executeLogging("gcFreeMixedSyncAsyncLogging.xml", GcFreeMixedSyncAyncLoggingTest.class); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java index 731c2af..3787aa2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java @@ -34,7 +34,7 @@ public class GcFreeSynchronousLoggingTest { /** * This code runs in a separate process, instrumented with the Google Allocation Instrumenter. */ - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeSynchronousLoggingTest.class); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java index d074368..c64e7a0 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java @@ -105,7 +105,7 @@ public class AsyncAppenderQueueFullPolicyTest { public static class CountingAsyncQueueFullPolicy extends DefaultAsyncQueueFullPolicy { static AtomicLong queueFull = new AtomicLong(); @Override - public EventRoute getRoute(long backgroundThreadId, Level level) { + public EventRoute getRoute(final long backgroundThreadId, final Level level) { queueFull.incrementAndGet(); return EventRoute.ENQUEUE; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java index 2d002ea..83f2476 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java @@ -1,147 +1,147 @@ -/* - * 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.mom.kafka; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import org.apache.kafka.clients.producer.MockProducer; -import org.apache.kafka.clients.producer.Producer; -import org.apache.kafka.clients.producer.ProducerRecord; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.impl.Log4jLogEvent; -import org.apache.logging.log4j.junit.LoggerContextRule; -import org.apache.logging.log4j.message.SimpleMessage; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class KafkaAppenderTest { - - private static final MockProducer<byte[], byte[]> kafka = new MockProducer<byte[], byte[]>(true, null, null) { - @Override - public void close() { - try { - Thread.sleep(3000); - } catch (InterruptedException ignore) { - } - } - - @Override - public void close(long timeout, TimeUnit timeUnit) { - try { - Thread.sleep(timeUnit.toMillis(timeout)); - } catch (InterruptedException ignore) { - } - } - }; - - private static final String LOG_MESSAGE = "Hello, world!"; - private static final String TOPIC_NAME = "kafka-topic"; - - private static Log4jLogEvent createLogEvent() { - return Log4jLogEvent.newBuilder() - .setLoggerName(KafkaAppenderTest.class.getName()) - .setLoggerFqcn(KafkaAppenderTest.class.getName()) - .setLevel(Level.INFO) - .setMessage(new SimpleMessage(LOG_MESSAGE)) - .build(); - } - - @BeforeClass - public static void setUpClass() throws Exception { - KafkaManager.producerFactory = new KafkaProducerFactory() { - @Override - public Producer<byte[], byte[]> newKafkaProducer(final Properties config) { - return kafka; - } - }; - } - - @Rule - public LoggerContextRule ctx = new LoggerContextRule("KafkaAppenderTest.xml"); - - @Before - public void setUp() throws Exception { - kafka.clear(); - } - - @Test - public void testAppend() throws Exception { - final Appender appender = ctx.getRequiredAppender("KafkaAppender"); - appender.append(createLogEvent()); - final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); - assertEquals(1, history.size()); - final ProducerRecord<byte[], byte[]> item = history.get(0); - assertNotNull(item); - assertEquals(TOPIC_NAME, item.topic()); - assertNull(item.key()); - assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_8)); - } - - @Test - public void testAppendWithLayout() throws Exception { - final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithLayout"); - appender.append(createLogEvent()); - final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); - assertEquals(1, history.size()); - final ProducerRecord<byte[], byte[]> item = history.get(0); - assertNotNull(item); - assertEquals(TOPIC_NAME, item.topic()); - assertNull(item.key()); - assertEquals("[" + LOG_MESSAGE + "]", new String(item.value(), StandardCharsets.UTF_8)); - } - - @Test - public void testAppendWithSerializedLayout() throws Exception { - final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithSerializedLayout"); - LogEvent logEvent = createLogEvent(); - appender.append(logEvent); - final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); - assertEquals(1, history.size()); - final ProducerRecord<byte[], byte[]> item = history.get(0); - assertNotNull(item); - assertEquals(TOPIC_NAME, item.topic()); - assertNull(item.key()); - assertEquals(LOG_MESSAGE, deserializeLogEvent(item.value()).getMessage().getFormattedMessage()); - } - - private LogEvent deserializeLogEvent(byte[] data) throws IOException, ClassNotFoundException { - ByteArrayInputStream bis = new ByteArrayInputStream(data); - try (ObjectInput ois = new ObjectInputStream(bis)) { - return (LogEvent) ois.readObject(); - } - } - - @Test(timeout = 2000) - public void testClose() throws Exception { - final Appender appender = ctx.getRequiredAppender("KafkaAppender"); - appender.stop(); - } +/* + * 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.mom.kafka; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.apache.kafka.clients.producer.MockProducer; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.impl.Log4jLogEvent; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.message.SimpleMessage; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class KafkaAppenderTest { + + private static final MockProducer<byte[], byte[]> kafka = new MockProducer<byte[], byte[]>(true, null, null) { + @Override + public void close() { + try { + Thread.sleep(3000); + } catch (InterruptedException ignore) { + } + } + + @Override + public void close(final long timeout, final TimeUnit timeUnit) { + try { + Thread.sleep(timeUnit.toMillis(timeout)); + } catch (InterruptedException ignore) { + } + } + }; + + private static final String LOG_MESSAGE = "Hello, world!"; + private static final String TOPIC_NAME = "kafka-topic"; + + private static Log4jLogEvent createLogEvent() { + return Log4jLogEvent.newBuilder() + .setLoggerName(KafkaAppenderTest.class.getName()) + .setLoggerFqcn(KafkaAppenderTest.class.getName()) + .setLevel(Level.INFO) + .setMessage(new SimpleMessage(LOG_MESSAGE)) + .build(); + } + + @BeforeClass + public static void setUpClass() throws Exception { + KafkaManager.producerFactory = new KafkaProducerFactory() { + @Override + public Producer<byte[], byte[]> newKafkaProducer(final Properties config) { + return kafka; + } + }; + } + + @Rule + public LoggerContextRule ctx = new LoggerContextRule("KafkaAppenderTest.xml"); + + @Before + public void setUp() throws Exception { + kafka.clear(); + } + + @Test + public void testAppend() throws Exception { + final Appender appender = ctx.getRequiredAppender("KafkaAppender"); + appender.append(createLogEvent()); + final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); + assertEquals(1, history.size()); + final ProducerRecord<byte[], byte[]> item = history.get(0); + assertNotNull(item); + assertEquals(TOPIC_NAME, item.topic()); + assertNull(item.key()); + assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_8)); + } + + @Test + public void testAppendWithLayout() throws Exception { + final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithLayout"); + appender.append(createLogEvent()); + final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); + assertEquals(1, history.size()); + final ProducerRecord<byte[], byte[]> item = history.get(0); + assertNotNull(item); + assertEquals(TOPIC_NAME, item.topic()); + assertNull(item.key()); + assertEquals("[" + LOG_MESSAGE + "]", new String(item.value(), StandardCharsets.UTF_8)); + } + + @Test + public void testAppendWithSerializedLayout() throws Exception { + final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithSerializedLayout"); + LogEvent logEvent = createLogEvent(); + appender.append(logEvent); + final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); + assertEquals(1, history.size()); + final ProducerRecord<byte[], byte[]> item = history.get(0); + assertNotNull(item); + assertEquals(TOPIC_NAME, item.topic()); + assertNull(item.key()); + assertEquals(LOG_MESSAGE, deserializeLogEvent(item.value()).getMessage().getFormattedMessage()); + } + + private LogEvent deserializeLogEvent(final byte[] data) throws IOException, ClassNotFoundException { + ByteArrayInputStream bis = new ByteArrayInputStream(data); + try (ObjectInput ois = new ObjectInputStream(bis)) { + return (LogEvent) ois.readObject(); + } + } + + @Test(timeout = 2000) + public void testClose() throws Exception { + final Appender appender = ctx.getRequiredAppender("KafkaAppender"); + appender.stop(); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java index 294d7c7..56bb8c5 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java @@ -91,7 +91,7 @@ public class RollingAppenderCustomDeleteActionTest { } } - public static void main(String[] args) { + public static void main(final String[] args) { Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); for (int i = 0; i < 16; i++) { String str = "test-" + i + ".log.gz"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java index 17686a7..4595b59 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java @@ -91,13 +91,13 @@ public class RollingAppenderDeleteAccumulatedCount1Test { } } - private void updateLastModified(Path... paths) throws IOException { + private void updateLastModified(final Path... paths) throws IOException { for (Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } - private Path writeTextTo(String location) throws IOException { + private Path writeTextTo(final String location) throws IOException { Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java index d2e471a..5d3e736 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java @@ -92,13 +92,13 @@ public class RollingAppenderDeleteAccumulatedCount2Test { } } - private void updateLastModified(Path... paths) throws IOException { + private void updateLastModified(final Path... paths) throws IOException { for (Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } - private Path writeTextTo(String location) throws IOException { + private Path writeTextTo(final String location) throws IOException { Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java index 9c11416..e185d58 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java @@ -87,7 +87,7 @@ public class RollingAppenderDeleteMaxDepthTest { assertTrue(p4 + " should not have been deleted", Files.exists(p4)); } - private Path writeTextTo(String location) throws IOException { + private Path writeTextTo(final String location) throws IOException { Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { @@ -109,7 +109,7 @@ public class RollingAppenderDeleteMaxDepthTest { } } - public static void main(String[] args) { + public static void main(final String[] args) { Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); for (int i = 0; i < 16; i++) { String str = "test-" + i + ".log.gz"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java index 7156abc..4fde77e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java @@ -91,13 +91,13 @@ public class RollingAppenderDeleteNestedTest { } } - private void updateLastModified(Path... paths) throws IOException { + private void updateLastModified(final Path... paths) throws IOException { for (Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } - private Path writeTextTo(String location) throws IOException { + private Path writeTextTo(final String location) throws IOException { Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java index f25a9e7..adcfd68 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java @@ -96,7 +96,7 @@ public class RollingAppenderNoUnconditionalDeleteTest { deleteDir(directory.getParentFile()); } - private void deleteDir(File dir) { + private void deleteDir(final File dir) { if (dir.exists()) { final File[] files = dir.listFiles(); for (final File file : files) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java index 9355582..12b61f6 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java @@ -1,62 +1,62 @@ -/* - * 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.attribute.BasicFileAttributes; - -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; - -/** - * Test helper class. - */ -public class CountingCondition implements PathCondition { - - private final boolean accept; - private int acceptCount; - private int beforeFileTreeWalkCount; - - public CountingCondition(boolean accept) { - this.accept = accept; - } - - @Override - public boolean accept(Path baseDir, Path path, BasicFileAttributes attrs) { - acceptCount++; - return accept; - } - - @Override - public void beforeFileTreeWalk() { - beforeFileTreeWalkCount++; - } - - /** - * @return the acceptCount - */ - public int getAcceptCount() { - return acceptCount; - } - - /** - * @return the beforeFileTreeWalkCount - */ - public int getBeforeFileTreeWalkCount() { - return beforeFileTreeWalkCount; - } -} +/* + * 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.attribute.BasicFileAttributes; + +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; + +/** + * Test helper class. + */ +public class CountingCondition implements PathCondition { + + private final boolean accept; + private int acceptCount; + private int beforeFileTreeWalkCount; + + public CountingCondition(final boolean accept) { + this.accept = accept; + } + + @Override + public boolean accept(final Path baseDir, final Path path, final BasicFileAttributes attrs) { + acceptCount++; + return accept; + } + + @Override + public void beforeFileTreeWalk() { + beforeFileTreeWalkCount++; + } + + /** + * @return the acceptCount + */ + public int getAcceptCount() { + return acceptCount; + } + + /** + * @return the beforeFileTreeWalkCount + */ + public int getBeforeFileTreeWalkCount() { + return beforeFileTreeWalkCount; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java index 4a1f14c..c745dd3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java @@ -1,119 +1,119 @@ -/* - * 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.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitor; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; - -import org.apache.logging.log4j.core.BasicConfigurationFactory; -import org.apache.logging.log4j.core.appender.rolling.action.DeleteAction; -import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor; -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; -import org.apache.logging.log4j.core.config.Configuration; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the {@code DeleteAction} class. - */ -public class DeleteActionTest { - - private static DeleteAction createAnyFilter(String path, boolean followLinks, int maxDepth, boolean testMode) { - PathCondition[] pathFilters = {new FixedCondition(true)}; - return create(path, followLinks, maxDepth, testMode, pathFilters); - } - - private static DeleteAction create(String path, boolean followLinks, int maxDepth, boolean testMode, - PathCondition[] conditions) { - Configuration config = new BasicConfigurationFactory().new BasicConfiguration(); - DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, testMode, null, conditions, - null, config); - return delete; - } - - @Test - public void testGetBasePathResolvesLookups() { - DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); - - Path actual = delete.getBasePath(); - String expected = System.getProperty("user.home") + "/a/b/c"; - - assertEquals(FileSystems.getDefault().getPath(expected), actual); - } - - @Test - public void testGetBasePathStringReturnsOriginalParam() { - DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); - assertEquals("${sys:user.home}/a/b/c", delete.getBasePathString()); - } - - @Test - public void testGetMaxDepthReturnsConstructorValue() { - DeleteAction delete = createAnyFilter("any", false, 23, false); - assertEquals(23, delete.getMaxDepth()); - } - - @Test - public void testGetOptionsReturnsEmptySetIfNotFollowingLinks() { - DeleteAction delete = createAnyFilter("any", false, 0, false); - assertEquals(Collections.emptySet(), delete.getOptions()); - } - - @Test - public void testGetOptionsReturnsSetWithFollowLinksIfFollowingLinks() { - DeleteAction delete = createAnyFilter("any", true, 0, false); - assertEquals(EnumSet.of(FileVisitOption.FOLLOW_LINKS), delete.getOptions()); - } - - @Test - public void testGetFiltersReturnsConstructorValue() { - PathCondition[] filters = {new FixedCondition(true), new FixedCondition(false)}; - - DeleteAction delete = create("any", true, 0, false, filters); - assertEquals(Arrays.asList(filters), delete.getPathConditions()); - } - - @Test - public void testCreateFileVisitorReturnsDeletingVisitor() { - DeleteAction delete = createAnyFilter("any", true, 0, false); - FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); - assertTrue(visitor instanceof DeletingVisitor); - } - - @Test - public void testCreateFileVisitorTestModeIsActionTestMode() { - DeleteAction delete = createAnyFilter("any", true, 0, false); - assertFalse(delete.isTestMode()); - FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); - assertTrue(visitor instanceof DeletingVisitor); - assertFalse(((DeletingVisitor) visitor).isTestMode()); - - DeleteAction deleteTestMode = createAnyFilter("any", true, 0, true); - assertTrue(deleteTestMode.isTestMode()); - FileVisitor<Path> testVisitor = deleteTestMode.createFileVisitor(delete.getBasePath(), - delete.getPathConditions()); - assertTrue(testVisitor instanceof DeletingVisitor); - assertTrue(((DeletingVisitor) testVisitor).isTestMode()); - } -} +/* + * 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.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitor; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; + +import org.apache.logging.log4j.core.BasicConfigurationFactory; +import org.apache.logging.log4j.core.appender.rolling.action.DeleteAction; +import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; +import org.apache.logging.log4j.core.config.Configuration; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the {@code DeleteAction} class. + */ +public class DeleteActionTest { + + private static DeleteAction createAnyFilter(final String path, final boolean followLinks, final int maxDepth, final boolean testMode) { + PathCondition[] pathFilters = {new FixedCondition(true)}; + return create(path, followLinks, maxDepth, testMode, pathFilters); + } + + private static DeleteAction create(final String path, final boolean followLinks, final int maxDepth, final boolean testMode, + final PathCondition[] conditions) { + Configuration config = new BasicConfigurationFactory().new BasicConfiguration(); + DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, testMode, null, conditions, + null, config); + return delete; + } + + @Test + public void testGetBasePathResolvesLookups() { + DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); + + Path actual = delete.getBasePath(); + String expected = System.getProperty("user.home") + "/a/b/c"; + + assertEquals(FileSystems.getDefault().getPath(expected), actual); + } + + @Test + public void testGetBasePathStringReturnsOriginalParam() { + DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); + assertEquals("${sys:user.home}/a/b/c", delete.getBasePathString()); + } + + @Test + public void testGetMaxDepthReturnsConstructorValue() { + DeleteAction delete = createAnyFilter("any", false, 23, false); + assertEquals(23, delete.getMaxDepth()); + } + + @Test + public void testGetOptionsReturnsEmptySetIfNotFollowingLinks() { + DeleteAction delete = createAnyFilter("any", false, 0, false); + assertEquals(Collections.emptySet(), delete.getOptions()); + } + + @Test + public void testGetOptionsReturnsSetWithFollowLinksIfFollowingLinks() { + DeleteAction delete = createAnyFilter("any", true, 0, false); + assertEquals(EnumSet.of(FileVisitOption.FOLLOW_LINKS), delete.getOptions()); + } + + @Test + public void testGetFiltersReturnsConstructorValue() { + PathCondition[] filters = {new FixedCondition(true), new FixedCondition(false)}; + + DeleteAction delete = create("any", true, 0, false, filters); + assertEquals(Arrays.asList(filters), delete.getPathConditions()); + } + + @Test + public void testCreateFileVisitorReturnsDeletingVisitor() { + DeleteAction delete = createAnyFilter("any", true, 0, false); + FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); + assertTrue(visitor instanceof DeletingVisitor); + } + + @Test + public void testCreateFileVisitorTestModeIsActionTestMode() { + DeleteAction delete = createAnyFilter("any", true, 0, false); + assertFalse(delete.isTestMode()); + FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); + assertTrue(visitor instanceof DeletingVisitor); + assertFalse(((DeletingVisitor) visitor).isTestMode()); + + DeleteAction deleteTestMode = createAnyFilter("any", true, 0, true); + assertTrue(deleteTestMode.isTestMode()); + FileVisitor<Path> testVisitor = deleteTestMode.createFileVisitor(delete.getBasePath(), + delete.getPathConditions()); + assertTrue(testVisitor instanceof DeletingVisitor); + assertTrue(((DeletingVisitor) testVisitor).isTestMode()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java index 4e96a2e..f35f44f 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java @@ -1,135 +1,135 @@ -/* - * 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.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the {@code DeletingVisitor} class. - */ -public class DeletingVisitorTest { - /** - * Modifies {@code DeletingVisitor} for testing: instead of actually deleting a file, it adds the path to a list for - * later verification. - */ - static class DeletingVisitorHelper extends DeletingVisitor { - List<Path> deleted = new ArrayList<>(); - - public DeletingVisitorHelper(final Path basePath, final List<? extends PathCondition> pathFilters, - final boolean testMode) { - super(basePath, pathFilters, testMode); - } - - @Override - protected void delete(final Path file) throws IOException { - deleted.add(file); // overrides and stores path instead of deleting - } - } - - @Test - public void testAcceptedFilesAreDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); - final FixedCondition ACCEPT_ALL = new FixedCondition(true); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL), false); - - Path any = Paths.get("/a/b/c/any"); - visitor.visitFile(any, null); - assertTrue(visitor.deleted.contains(any)); - } - - @Test - public void testRejectedFilesAreNotDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); - final FixedCondition REJECT_ALL = new FixedCondition(false); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL), false); - - Path any = Paths.get("/a/b/c/any"); - visitor.visitFile(any, null); - assertFalse(visitor.deleted.contains(any)); - } - - @Test - public void testAllFiltersMustAcceptOrFileIsNotDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); - final FixedCondition ACCEPT_ALL = new FixedCondition(true); - final FixedCondition REJECT_ALL = new FixedCondition(false); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); - - Path any = Paths.get("/a/b/c/any"); - visitor.visitFile(any, null); - assertFalse(visitor.deleted.contains(any)); - } - - @Test - public void testIfAllFiltersAcceptFileIsDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); - final FixedCondition ACCEPT_ALL = new FixedCondition(true); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); - - Path any = Paths.get("/a/b/c/any"); - visitor.visitFile(any, null); - assertTrue(visitor.deleted.contains(any)); - } - - @Test - public void testInTestModeFileIsNotDeletedEvenIfAllFiltersAccept() throws IOException { - Path base = Paths.get("/a/b/c"); - final FixedCondition ACCEPT_ALL = new FixedCondition(true); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, true); - - Path any = Paths.get("/a/b/c/any"); - visitor.visitFile(any, null); - assertFalse(visitor.deleted.contains(any)); - } - - @Test - public void testVisitFileRelativizesAgainstBase() throws IOException { - - PathCondition filter = new PathCondition() { - - @Override - public boolean accept(Path baseDir, Path relativePath, BasicFileAttributes attrs) { - Path expected = Paths.get("relative"); - assertEquals(expected, relativePath); - return true; - } - - @Override - public void beforeFileTreeWalk() { - } - }; - Path base = Paths.get("/a/b/c"); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false); - - Path child = Paths.get("/a/b/c/relative"); - visitor.visitFile(child, null); - } -} +/* + * 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.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the {@code DeletingVisitor} class. + */ +public class DeletingVisitorTest { + /** + * Modifies {@code DeletingVisitor} for testing: instead of actually deleting a file, it adds the path to a list for + * later verification. + */ + static class DeletingVisitorHelper extends DeletingVisitor { + List<Path> deleted = new ArrayList<>(); + + public DeletingVisitorHelper(final Path basePath, final List<? extends PathCondition> pathFilters, + final boolean testMode) { + super(basePath, pathFilters, testMode); + } + + @Override + protected void delete(final Path file) throws IOException { + deleted.add(file); // overrides and stores path instead of deleting + } + } + + @Test + public void testAcceptedFilesAreDeleted() throws IOException { + Path base = Paths.get("/a/b/c"); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL), false); + + Path any = Paths.get("/a/b/c/any"); + visitor.visitFile(any, null); + assertTrue(visitor.deleted.contains(any)); + } + + @Test + public void testRejectedFilesAreNotDeleted() throws IOException { + Path base = Paths.get("/a/b/c"); + final FixedCondition REJECT_ALL = new FixedCondition(false); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL), false); + + Path any = Paths.get("/a/b/c/any"); + visitor.visitFile(any, null); + assertFalse(visitor.deleted.contains(any)); + } + + @Test + public void testAllFiltersMustAcceptOrFileIsNotDeleted() throws IOException { + Path base = Paths.get("/a/b/c"); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + final FixedCondition REJECT_ALL = new FixedCondition(false); + List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); + + Path any = Paths.get("/a/b/c/any"); + visitor.visitFile(any, null); + assertFalse(visitor.deleted.contains(any)); + } + + @Test + public void testIfAllFiltersAcceptFileIsDeleted() throws IOException { + Path base = Paths.get("/a/b/c"); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); + + Path any = Paths.get("/a/b/c/any"); + visitor.visitFile(any, null); + assertTrue(visitor.deleted.contains(any)); + } + + @Test + public void testInTestModeFileIsNotDeletedEvenIfAllFiltersAccept() throws IOException { + Path base = Paths.get("/a/b/c"); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, true); + + Path any = Paths.get("/a/b/c/any"); + visitor.visitFile(any, null); + assertFalse(visitor.deleted.contains(any)); + } + + @Test + public void testVisitFileRelativizesAgainstBase() throws IOException { + + PathCondition filter = new PathCondition() { + + @Override + public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { + Path expected = Paths.get("relative"); + assertEquals(expected, relativePath); + return true; + } + + @Override + public void beforeFileTreeWalk() { + } + }; + Path base = Paths.get("/a/b/c"); + DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false); + + Path child = Paths.get("/a/b/c/relative"); + visitor.visitFile(child, null); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java index e78f878..8815d5a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java @@ -1,44 +1,44 @@ -/* - * 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.attribute.BasicFileAttributes; - -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; - -/** - * Test helper class. - */ -public class FixedCondition implements PathCondition { - - private final boolean accept; - - public FixedCondition(boolean accept) { - this.accept = accept; - } - - @Override - public boolean accept(Path baseDir, Path path, BasicFileAttributes attrs) { - return accept; - } - - @Override - public void beforeFileTreeWalk() { - } -} +/* + * 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.attribute.BasicFileAttributes; + +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; + +/** + * Test helper class. + */ +public class FixedCondition implements PathCondition { + + private final boolean accept; + + public FixedCondition(final boolean accept) { + this.accept = accept; + } + + @Override + public boolean accept(final Path baseDir, final Path path, final BasicFileAttributes attrs) { + return accept; + } + + @Override + public void beforeFileTreeWalk() { + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 5158789..dcd5ffd 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 @@ -1,93 +1,93 @@ -/* - * 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.nio.file.attribute.FileTime; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the {@code PathSortByModificationTime} class. - */ -public class PathSortByModificationTimeTest { - - /** - * Test method for - * {@link org.apache.logging.log4j.core.appender.rolling.action.PathSortByModificationTime#isRecentFirst()}. - */ - @Test - public void testIsRecentFirstReturnsConstructorValue() { - assertTrue(((PathSortByModificationTime) PathSortByModificationTime.createSorter(true)).isRecentFirst()); - assertFalse(((PathSortByModificationTime) PathSortByModificationTime.createSorter(false)).isRecentFirst()); - } - - @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(); - a1.lastModified = FileTime.fromMillis(100); - a2.lastModified = FileTime.fromMillis(222); - - assertEquals("same path, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p1, a2))); - assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p2, a2))); - assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p2, a1), path(p1, a2))); - - assertEquals("same path, 1st more recent", -1, sorter.compare(path(p1, a2), path(p1, a1))); - assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p1, a2), path(p2, a1))); - assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p2, a2), path(p1, a1))); - - assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); - assertEquals("p2 < p1, same time", 1, sorter.compare(path(p1, a1), path(p2, a1))); - assertEquals("p2 < p1, same time", -1, sorter.compare(path(p2, a1), path(p1, a1))); - } - - @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(); - a1.lastModified = FileTime.fromMillis(100); - a2.lastModified = FileTime.fromMillis(222); - - assertEquals("same path, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p1, a2))); - assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p2, a2))); - assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p2, a1), path(p1, a2))); - - assertEquals("same path, 1st more recent", 1, sorter.compare(path(p1, a2), path(p1, a1))); - assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p1, a2), path(p2, a1))); - assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p2, a2), path(p1, a1))); - - assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); - assertEquals("p1 < p2, same time", -1, sorter.compare(path(p1, a1), path(p2, a1))); - assertEquals("p1 < p2, same time", 1, sorter.compare(path(p2, a1), path(p1, a1))); - } - - private PathWithAttributes path(Path path, DummyFileAttributes attributes) { - return new PathWithAttributes(path, attributes); - } - -} +/* + * 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.nio.file.attribute.FileTime; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the {@code PathSortByModificationTime} class. + */ +public class PathSortByModificationTimeTest { + + /** + * Test method for + * {@link org.apache.logging.log4j.core.appender.rolling.action.PathSortByModificationTime#isRecentFirst()}. + */ + @Test + public void testIsRecentFirstReturnsConstructorValue() { + assertTrue(((PathSortByModificationTime) PathSortByModificationTime.createSorter(true)).isRecentFirst()); + assertFalse(((PathSortByModificationTime) PathSortByModificationTime.createSorter(false)).isRecentFirst()); + } + + @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(); + a1.lastModified = FileTime.fromMillis(100); + a2.lastModified = FileTime.fromMillis(222); + + assertEquals("same path, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p1, a2))); + assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p1, a1), path(p2, a2))); + assertEquals("path ignored, 2nd more recent", 1, sorter.compare(path(p2, a1), path(p1, a2))); + + assertEquals("same path, 1st more recent", -1, sorter.compare(path(p1, a2), path(p1, a1))); + assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p1, a2), path(p2, a1))); + assertEquals("path ignored, 1st more recent", -1, sorter.compare(path(p2, a2), path(p1, a1))); + + assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); + assertEquals("p2 < p1, same time", 1, sorter.compare(path(p1, a1), path(p2, a1))); + assertEquals("p2 < p1, same time", -1, sorter.compare(path(p2, a1), path(p1, a1))); + } + + @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(); + a1.lastModified = FileTime.fromMillis(100); + a2.lastModified = FileTime.fromMillis(222); + + assertEquals("same path, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p1, a2))); + assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p1, a1), path(p2, a2))); + assertEquals("path ignored, 2nd more recent", -1, sorter.compare(path(p2, a1), path(p1, a2))); + + assertEquals("same path, 1st more recent", 1, sorter.compare(path(p1, a2), path(p1, a1))); + assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p1, a2), path(p2, a1))); + assertEquals("path ignored, 1st more recent", 1, sorter.compare(path(p2, a2), path(p1, a1))); + + assertEquals("same path, same time", 0, sorter.compare(path(p1, a1), path(p1, a1))); + assertEquals("p1 < p2, same time", -1, sorter.compare(path(p1, a1), path(p2, a1))); + assertEquals("p1 < p2, same time", 1, sorter.compare(path(p2, a1), path(p1, a1))); + } + + private PathWithAttributes path(final Path path, final DummyFileAttributes attributes) { + return new PathWithAttributes(path, attributes); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 9920690..c6624ea 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 @@ -106,7 +106,7 @@ public class RoutingAppenderWithPurgingTest { assertEquals("Incorrect number of appenders with manual purge.", 0, routingAppenderManual.getAppenders().size()); } - private void assertFileExistance(String... files) { + private void assertFileExistance(final String... files) { for (String file : files) { assertTrue("File should exist - " + file + " file ", new File(file).exists()); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java index de74115..2be6499 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java @@ -199,7 +199,7 @@ public class PerfTestDriver { private final Class<? extends IPerfTestRunner> implementationClass; - private Runner(Class<? extends IPerfTestRunner> cls) { + private Runner(final Class<? extends IPerfTestRunner> cls) { this.implementationClass = cls; } } @@ -277,7 +277,7 @@ public class PerfTestDriver { return tests; } - private static void add(final List<Setup> tests, int threadCount, final String config, final Runner runner, final String name, + private static void add(final List<Setup> tests, final int threadCount, final String config, final Runner runner, final String name, final String... systemProperties) throws IOException { final WaitStrategy wait = WaitStrategy.get(); final Class<?> perfTest = threadCount == 1 ? PerfTest.class : MultiThreadPerfTest.class; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 1ad25db..57140b5 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 @@ -94,7 +94,7 @@ import org.apache.logging.log4j.core.util.Loader; public class ResponseTimeTest { private static final String LATENCY_MSG = new String(new char[64]); - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { if (args.length < 2) { System.out.println("Please specify thread count, target throughput (msg/sec) " + "and logger library (Log4j1, Log4j2, Logback, JUL)"); @@ -244,7 +244,7 @@ public class ResponseTimeTest { static AtomicLong ringbufferFull = new AtomicLong(); @Override - public EventRoute getRoute(long backgroundThreadId, Level level) { + public EventRoute getRoute(final long backgroundThreadId, final Level level) { ringbufferFull.incrementAndGet(); System.out.print('!'); return super.getRoute(backgroundThreadId, level); @@ -283,27 +283,27 @@ public class ResponseTimeTest { private double catchUpRateMultiple; private final IdleStrategy idleStrategy; - public Pacer(double unitsPerSec, IdleStrategy idleStrategy) { + public Pacer(final double unitsPerSec, final IdleStrategy idleStrategy) { this(unitsPerSec, 3.0, idleStrategy); // Default to catching up at 3x the set throughput } - public Pacer(double unitsPerSec, double catchUpRateMultiple, IdleStrategy idleStrategy) { + public Pacer(final double unitsPerSec, final double catchUpRateMultiple, final IdleStrategy idleStrategy) { this.idleStrategy = idleStrategy; setThroughout(unitsPerSec); setCatchupRateMultiple(catchUpRateMultiple); initialStartTime = System.nanoTime(); } - public void setInitialStartTime(long initialStartTime) { + public void setInitialStartTime(final long initialStartTime) { this.initialStartTime = initialStartTime; } - public void setThroughout(double unitsPerSec) { + public void setThroughout(final double unitsPerSec) { throughputInUnitsPerNsec = unitsPerSec / 1000000000.0; catchUpThroughputInUnitsPerNsec = catchUpRateMultiple * throughputInUnitsPerNsec; } - public void setCatchupRateMultiple(double multiple) { + public void setCatchupRateMultiple(final double multiple) { catchUpRateMultiple = multiple; catchUpThroughputInUnitsPerNsec = catchUpRateMultiple * throughputInUnitsPerNsec; } @@ -357,7 +357,7 @@ public class ResponseTimeTest { * * @param unitCount */ - public void acquire(long unitCount) { + public void acquire(final long unitCount) { long nsecToNextOperation = nsecToNextOperation(); if (nsecToNextOperation > 0) { sleepNs(nsecToNextOperation); @@ -365,7 +365,7 @@ public class ResponseTimeTest { unitsCompleted += unitCount; } - private void sleepNs(long ns) { + private void sleepNs(final long ns) { long now = System.nanoTime(); long deadline = now + ns; while ((now = System.nanoTime()) < deadline) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 d886d00..dacc1a5 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 @@ -38,7 +38,7 @@ import org.apache.logging.log4j.spi.LoggerContext; public class SimplePerfTest { static final int ITERATIONS = 100000; - public static void main(String[] args) throws Exception { + public static void main(final String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); Logger logger = LogManager.getLogger(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 85a7df1..ecf57f0 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 @@ -164,7 +164,7 @@ public class CompositeConfigurationTest { } */ - private void runTest(LoggerContextRule rule, Statement statement) { + private void runTest(final LoggerContextRule rule, final Statement statement) { try { rule.apply(statement, Description .createTestDescription(getClass(), Thread.currentThread().getStackTrace()[1].getMethodName())) http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java index 6ce49dc..420ec2b 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorTest.java @@ -1,47 +1,47 @@ -/* - * 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 java.io.File; - -import org.apache.logging.log4j.core.LoggerContext; -import org.junit.Assert; -import org.junit.Test; - -public class ConfiguratorTest { - - @Test - public void testInitializeFromAbsoluteFilePath() { - final String path = new File("src/test/resources/log4j-list.xml").getAbsolutePath(); - testInitializeFromFilePath(path); - } - - @Test - public void testInitializeFromRelativeFilePath() { - final String path = new File("src/test/resources/log4j-list.xml").toString(); - testInitializeFromFilePath(path); - } - - private void testInitializeFromFilePath(String path) { - final LoggerContext loggerContext = Configurator.initialize(getClass().getName(), null, path); - try { - Assert.assertNotNull(loggerContext.getConfiguration().getAppender("List")); - } finally { - loggerContext.stop(); - } - } -} +/* + * 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 java.io.File; + +import org.apache.logging.log4j.core.LoggerContext; +import org.junit.Assert; +import org.junit.Test; + +public class ConfiguratorTest { + + @Test + public void testInitializeFromAbsoluteFilePath() { + final String path = new File("src/test/resources/log4j-list.xml").getAbsolutePath(); + testInitializeFromFilePath(path); + } + + @Test + public void testInitializeFromRelativeFilePath() { + final String path = new File("src/test/resources/log4j-list.xml").toString(); + testInitializeFromFilePath(path); + } + + private void testInitializeFromFilePath(final String path) { + final LoggerContext loggerContext = Configurator.initialize(getClass().getName(), null, path); + try { + Assert.assertNotNull(loggerContext.getConfiguration().getAppender("List")); + } finally { + loggerContext.stop(); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 f938824..ea2c954 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 @@ -65,7 +65,7 @@ public class ConfigurationAssemblerTest { } } - private void validate(Configuration config) { + private void validate(final Configuration config) { assertNotNull(config); assertNotNull(config.getName()); assertFalse(config.getName().isEmpty()); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/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 a6e8017..659f163 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 @@ -36,7 +36,7 @@ import java.net.URI; //@Order(50) public class CustomConfigurationFactory extends ConfigurationFactory { - static Configuration addTestFixtures(final String name, ConfigurationBuilder<BuiltConfiguration> builder) { + static Configuration addTestFixtures(final String name, final ConfigurationBuilder<BuiltConfiguration> builder) { builder.setConfigurationName(name); builder.setStatusLevel(Level.ERROR); builder.add(builder.newScriptFile("target/test-classes/scripts/filter.groovy").addIsWatched(true)); @@ -56,7 +56,7 @@ public class CustomConfigurationFactory extends ConfigurationFactory { } @Override - public Configuration getConfiguration(ConfigurationSource source) { + public Configuration getConfiguration(final ConfigurationSource source) { return getConfiguration(source.toString(), null); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractFilterableTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractFilterableTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractFilterableTest.java index 332b03c..beba5d3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractFilterableTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractFilterableTest.java @@ -257,12 +257,12 @@ public class AbstractFilterableTest { private class EqualFilter extends AbstractFilter { private final String key; - public EqualFilter(String key) { + public EqualFilter(final String key) { this.key = key; } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) return true; if (!(o instanceof EqualFilter)) return false; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java index df4adfb..f5f2e87 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java @@ -221,7 +221,7 @@ public class Log4jLogEventTest { } @SuppressWarnings("deprecation") - private void verifyNanoTimeWithAllConstructors(long expected) { + private void verifyNanoTimeWithAllConstructors(final long expected) { assertEquals(expected, Log4jLogEvent.getNanoClock().nanoTime()); assertEquals("No-arg constructor", expected, new Log4jLogEvent().getNanoTime()); @@ -464,11 +464,11 @@ public class Log4jLogEventTest { different("null exception", builder(event).setThrown(null), event); } - private static Log4jLogEvent.Builder builder(LogEvent event) { + private static Log4jLogEvent.Builder builder(final LogEvent event) { return new Log4jLogEvent.Builder(event); } - private void different(String reason, Log4jLogEvent.Builder builder, LogEvent event) { + private void different(final String reason, final Log4jLogEvent.Builder builder, final LogEvent event) { final LogEvent other = builder.build(); assertNotEquals(reason, other, event); assertNotEquals(reason + " hashCode", other.hashCode(), event.hashCode()); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java index 787c33b..98e3ec7 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java @@ -73,7 +73,7 @@ public class ThrowableProxyTest { return arr.toByteArray(); } - private void testIoContainer(ObjectMapper objectMapper ) throws IOException { + private void testIoContainer(final ObjectMapper objectMapper ) throws IOException { final Fixture expected = new Fixture(); final String s = objectMapper.writeValueAsString(expected); final Fixture actual = objectMapper.readValue(s, Fixture.class); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java index 58136de7..ed95e17 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvLogEventLayoutTest.java @@ -94,7 +94,7 @@ public class CsvLogEventLayoutTest { testLayout(format, CsvLogEventLayout.createLayout(format), null, null); } - private void testLayout(final CSVFormat format, final AbstractCsvLayout layout, String header, String footer) { + private void testLayout(final CSVFormat format, final AbstractCsvLayout layout, final String header, final String footer) { final Map<String, Appender> appenders = root.getAppenders(); for (final Appender appender : appenders.values()) { root.removeAppender(appender); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a5dcd43/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java index 061458f..f1826a2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/CsvParameterLayoutTest.java @@ -90,7 +90,7 @@ public class CsvParameterLayoutTest { assertEquals("text/csv; charset=UTF-8", layout.getContentType()); } - static void testLayoutNormalApi(final Logger root, final AbstractCsvLayout layout, boolean messageApi) throws Exception { + static void testLayoutNormalApi(final Logger root, final AbstractCsvLayout layout, final boolean messageApi) throws Exception { final Map<String, Appender> appenders = root.getAppenders(); for (final Appender appender : appenders.values()) { root.removeAppender(appender);