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 02e65e7754e129b8280fac6e2e62ad5ebfefa44c..9d966082acaff0971f79e02c8c1a7cb816859965 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) {
 
     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());
         }
         if (!entries.isEmpty()) {
             ps.println(indent + registry.getAnchor() + " : " + registry.getCreateDescription());
         }
index 63629f6c8c06c96cf263e5e3950ad1613bc78bd3..d0731da03838d1952a602b239a7f2d418a25dcde 100644 (file)
@@ -38,7 +38,11 @@ public class TracingBrokerTest {
         BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
         TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
 
         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();
 
         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();
         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());
 
         assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
         assertThat(output).doesNotContain(TracingBroker.class.getName());
 
@@ -60,6 +64,9 @@ public class TracingBrokerTest {
             previousLine = line;
         }
 
             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
         // 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