Bug 9060: Filter TracingBroker stack trace elements 32/62632/3
authorMichael Vorburger <vorburger@redhat.com>
Mon, 4 Sep 2017 15:24:49 +0000 (17:24 +0200)
committerStephen Kitt <skitt@redhat.com>
Thu, 7 Sep 2017 11:29:44 +0000 (11:29 +0000)
Just to make them a lot easier to read, because what is really
interesting in them is the "middle part" (before the trace close
tracking infra classes and after the lower level e.g. BP set up class
stack frames).

Change-Id: I5f90b69a10ec0ea3f3e3407279c523751813418d
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingBroker.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/test/java/org/opendaylight/controller/md/sal/trace/tests/CloseTrackedRegistryTest.java [moved from opendaylight/md-sal/mdsal-trace/dom-impl/src/test/java/org/opendaylight/controller/md/sal/trace/closetracker/impl/tests/CloseTrackedRegistryTest.java with 98% similarity]
opendaylight/md-sal/mdsal-trace/dom-impl/src/test/java/org/opendaylight/controller/md/sal/trace/tests/TracingBrokerTest.java [moved from opendaylight/md-sal/mdsal-trace/dom-impl/src/test/java/org/opendaylight/controller/md/sal/trace/closetracker/impl/tests/TracingBrokerTest.java with 92% similarity]

index 2150e28..84e8c02 100644 (file)
@@ -391,7 +391,7 @@ public class TracingBroker implements TracingDOMDataBroker {
         }
         entries.forEach(entry -> {
             ps.println("    " + entry.getNumberAddedNotRemoved() + "x TransactionChains opened but not closed here:");
-            entry.getStackTraceElements().forEach(line -> ps.println("      " + line));
+            printStackTraceElements(ps, "      ", entry.getStackTraceElements());
             @SuppressWarnings("resource")
             TracingTransactionChain txChain = (TracingTransactionChain) entry
                 .getExampleCloseTracked().getRealCloseTracked();
@@ -413,10 +413,33 @@ public class TracingBroker implements TracingDOMDataBroker {
         entries.forEach(entry -> {
             ps.println(indent + "  " + entry.getNumberAddedNotRemoved()
                 + "x transactions opened here, which are not closed:");
-            entry.getStackTraceElements().forEach(line -> ps.println(indent + "    " + line));
+            printStackTraceElements(ps, indent + "    ", entry.getStackTraceElements());
         });
         if (!entries.isEmpty()) {
             ps.println();
         }
     }
+
+    private void printStackTraceElements(PrintStream ps, String indent, List<StackTraceElement> stackTraceElements) {
+        stackTraceElements.forEach(line -> {
+            if (isStackTraceElementInteresting(line)) {
+                ps.println(indent + line);
+            } else {
+                ps.println(indent + "(...)");
+            }
+        });
+    }
+
+    private boolean isStackTraceElementInteresting(StackTraceElement element) {
+        final String className = element.getClassName();
+        return !className.startsWith(getClass().getPackage().getName())
+            && !className.startsWith(CloseTracked.class.getPackage().getName())
+            && !className.startsWith("Proxy")
+            && !className.startsWith("akka")
+            && !className.startsWith("scala")
+            && !className.startsWith("sun.reflect")
+            && !className.startsWith("java.lang.reflect")
+            && !className.startsWith("org.apache.aries.blueprint")
+            && !className.startsWith("org.osgi.util.tracker");
+    }
 }
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.controller.md.sal.trace.closetracker.impl.tests;
+package org.opendaylight.controller.md.sal.trace.tests;
 
 import static com.google.common.truth.Truth.assertThat;
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -48,7 +48,9 @@ public class TracingBrokerTest {
         String output = new String(baos.toByteArray(), UTF_8);
 
         assertThat(printReturnValue).isTrue();
-        assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java:41)"); // in a stack trace
+        // Assert expections about stack trace
+        assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java:41)");
+        assertThat(output).doesNotContain(TracingBroker.class.getName());
 
         // We don't do any verify/times on the mocks,
         // because the main point of the test is just to verify that

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.