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);
}
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());
}
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;
}
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;
}
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();
}
}
}
Aggregations