use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testWriteTransactionWithMultipleShards.
@Test
public void testWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
doCommit(writeTx.ready());
writeTx = dataStore.newWriteOnlyTransaction();
writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
doCommit(writeTx.ready());
writeTx = dataStore.newWriteOnlyTransaction();
final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
writeTx.write(carPath, car);
final MapEntryNode person = PeopleModel.newPersonEntry("jack");
final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
writeTx.write(personPath, person);
doCommit(writeTx.ready());
// Verify the data in the store
final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> 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.yangtools.yang.data.api.schema.MapEntryNode 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.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testForwardedReadyTransactionForwardedToLeader.
@SuppressWarnings("unchecked")
@Test
public void testForwardedReadyTransactionForwardedToLeader() throws Exception {
initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
// Send a tx with immediate commit.
DataTreeModification modification = dataTree.takeSnapshot().newModification();
new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx1, modification), true);
carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
Object resp = followerTestKit.expectMsgClass(Object.class);
if (resp instanceof akka.actor.Status.Failure) {
throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
}
assertEquals("Response type", CommitTransactionReply.class, resp.getClass());
verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);
// Send another tx without immediate commit.
modification = dataTree.takeSnapshot().newModification();
MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);
forwardedReady = new ForwardedReadyTransaction(tx2, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx2, modification), false);
carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
resp = followerTestKit.expectMsgClass(Object.class);
if (resp instanceof akka.actor.Status.Failure) {
throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
}
assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());
ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(((ReadyTransactionReply) resp).getCohortPath());
final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(leaderDistributedDataStore.getActorContext(), Arrays.asList(new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
cohort.canCommit().get(5, TimeUnit.SECONDS);
cohort.preCommit().get(5, TimeUnit.SECONDS);
cohort.commit().get(5, TimeUnit.SECONDS);
verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode 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.yangtools.yang.data.api.schema.MapEntryNode 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