use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testTransactionChainWithSingleShard.
@Test
public void testTransactionChainWithSingleShard() throws Exception {
initDatastoresWithCars("testTransactionChainWithSingleShard");
final DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
// Add the top-level cars container with write-only.
final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
final DOMStoreThreePhaseCommitCohort writeTxReady = writeTx.ready();
// Verify the top-level cars container with read-only.
verifyNode(txChain.newReadOnlyTransaction(), CarsModel.BASE_PATH, CarsModel.emptyContainer());
// Perform car operations with read-write.
final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
verifyNode(rwTx, CarsModel.BASE_PATH, CarsModel.emptyContainer());
rwTx.merge(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
final YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
rwTx.write(car1Path, car1);
verifyExists(rwTx, car1Path);
verifyCars(rwTx, car1);
final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
rwTx.merge(CarsModel.newCarPath("sportage"), car2);
rwTx.delete(car1Path);
followerTestKit.doCommit(writeTxReady);
followerTestKit.doCommit(rwTx.ready());
txChain.close();
verifyCars(followerDistributedDataStore.newReadOnlyTransaction(), car2);
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class DOMBrokerTransactionChain method close.
@Override
public void close() {
final boolean success = STATE_UPDATER.compareAndSet(this, State.RUNNING, State.CLOSING);
if (!success) {
LOG.debug("Chain {} is no longer running", this);
return;
}
super.close();
for (DOMStoreTransactionChain subChain : getTxFactories().values()) {
subChain.close();
}
if (counter == 0) {
finishClose();
}
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class ClientBackedDataStoreTest method testCreateTransactionChain.
@Test
public void testCreateTransactionChain() throws Exception {
try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(actorContext, UNKNOWN_ID, clientActor)) {
final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
Assert.assertNotNull(txChain);
Mockito.verify(clientActor, Mockito.times(1)).createLocalHistory();
}
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class ConcurrentDOMDataBrokerTest method testCreateTransactionOnChain.
@Test
public void testCreateTransactionOnChain() {
DOMStore domStore = mock(DOMStore.class);
try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor)) {
DOMStoreReadWriteTransaction operationalTransaction = mock(DOMStoreReadWriteTransaction.class);
DOMStoreTransactionChain mockChain = mock(DOMStoreTransactionChain.class);
doReturn(mockChain).when(domStore).createTransactionChain();
doReturn(operationalTransaction).when(mockChain).newWriteOnlyTransaction();
DOMTransactionChain transactionChain = dataBroker.createTransactionChain(mock(TransactionChainListener.class));
DOMDataTreeWriteTransaction domDataWriteTransaction = transactionChain.newWriteOnlyTransaction();
verify(mockChain, never()).newWriteOnlyTransaction();
domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
}
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testCreateChainedTransactionAfterEmptyTxReadied.
@Test
public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
final DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
rwTx1.ready();
final DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
final Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", false, optional.isPresent());
txChain.close();
}
}
};
}
Aggregations