Search in sources :

Example 16 with DOMDataReadWriteTransaction

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

the class DOMBrokerTest method testRejectedCommit.

@Test(expected = TransactionCommitFailedException.class)
public void testRejectedCommit() throws Exception {
    commitExecutor.delegate = Mockito.mock(ExecutorService.class);
    Mockito.doThrow(new RejectedExecutionException("mock")).when(commitExecutor.delegate).execute(Mockito.any(Runnable.class));
    Mockito.doNothing().when(commitExecutor.delegate).shutdown();
    Mockito.doReturn(Collections.emptyList()).when(commitExecutor.delegate).shutdownNow();
    Mockito.doReturn("").when(commitExecutor.delegate).toString();
    Mockito.doReturn(true).when(commitExecutor.delegate).awaitTermination(Mockito.anyLong(), Mockito.any(TimeUnit.class));
    DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
    writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) ForwardingExecutorService(com.google.common.util.concurrent.ForwardingExecutorService) ExecutorService(java.util.concurrent.ExecutorService) DeadlockDetectingListeningExecutorService(org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TimeUnit(java.util.concurrent.TimeUnit) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 17 with DOMDataReadWriteTransaction

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

the class DOMBrokerTest method testTransactionIsolation.

@Test(timeout = 10000)
public void testTransactionIsolation() throws InterruptedException, ExecutionException {
    assertNotNull(domBroker);
    DOMDataReadTransaction readTx = domBroker.newReadOnlyTransaction();
    assertNotNull(readTx);
    DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
    assertNotNull(writeTx);
    /**
     * Writes /test in writeTx
     */
    writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    /**
     * Reads /test from writeTx Read should return container.
     */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(OPERATIONAL, TestModel.TEST_PATH);
    assertTrue(writeTxContainer.get().isPresent());
    /**
     * Reads /test from readTx Read should return Absent.
     */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> readTxContainer = readTx.read(OPERATIONAL, TestModel.TEST_PATH);
    assertFalse(readTxContainer.get().isPresent());
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Optional(com.google.common.base.Optional) DOMDataReadTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction) Test(org.junit.Test)

Example 18 with DOMDataReadWriteTransaction

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

the class PingPongTransactionChain method newReadWriteTransaction.

@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
    final PingPongTransaction tx = allocateTransaction();
    final DOMDataReadWriteTransaction ret = new ForwardingDOMDataReadWriteTransaction() {

        private boolean isOpen = true;

        @Override
        protected DOMDataReadWriteTransaction delegate() {
            return tx.getTransaction();
        }

        @Override
        public CheckedFuture<Void, TransactionCommitFailedException> submit() {
            readyTransaction(tx);
            isOpen = false;
            return tx.getSubmitFuture();
        }

        @Override
        public boolean cancel() {
            if (isOpen) {
                cancelTransaction(tx, this);
                isOpen = false;
                return true;
            } else {
                return false;
            }
        }
    };
    tx.recordFrontendTransaction(ret);
    return ret;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) ForwardingDOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction) ForwardingDOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)

Example 19 with DOMDataReadWriteTransaction

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

the class PingPongTransactionChain method slowAllocateTransaction.

private synchronized PingPongTransaction slowAllocateTransaction() {
    Preconditions.checkState(shutdownTx == null, "Transaction chain %s has been shut down", this);
    if (deadTx != null) {
        throw new IllegalStateException(String.format("Transaction chain %s has failed due to transaction %s being canceled", this, deadTx.getKey()), deadTx.getValue());
    }
    final DOMDataReadWriteTransaction delegateTx = delegate.newReadWriteTransaction();
    final PingPongTransaction newTx = new PingPongTransaction(delegateTx);
    if (!LOCKED_UPDATER.compareAndSet(this, null, newTx)) {
        delegateTx.cancel();
        throw new IllegalStateException(String.format("New transaction %s raced with transaction %s", newTx, lockedTx));
    }
    return newTx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) ForwardingDOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)

Example 20 with DOMDataReadWriteTransaction

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

the class PingPongTransactionChain method delegateFailed.

void delegateFailed(final TransactionChain<?, ?> chain, final Throwable cause) {
    final DOMDataReadWriteTransaction frontend;
    final PingPongTransaction tx = inflightTx;
    if (tx == null) {
        LOG.warn("Transaction chain {} failed with no pending transactions", chain);
        frontend = null;
    } else {
        frontend = tx.getFrontendTransaction();
    }
    listener.onTransactionChainFailed(this, frontend, cause);
    synchronized (this) {
        failed = true;
        /*
             * If we do not have a locked transaction, we need to ensure that
             * the backend transaction is cancelled. Otherwise we can defer
             * until the user calls us.
             */
        if (lockedTx == null) {
            processIfReady();
        }
    }
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) ForwardingDOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction)

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