use of org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain in project controller by opendaylight.
the class DOMTransactionChainTest method testTransactionChainNoConflict.
@Test
public void testTransactionChainNoConflict() throws InterruptedException, ExecutionException, TimeoutException {
BlockingTransactionChainListener listener = new BlockingTransactionChainListener();
DOMTransactionChain txChain = domBroker.createTransactionChain(listener);
assertNotNull(txChain);
/**
* We alocate new read-write transaction and write /test.
*/
DOMDataReadWriteTransaction firstTx = allocateAndWrite(txChain);
/**
* First transaction is marked as ready, we are able to allocate chained
* transactions.
*/
ListenableFuture<Void> firstWriteTxFuture = firstTx.submit();
/**
* We alocate chained transaction - read transaction.
*/
DOMDataReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
/**
* We test if we are able to read data from tx, read should not fail
* since we are using chained transaction.
*/
assertTestContainerExists(secondReadTx);
/**
* We alocate next transaction, which is still based on first one, but
* is read-write.
*/
DOMDataReadWriteTransaction thirdDeleteTx = allocateAndDelete(txChain);
/**
* We commit first transaction.
*/
assertCommitSuccessful(firstWriteTxFuture);
/**
* Allocates transaction from data store.
*/
DOMDataReadTransaction storeReadTx = domBroker.newReadOnlyTransaction();
/**
* We verify transaction is commited to store, container should exists
* in datastore.
*/
assertTestContainerExists(storeReadTx);
/**
* third transaction is sealed and commited.
*/
ListenableFuture<Void> thirdDeleteTxFuture = thirdDeleteTx.submit();
assertCommitSuccessful(thirdDeleteTxFuture);
/**
* We close transaction chain.
*/
txChain.close();
listener.getSuccessFuture().get(1000, TimeUnit.MILLISECONDS);
}
use of org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain in project controller by opendaylight.
the class DOMTransactionChainTest method testTransactionChainNotSealed.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionChainNotSealed() throws InterruptedException, ExecutionException, TimeoutException {
BlockingTransactionChainListener listener = new BlockingTransactionChainListener();
DOMTransactionChain txChain = domBroker.createTransactionChain(listener);
assertNotNull(txChain);
/**
* We alocate new read-write transaction and write /test
*/
allocateAndWrite(txChain);
/**
* We alocate chained transaction - read transaction, note first one is
* still not commited to datastore, so this allocation should fail with
* IllegalStateException.
*/
try {
txChain.newReadOnlyTransaction();
fail("Allocation of secondReadTx should fail with IllegalStateException");
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
}
}
use of org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain in project controller by opendaylight.
the class TxchainDomWrite method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (MapEntryNode element : this.list) {
YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
if (oper == StartTestInput.Operation.PUT) {
tx.put(dsType, yid, element);
} else {
tx.merge(dsType, yid, element);
}
writeCnt++;
// Start performing the operation; submit the transaction at every n-th operation
if (writeCnt == writesPerTx) {
txSubmitted++;
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
txOk++;
}
@Override
public void onFailure(final Throwable t) {
LOG.error("Transaction failed, {}", t);
txError++;
}
});
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
try {
txSubmitted++;
tx.submit().checkedGet();
txOk++;
} catch (final TransactionCommitFailedException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
}
use of org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain in project controller by opendaylight.
the class TxchainDomDelete method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (int l = 0; l < outerListElem; l++) {
YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
tx.delete(dsType, yid);
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
txOk++;
}
@Override
public void onFailure(final Throwable t) {
LOG.error("Transaction failed, {}", t);
txError++;
}
});
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the transaction chain before closing it
try {
txSubmitted++;
tx.submit().checkedGet();
txOk++;
} catch (final TransactionCommitFailedException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
}
use of org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapter method createTransactionChain.
@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
AtomicReference<DOMTransactionChain> legacyChain = new AtomicReference<>();
org.opendaylight.mdsal.common.api.TransactionChainListener delegateListener = new org.opendaylight.mdsal.common.api.TransactionChainListener() {
@SuppressWarnings("rawtypes")
@Override
public void onTransactionChainFailed(final org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain, final org.opendaylight.mdsal.common.api.AsyncTransaction<?, ?> transaction, final Throwable cause) {
listener.onTransactionChainFailed(legacyChain.get(), (AsyncTransaction) () -> transaction.getIdentifier(), cause instanceof Exception ? SUBMIT_EX_MAPPER.apply((Exception) cause) : cause);
}
@Override
public void onTransactionChainSuccessful(org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain) {
listener.onTransactionChainSuccessful(legacyChain.get());
}
};
final org.opendaylight.mdsal.dom.api.DOMTransactionChain delegateChain = delegate().createTransactionChain(delegateListener);
legacyChain.set(new DOMTransactionChain() {
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
return new DOMDataReadOnlyTransactionAdapter(delegateChain.newReadOnlyTransaction());
}
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newReadWriteTransaction());
}
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newWriteOnlyTransaction());
}
@Override
public void close() {
delegateChain.close();
}
});
return legacyChain.get();
}
Aggregations