You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/18 16:42:49 UTC

logging-log4j2 git commit: LOG4J2-1295 fix garbage-free unit test: stop printing allocations after we're done with logging test

Repository: logging-log4j2
Updated Branches:
  refs/heads/master c989349ef -> 4c01f1cdb


LOG4J2-1295 fix garbage-free unit test: stop printing allocations after we're done with logging 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/4c01f1cd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4c01f1cd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4c01f1cd

Branch: refs/heads/master
Commit: 4c01f1cdbcc7486617b39a1686850f9211978029
Parents: c989349
Author: rpopma <rp...@apache.org>
Authored: Mon Apr 18 23:42:52 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Mon Apr 18 23:42:52 2016 +0900

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java   | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4c01f1cd/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 e6517ed..ead935e 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
@@ -21,6 +21,7 @@ import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.logging.log4j.*;
 import org.apache.logging.log4j.core.util.Constants;
@@ -66,9 +67,13 @@ public class GcFreeLoggingTestUtil {
                 "java/util/concurrent/locks/AbstractQueuedSynchronizer$Node", //
                 "com/google/monitoring/runtime/instrumentation/Sampler", //
         };
+        final AtomicBoolean samplingEnabled = new AtomicBoolean(true);
         final Sampler sampler = new Sampler() {
             @Override
             public void sampleAllocation(int count, String desc, Object newObj, long size) {
+                if (!samplingEnabled.get()) {
+                    return;
+                }
                 for (int i = 0; i < exclude.length; i++) {
                     if (exclude[i].equals(desc)) {
                         return; // exclude
@@ -98,6 +103,7 @@ public class GcFreeLoggingTestUtil {
             logger.error("Test parameterized message {}{}{}", "param", "param2", "abc");
         }
         Thread.sleep(50);
+        samplingEnabled.set(false); // reliably ignore all allocations from now on
         AllocationRecorder.removeSampler(sampler);
         Thread.sleep(100);
     }