Search in sources :

Example 21 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadWriteTransaction.

@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
    final Object readWriteTxId = newTransactionIdentifier();
    final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
    final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(readWriteTxId, readTxDelegate);
    final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
    final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(readWriteTxId, writeTxDelegate);
    final DOMDataReadWriteTransaction readWriteTx = new ShardedDOMDataBrokerDelegatingReadWriteTransaction(readWriteTxId, schemaContext, readTx, writeTx);
    transactionMap.put(readTxDelegate.getIdentifier(), readWriteTx);
    transactionMap.put(writeTxDelegate.getIdentifier(), readWriteTx);
    return readWriteTx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 22 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction 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)

Example 23 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testTransactionChain.

@SuppressWarnings("rawtypes")
@Test
public void testTransactionChain() throws Exception {
    TransactionChainListener mockListener = mock(TransactionChainListener.class);
    doNothing().when(mockListener).onTransactionChainSuccessful(anyObject());
    doNothing().when(mockListener).onTransactionChainFailed(anyObject(), anyObject(), anyObject());
    DOMTransactionChain chain = adapter.createTransactionChain(mockListener);
    // Test read-only tx
    DOMDataReadOnlyTransaction readTx = chain.newReadOnlyTransaction();
    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    // Test write-only tx
    DOMDataWriteTransaction writeTx = chain.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
    submitFuture.get(5, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(mockCommitCohort);
    inOrder.verify(mockCommitCohort).canCommit();
    inOrder.verify(mockCommitCohort).preCommit();
    inOrder.verify(mockCommitCohort).commit();
    // Test read-write tx
    DOMDataReadWriteTransaction readWriteTx = chain.newReadWriteTransaction();
    readFuture = readWriteTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    chain.close();
    verify(mockListener).onTransactionChainSuccessful(chain);
    // Test failed chain
    doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException("mock", (Throwable) null))).when(mockCommitCohort).canCommit();
    chain = adapter.createTransactionChain(mockListener);
    writeTx = chain.newWriteOnlyTransaction();
    try {
        writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (TransactionCommitFailedException e) {
    // expected
    }
    ArgumentCaptor<AsyncTransaction> failedTx = ArgumentCaptor.forClass(AsyncTransaction.class);
    verify(mockListener).onTransactionChainFailed(eq(chain), failedTx.capture(), any(TransactionCommitFailedException.class));
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 24 with DOMDataReadWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testReadWriteTransaction.

@Test
public void testReadWriteTransaction() throws Exception {
    DOMDataReadWriteTransaction tx = adapter.newReadWriteTransaction();
    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
    assertEquals("isPresent", true, readOptional.isPresent());
    assertEquals("NormalizedNode", dataNode, readOptional.get());
    tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
    submitFuture.get(5, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(mockCommitCohort);
    inOrder.verify(mockCommitCohort).canCommit();
    inOrder.verify(mockCommitCohort).preCommit();
    inOrder.verify(mockCommitCohort).commit();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)24 Test (org.junit.Test)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 Optional (com.google.common.base.Optional)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)4 TransactionChainListener (org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)3 DOMDataReadTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction)3 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)3 ForwardingDOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InOrder (org.mockito.InOrder)2 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)2 DOMDataBroker (org.opendaylight.controller.md.sal.dom.api.DOMDataBroker)2