use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction 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.DOMDataReadTransaction in project controller by opendaylight.
the class DOMBrokerPerformanceTest method measureSeparateWritesOneLevel.
private void measureSeparateWritesOneLevel(final int txNum, final int innerNum) throws Exception {
final List<DOMDataReadWriteTransaction> transactions = measure("Txs:" + txNum + " Allocate", () -> {
List<DOMDataReadWriteTransaction> builder = new ArrayList<>(txNum);
for (int i = 0; i < txNum; i++) {
DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
builder.add(writeTx);
}
return builder;
});
assertEquals(txNum, transactions.size());
measure("Txs:" + txNum + " Writes:1", (Callable<Void>) () -> {
int index = 0;
for (DOMDataReadWriteTransaction writeTx : transactions) {
// Writes /test/outer-list/i in writeTx
writeTx.put(OPERATIONAL, outerListPath(index), outerList(index));
index++;
}
return null;
});
measure("Txs:" + txNum + " Writes:" + innerNum, (Callable<Void>) () -> {
int index = 0;
for (DOMDataReadWriteTransaction writeTx : transactions) {
// Writes /test/outer-list/i in writeTx
YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(index)).node(TestModel.INNER_LIST_QNAME).build();
writeTx.put(OPERATIONAL, path, ImmutableNodes.mapNodeBuilder(TestModel.INNER_LIST_QNAME).build());
for (int j = 0; j < innerNum; j++) {
YangInstanceIdentifier innerPath = YangInstanceIdentifier.builder(path).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
writeTx.put(OPERATIONAL, innerPath, ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)));
}
index++;
}
return null;
});
measure("Txs:" + txNum + " Submit, Finish", (Callable<Void>) () -> {
List<ListenableFuture<?>> allFutures = measure(txNum + " Submits", () -> {
List<ListenableFuture<?>> builder = new ArrayList<>(txNum);
for (DOMDataReadWriteTransaction tx : transactions) {
builder.add(tx.submit());
}
return builder;
});
Futures.allAsList(allFutures).get();
return null;
});
final DOMDataReadTransaction readTx = measure("Txs:1 (ro), Allocate", (Callable<DOMDataReadTransaction>) () -> domBroker.newReadOnlyTransaction());
measure("Txs:1 (ro) Reads:" + txNum + " (1-level)", (Callable<Void>) () -> {
for (int i = 0; i < txNum; i++) {
ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, outerListPath(i));
assertTrue("outerList/" + i, potential.get().isPresent());
}
return null;
});
measure("Txs:1 (ro) Reads:" + txNum * innerNum + " (2-level)", (Callable<Void>) () -> {
for (int i = 0; i < txNum; i++) {
for (int j = 0; j < innerNum; j++) {
YangInstanceIdentifier path = YangInstanceIdentifier.builder(outerListPath(i)).node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, String.valueOf(j)).build();
ListenableFuture<Optional<NormalizedNode<?, ?>>> potential = readTx.read(OPERATIONAL, path);
assertTrue("outer-list/" + i + "/inner-list/" + j, potential.get().isPresent());
}
}
return null;
});
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction 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());
}
Aggregations