use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testReadWriteTransactionWithMultipleShards.
@Test
public void testReadWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
doCommit(readWriteTx.ready());
readWriteTx = dataStore.newReadWriteTransaction();
readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
doCommit(readWriteTx.ready());
readWriteTx = dataStore.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.write(personPath, person);
final Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
assertEquals("exists", true, exists);
Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", car, optional.get());
doCommit(readWriteTx.ready());
// Verify the data in the store
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", car, optional.get());
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.DOMStoreReadWriteTransaction in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testTransactionChainWithMultipleShards.
@Test
public void testTransactionChainWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testTransactionChainWithMultipleShards");
final DOMStoreTransactionChain txChain = followerDistributedDataStore.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());
followerTestKit.doCommit(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(personPath);
final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
followerTestKit.doCommit(cohort2);
followerTestKit.doCommit(cohort3);
txChain.close();
final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
verifyCars(readTx, car);
optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", false, optional.isPresent());
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testReadWriteMessageSlicing.
@Test
public void testReadWriteMessageSlicing() throws Exception {
// The slicing is only implemented for tell-based protocol
Assume.assumeTrue(testParameter.equals(ClientBackedDataStore.class));
leaderDatastoreContextBuilder.maximumMessageSliceSize(100);
followerDatastoreContextBuilder.maximumMessageSliceSize(100);
initDatastoresWithCars("testLargeReadReplySlicing");
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
final NormalizedNode<?, ?> carsNode = CarsModel.create();
rwTx.write(CarsModel.BASE_PATH, carsNode);
verifyNode(rwTx, CarsModel.BASE_PATH, carsNode);
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testReadWriteTransactionWithMultipleShards.
@Test
public void testReadWriteTransactionWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testReadWriteTransactionWithMultipleShards");
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", rwTx);
final YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
final NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
rwTx.write(carsPath, carsNode);
final YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
final NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
rwTx.write(peoplePath, peopleNode);
followerTestKit.doCommit(rwTx.ready());
final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
verifyNode(readTx, carsPath, carsNode);
verifyNode(readTx, peoplePath, peopleNode);
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction 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);
}
Aggregations