TracingBroker: collapse ellipses 29/62829/5
authorStephen Kitt <skitt@redhat.com>
Thu, 7 Sep 2017 11:38:14 +0000 (13:38 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Mon, 25 Sep 2017 19:40:33 +0000 (19:40 +0000)
This avoids printing multiple "(...)" lines in succession.

(The test is made a little more change-resistant by removing the
expected line number.)

Change-Id: I9ede5d0d15afecb06c61cbe2b2c5a70967616280
Signed-off-by: Stephen Kitt <skitt@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/TracingBrokerTest.java

index 84e8c02..2aa7457 100644 (file)
@@ -421,13 +421,16 @@ public class TracingBroker implements TracingDOMDataBroker {
     }
 
     private void printStackTraceElements(PrintStream ps, String indent, List<StackTraceElement> stackTraceElements) {
-        stackTraceElements.forEach(line -> {
-            if (isStackTraceElementInteresting(line)) {
-                ps.println(indent + line);
-            } else {
+        boolean ellipsis = false;
+        for (final StackTraceElement stackTraceElement : stackTraceElements) {
+            if (isStackTraceElementInteresting(stackTraceElement)) {
+                ps.println(indent + stackTraceElement);
+                ellipsis = false;
+            } else if (!ellipsis) {
                 ps.println(indent + "(...)");
+                ellipsis = true;
             }
-        });
+        }
     }
 
     private boolean isStackTraceElementInteresting(StackTraceElement element) {
index 3179b2a..63629f6 100644 (file)
@@ -49,9 +49,17 @@ public class TracingBrokerTest {
 
         assertThat(printReturnValue).isTrue();
         // Assert expections about stack trace
-        assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java:41)");
+        assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
         assertThat(output).doesNotContain(TracingBroker.class.getName());
 
+        String previousLine = "";
+        for (String line : output.split("\n")) {
+            if (line.contains("(...")) {
+                assertThat(previousLine.contains("(...)")).isFalse();
+            }
+            previousLine = line;
+        }
+
         // We don't do any verify/times on the mocks,
         // because the main point of the test is just to verify that
         // printOpenTransactions runs through without any exceptions

©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.