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 84e8c02fadebd426587b71d18cb7b7a691e72686..2aa7457ee2a6bd0ce5b4350ea3fe0fdb95164d8d 100644 (file)
@@ -421,13 +421,16 @@ public class TracingBroker implements TracingDOMDataBroker {
     }
 
     private void printStackTraceElements(PrintStream ps, String indent, List<StackTraceElement> stackTraceElements) {
     }
 
     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 + "(...)");
                 ps.println(indent + "(...)");
+                ellipsis = true;
             }
             }
-        });
+        }
     }
 
     private boolean isStackTraceElementInteresting(StackTraceElement element) {
     }
 
     private boolean isStackTraceElementInteresting(StackTraceElement element) {
index 3179b2a20d5957a6fe6cfa7de3b7890c9a7a4b81..63629f6c8c06c96cf263e5e3950ad1613bc78bd3 100644 (file)
@@ -49,9 +49,17 @@ public class TracingBrokerTest {
 
         assertThat(printReturnValue).isTrue();
         // Assert expections about stack trace
 
         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());
 
         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
         // 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