Repository: logging-log4j2 Updated Branches: refs/heads/master 7fafa3cd8 -> b679156b2
LOG4J2-1349 better gc-free test Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ae887b32 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ae887b32 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ae887b32 Branch: refs/heads/master Commit: ae887b32b5dfe63d1f0f6c70ca6e0833e056f46c Parents: 7fafa3c Author: rpopma <[email protected]> Authored: Wed Sep 28 07:33:39 2016 +0900 Committer: rpopma <[email protected]> Committed: Wed Sep 28 07:33:39 2016 +0900 ---------------------------------------------------------------------- .../apache/logging/log4j/core/GcFreeLoggingTestUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ae887b32/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 aa6801a..51a0b96 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 @@ -58,7 +58,6 @@ public class GcFreeLoggingTestUtil { // initialize LoggerContext etc. // This is not steady-state logging and will allocate objects. - ThreadContext.put("aKey", "value1"); ThreadContext.put("key2", "value2"); @@ -70,6 +69,8 @@ public class GcFreeLoggingTestUtil { for (int i = 0; i < 256; i++) { logger.debug("ensure all ringbuffer slots have been used once"); // allocate MutableLogEvent.messageText } + ThreadContext.remove("aKey"); + ThreadContext.remove("key2"); // BlockingWaitStrategy uses ReentrantLock which allocates Node objects. Ignore this. final String[] exclude = new String[] { @@ -102,6 +103,10 @@ public class GcFreeLoggingTestUtil { AllocationRecorder.addSampler(sampler); // now do some steady-state logging + + ThreadContext.put("aKey", "value1"); + ThreadContext.put("key2", "value2"); + final int ITERATIONS = 5; for (int i = 0; i < ITERATIONS; i++) { logger.error(myCharSeq); @@ -110,6 +115,8 @@ public class GcFreeLoggingTestUtil { logger.error("Test parameterized message {}", "param"); logger.error("Test parameterized message {}{}", "param", "param2"); logger.error("Test parameterized message {}{}{}", "param", "param2", "abc"); + ThreadContext.remove("aKey"); + ThreadContext.put("aKey", "value1"); } Thread.sleep(50); samplingEnabled.set(false); // reliably ignore all allocations from now on
