use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testChainWithReadOnlyTxAfterPreviousReady.
@Test
public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
// Create a write tx and submit.
final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// Create read-only tx's and issue a read.
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
// Create another write tx and issue the write.
DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
writeTx2.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
// Ensure the reads succeed.
assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
// Ensure the writes succeed.
DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
doCommit(cohort1);
doCommit(cohort2);
assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH).checkedGet(5, TimeUnit.SECONDS).isPresent());
}
}
};
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionChainWithMultipleShards.
@Test
public void testTransactionChainWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
final DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
readWriteTx.write(carPath, car);
final MapEntryNode person = PeopleModel.newPersonEntry("jack");
final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
readWriteTx.merge(personPath, person);
Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", car, optional.get());
optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", person, optional.get());
final DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
writeTx = txChain.newWriteOnlyTransaction();
writeTx.delete(carPath);
final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
final ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
final ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
doCommit(canCommit1, cohort1);
doCommit(canCommit2, cohort2);
doCommit(cohort3);
txChain.close();
final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", false, optional.isPresent());
optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", person, optional.get());
}
}
};
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
ConcurrentDOMDataBroker backendBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL, mockOperStore, org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION, mockConfigStore), MoreExecutors.newDirectExecutorService());
adapter = new LegacyDOMDataBrokerAdapter(backendBroker);
doReturn(Futures.immediateFuture(Boolean.TRUE)).when(mockCommitCohort).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).preCommit();
doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).commit();
doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).abort();
dataNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doReturn(mockWriteTx).when(mockConfigStore).newWriteOnlyTransaction();
doNothing().when(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
doNothing().when(mockWriteTx).merge(TestModel.TEST_PATH, dataNode);
doNothing().when(mockWriteTx).delete(TestModel.TEST_PATH);
doNothing().when(mockWriteTx).close();
doReturn(mockCommitCohort).when(mockWriteTx).ready();
doReturn(mockReadTx).when(mockConfigStore).newReadOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(Optional.of(dataNode))).when(mockReadTx).read(TestModel.TEST_PATH);
doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(mockReadTx).exists(TestModel.TEST_PATH);
doReturn(mockReadWriteTx).when(mockConfigStore).newReadWriteTransaction();
doNothing().when(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
doReturn(mockCommitCohort).when(mockReadWriteTx).ready();
doReturn(Futures.immediateCheckedFuture(Optional.of(dataNode))).when(mockReadWriteTx).read(TestModel.TEST_PATH);
DOMStoreTransactionChain mockTxChain = mock(DOMStoreTransactionChain.class);
doReturn(mockReadTx).when(mockTxChain).newReadOnlyTransaction();
doReturn(mockWriteTx).when(mockTxChain).newWriteOnlyTransaction();
doReturn(mockReadWriteTx).when(mockTxChain).newReadWriteTransaction();
doReturn(mockTxChain).when(mockConfigStore).createTransactionChain();
doReturn(mock(DOMStoreTransactionChain.class)).when(mockOperStore).createTransactionChain();
}
Aggregations