You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/11/18 01:25:40 UTC
[1/2] logging-log4j2 git commit: Remove dead comments.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 8e5276981 -> 2dfddba07
Remove dead comments.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fba71d1e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fba71d1e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fba71d1e
Branch: refs/heads/master
Commit: fba71d1ea7dc53200fdbfb7bb231bbf02669061d
Parents: 8e52769
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Nov 17 18:36:24 2014 -0500
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Nov 17 18:36:24 2014 -0500
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/util/ClockFactory.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fba71d1e/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java
index 098eeb7..3329e56 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java
@@ -68,12 +68,12 @@ public final class ClockFactory {
LOGGER.debug("Using default SystemClock for timestamps");
return new SystemClock();
}
- if (CachedClock.class.getName().equals(userRequest) //
+ if (CachedClock.class.getName().equals(userRequest)
|| "CachedClock".equals(userRequest)) {
LOGGER.debug("Using specified CachedClock for timestamps");
return CachedClock.instance();
}
- if (CoarseCachedClock.class.getName().equals(userRequest) //
+ if (CoarseCachedClock.class.getName().equals(userRequest)
|| "CoarseCachedClock".equals(userRequest)) {
LOGGER.debug("Using specified CoarseCachedClock for timestamps");
return CoarseCachedClock.instance();
[2/2] logging-log4j2 git commit: Bullet-proof clock-based tests. I am
seeing failures due to test ordering on Java 7 and 8.
Posted by gg...@apache.org.
Bullet-proof clock-based tests. I am seeing failures due to test
ordering on Java 7 and 8.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2dfddba0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2dfddba0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2dfddba0
Branch: refs/heads/master
Commit: 2dfddba075c858d39b9e5ac0d12cbc8834184632
Parents: fba71d1
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Nov 17 19:25:33 2014 -0500
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Nov 17 19:25:33 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/core/LateConfigTest.java | 19 ++++++++++----
.../log4j/core/TimestampMessageTest.java | 25 +++++++++++++-----
.../async/AsyncLoggerTimestampMessageTest.java | 18 +++++++------
.../log4j/core/impl/Log4jLogEventTest.java | 5 ++--
.../log4j/core/util/ClockFactoryTest.java | 27 ++++++++++++++++++--
5 files changed, 70 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2dfddba0/log4j-core/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
index c0c4c3c..016ba9a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
@@ -23,8 +23,11 @@ import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -34,16 +37,22 @@ import org.junit.Test;
public class LateConfigTest {
private static final String CONFIG = "target/test-classes/log4j-test1.xml";
- private static LoggerContext ctx;
+ private static LoggerContext context;
@BeforeClass
public static void setupClass() {
- ctx = (LoggerContext) LogManager.getContext(false);
+ context = (LoggerContext) LogManager.getContext(false);
}
+ @AfterClass
+ public static void tearDownClass() {
+ Configurator.shutdown(context);
+ StatusLogger.getLogger().reset();
+ }
+
@Test
public void testReconfiguration() throws Exception {
- final Configuration cfg = ctx.getConfiguration();
+ final Configuration cfg = context.getConfiguration();
assertNotNull("No configuration", cfg);
assertTrue("Not set to default configuration", cfg instanceof DefaultConfiguration);
final File file = new File(CONFIG);
@@ -52,8 +61,8 @@ public class LateConfigTest {
final Configuration newConfig = loggerContext.getConfiguration();
assertTrue("Configuration not reset", cfg != newConfig);
assertTrue("Reconfiguration failed", newConfig instanceof XmlConfiguration);
- ctx = (LoggerContext) LogManager.getContext(false);
- final Configuration sameConfig = ctx.getConfiguration();
+ context = (LoggerContext) LogManager.getContext(false);
+ final Configuration sameConfig = context.getConfiguration();
assertTrue("Configuration should not have been reset", newConfig == sameConfig);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2dfddba0/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
index 72b9eb4..b295bc9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
@@ -16,20 +16,26 @@
*/
package org.apache.logging.log4j.core;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.util.Clock;
import org.apache.logging.log4j.core.util.ClockFactory;
+import org.apache.logging.log4j.core.util.ClockFactoryTest;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.junit.InitialLoggerContext;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.message.TimestampMessage;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.apache.logging.log4j.util.Strings;
-import org.junit.*;
-
-import java.util.List;
-
-import static org.junit.Assert.*;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
/**
* Confirms that if you log a {@link TimestampMessage} then there are no unnecessary calls to {@link Clock}.
@@ -54,9 +60,9 @@ public class TimestampMessageTest {
}
@AfterClass
- public static void afterClass() {
+ public static void afterClass() throws IllegalAccessException {
System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
- System.setProperty(ClockFactory.PROPERTY_NAME, Strings.EMPTY);
+ ClockFactoryTest.resetClocks();
}
@Test
@@ -71,6 +77,11 @@ public class TimestampMessageTest {
}
public static class PoisonClock implements Clock {
+ public PoisonClock() {
+ super();
+ // Breakpoint here for debuging.
+ }
+
@Override
public long currentTimeMillis() {
throw new RuntimeException("This should not have been called");
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2dfddba0/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
index 136a11b..39b4511 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
@@ -16,12 +16,20 @@
*/
package org.apache.logging.log4j.core.async;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LifeCycle;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.util.Clock;
import org.apache.logging.log4j.core.util.ClockFactory;
+import org.apache.logging.log4j.core.util.ClockFactoryTest;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.message.TimestampMessage;
@@ -30,12 +38,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-
-import static org.junit.Assert.*;
-
/**
* Confirms that if you log a {@link TimestampMessage} then there are no unnecessary calls to {@link Clock}.
* <p>
@@ -55,9 +57,9 @@ public class AsyncLoggerTimestampMessageTest {
}
@AfterClass
- public static void afterClass() {
+ public static void afterClass() throws IllegalAccessException {
System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
- System.setProperty(ClockFactory.PROPERTY_NAME, Strings.EMPTY);
+ ClockFactoryTest.resetClocks();
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2dfddba0/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 e6b4dde..bf3af14 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
@@ -28,6 +28,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.util.Clock;
import org.apache.logging.log4j.core.util.ClockFactory;
+import org.apache.logging.log4j.core.util.ClockFactoryTest;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.util.Strings;
@@ -60,8 +61,8 @@ public class Log4jLogEventTest {
}
@AfterClass
- public static void afterClass() {
- System.clearProperty(ClockFactory.PROPERTY_NAME);
+ public static void afterClass() throws IllegalAccessException {
+ ClockFactoryTest.resetClocks();
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2dfddba0/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
index 1b69a16..0e50b56 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
@@ -16,12 +16,35 @@
*/
package org.apache.logging.log4j.core.util;
-import org.junit.Test;
+import static org.junit.Assert.assertSame;
+
+import java.lang.reflect.Field;
-import static org.junit.Assert.*;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.logging.log4j.core.async.AsyncLogger;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.junit.AfterClass;
+import org.junit.Test;
public class ClockFactoryTest {
+ public static void resetClocks() throws IllegalAccessException {
+ resetClock(Log4jLogEvent.class);
+ resetClock(AsyncLogger.class);
+ }
+
+ public static void resetClock(Class<?> clazz) throws IllegalAccessException {
+ System.clearProperty(ClockFactory.PROPERTY_NAME);
+ Field field = FieldUtils.getField(clazz, "clock", true);
+ FieldUtils.removeFinalModifier(field, true);
+ FieldUtils.writeStaticField(field, ClockFactory.getClock(), false);
+ }
+
+ @AfterClass
+ public static void afterClass() throws IllegalAccessException {
+ resetClocks();
+ }
+
@Test
public void testDefaultIsSystemClock() {
System.clearProperty(ClockFactory.PROPERTY_NAME);