Search in sources :

Example 1 with TracingBroker

use of org.opendaylight.mdsal.trace.impl.TracingBroker in project mdsal by opendaylight.

the class TracingBrokerTest method testPrintOpenTransactions.

@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
    DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
    Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
    BindingCodecTree codec = mock(BindingCodecTree.class);
    TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
    for (int i = 0; i < 3; i++) {
        DOMDataTreeReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
    }
    DOMDataTreeReadWriteTransaction anotherTx = tracingBroker.newReadWriteTransaction();
    DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
    DOMDataTreeReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    boolean printReturnValue = tracingBroker.printOpenTransactions(ps, 1);
    String output = new String(baos.toByteArray(), UTF_8);
    assertThat(printReturnValue).isTrue();
    // Assert expectations about stack trace
    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;
    }
    // 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
// (e.g. it used to have a ClassCastException).
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) PrintStream(java.io.PrintStream) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config) ConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.ConfigBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TracingBroker(org.opendaylight.mdsal.trace.impl.TracingBroker) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) BindingCodecTree(org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Test (org.junit.Test)1 BindingCodecTree (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree)1 DOMDataBroker (org.opendaylight.mdsal.dom.api.DOMDataBroker)1 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)1 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)1 TracingBroker (org.opendaylight.mdsal.trace.impl.TracingBroker)1 Config (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config)1 ConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.ConfigBuilder)1