Search in sources :

Example 1 with TracingBroker

use of org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker in project controller 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();
    BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
    TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
    DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
    DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
    DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    boolean printReturnValue = tracingBroker.printOpenTransactions(ps);
    String output = new String(baos.toByteArray(), UTF_8);
    assertThat(printReturnValue).isTrue();
    // Assert expections 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;
    }
// 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 : PrintStream(java.io.PrintStream) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) 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) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TracingBroker(org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Test (org.junit.Test)1 DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)1 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)1 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)1 TracingBroker (org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker)1 BindingNormalizedNodeSerializer (org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer)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