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).
}
Aggregations