use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testReadyLocalTransactionForwardedToLeader.
@SuppressWarnings("unchecked")
@Test
public void testReadyLocalTransactionForwardedToLeader() throws Exception {
initDatastoresWithCars("testReadyLocalTransactionForwardedToLeader");
followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
// 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);
modification.ready();
ReadyLocalTransaction readyLocal = new ReadyLocalTransaction(tx1, modification, true);
carsFollowerShard.get().tell(readyLocal, 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);
modification.ready();
readyLocal = new ReadyLocalTransaction(tx2, modification, false);
carsFollowerShard.get().tell(readyLocal, 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());
final ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(((ReadyTransactionReply) resp).getCohortPath());
final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
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 testReadWriteTransactionWithSingleShard.
@Test
public void testReadWriteTransactionWithSingleShard() throws Exception {
initDatastoresWithCars("testReadWriteTransactionWithSingleShard");
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", rwTx);
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
rwTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
rwTx.merge(CarsModel.newCarPath("optima"), car1);
verifyCars(rwTx, car1);
final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
final YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
rwTx.merge(car2Path, car2);
verifyExists(rwTx, car2Path);
followerTestKit.doCommit(rwTx.ready());
verifyCars(followerDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class AbstractEntityOwnershipTest method getMapEntryNodeChild.
protected MapEntryNode getMapEntryNodeChild(final DataContainerNode<? extends PathArgument> parent, final QName childMap, final QName child, final Object key, final boolean expectPresent) {
Optional<DataContainerChild<? extends PathArgument, ?>> childNode = parent.getChild(new NodeIdentifier(childMap));
assertEquals("Missing " + childMap.toString(), true, childNode.isPresent());
MapNode entityTypeMapNode = (MapNode) childNode.get();
Optional<MapEntryNode> entityTypeEntry = entityTypeMapNode.getChild(new NodeIdentifierWithPredicates(childMap, child, key));
if (expectPresent && !entityTypeEntry.isPresent()) {
fail("Missing " + childMap.toString() + " entry for " + key + ". Actual: " + entityTypeMapNode.getValue());
} else if (!expectPresent && entityTypeEntry.isPresent()) {
fail("Found unexpected " + childMap.toString() + " entry for " + key);
}
return entityTypeEntry.isPresent() ? entityTypeEntry.get() : null;
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class DistributedEntityOwnershipIntegrationTest method verifyCandidates.
private static void verifyCandidates(final AbstractDataStore dataStore, final DOMEntity entity, final String... expCandidates) throws Exception {
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.MILLISECONDS) <= 10000) {
Optional<NormalizedNode<?, ?>> possible = dataStore.newReadOnlyTransaction().read(entityPath(entity.getType(), entity.getIdentifier()).node(Candidate.QNAME)).get(5, TimeUnit.SECONDS);
try {
assertEquals("Candidates not found for " + entity, true, possible.isPresent());
Collection<String> actual = new ArrayList<>();
for (MapEntryNode candidate : ((MapNode) possible.get()).getValue()) {
actual.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
}
assertEquals("Candidates for " + entity, Arrays.asList(expCandidates), actual);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.
the class AbstractShardTest method testRecovery.
protected void testRecovery(final Set<Integer> listEntryKeys) throws Exception {
// Create the actor and wait for recovery complete.
final int nListEntries = listEntryKeys.size();
final CountDownLatch recoveryComplete = new CountDownLatch(1);
final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {
@Override
protected void onRecoveryComplete() {
try {
super.onRecoveryComplete();
} finally {
recoveryComplete.countDown();
}
}
};
final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testRecovery");
assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
// Verify data in the data store.
final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable", outerList.getValue() instanceof Iterable);
for (final Object entry : (Iterable<?>) outerList.getValue()) {
assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode", entry instanceof MapEntryNode);
final MapEntryNode mapEntry = (MapEntryNode) entry;
final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf = mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
final Object value = idLeaf.get().getValue();
assertTrue("Unexpected value for leaf " + TestModel.ID_QNAME.getLocalName() + ": " + value, listEntryKeys.remove(value));
}
if (!listEntryKeys.isEmpty()) {
fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " + listEntryKeys);
}
assertEquals("Last log index", nListEntries, shard.underlyingActor().getShardMBean().getLastLogIndex());
assertEquals("Commit index", nListEntries, shard.underlyingActor().getShardMBean().getCommitIndex());
assertEquals("Last applied", nListEntries, shard.underlyingActor().getShardMBean().getLastApplied());
shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
Aggregations