sort by descending number of suspected transaction leaks in trace output 62/72362/2
authorMichael Vorburger <vorburger@redhat.com>
Mon, 28 May 2018 11:56:34 +0000 (13:56 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Tue, 29 May 2018 01:32:04 +0000 (01:32 +0000)
Change-Id: I7b780c3df72f87f6f1e693e9ec995a8f48da5c3b
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/TracingBrokerTest.java

index 02e65e7..9d96608 100644 (file)
@@ -410,7 +410,11 @@ public class TracingBroker implements TracingDOMDataBroker {
 
     private <T extends CloseTracked<T>> void printRegistryOpenTransactions(
             CloseTrackedRegistry<T> registry, PrintStream ps, String indent) {
-        Set<CloseTrackedRegistryReportEntry<T>> entries = registry.getAllUnique();
+        Set<CloseTrackedRegistryReportEntry<T>> unsorted = registry.getAllUnique();
+
+        List<CloseTrackedRegistryReportEntry<T>> entries = new ArrayList<>(unsorted);
+        entries.sort((o1, o2) -> Long.compare(o2.getNumberAddedNotRemoved(), o1.getNumberAddedNotRemoved()));
+
         if (!entries.isEmpty()) {
             ps.println(indent + registry.getAnchor() + " : " + registry.getCreateDescription());
         }
index 63629f6..d0731da 100644 (file)
@@ -38,7 +38,11 @@ public class TracingBrokerTest {
         BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
         TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
 
-        DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
+        for (int i = 0; i < 3; i++) {
+            DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
+        }
+        DOMDataReadWriteTransaction anotherTx = tracingBroker.newReadWriteTransaction();
+
         DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
         DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
 
@@ -48,7 +52,7 @@ public class TracingBrokerTest {
         String output = new String(baos.toByteArray(), UTF_8);
 
         assertThat(printReturnValue).isTrue();
-        // Assert expections about stack trace
+        // Assert expectations about stack trace
         assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
         assertThat(output).doesNotContain(TracingBroker.class.getName());
 
@@ -60,6 +64,9 @@ public class TracingBrokerTest {
             previousLine = line;
         }
 
+        // assert that the sorting works - the x3 is shown before the x1
+        assertThat(output).contains("  DataBroker : newReadWriteTransaction()\n    3x");
+
         // 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.