use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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.NormalizedNode in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistrationForClusteredListener.
@Test(timeout = 10000)
public void testSuccessfulRegistrationForClusteredListener() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener = Mockito.mock(ClusteredDOMDataChangeListener.class);
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockClusteredListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardFound(getRef()));
RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
Assert.assertEquals("getPath", path, registerMsg.getPath());
Assert.assertEquals("getScope", scope, registerMsg.getScope());
Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
reply(new RegisterDataTreeNotificationListenerReply(getRef()));
for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
watch(proxy.getDataChangeListenerActor());
proxy.close();
// The listener registration actor should get a Close message
expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
// The DataChangeListener actor should be terminated
expectMsgClass(timeout, Terminated.class);
proxy.close();
expectNoMsg();
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testReadOnlyTransaction.
@Test
public void testReadOnlyTransaction() throws Exception {
DOMDataReadOnlyTransaction tx = adapter.newReadOnlyTransaction();
// Test successful read
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
// Test successful exists
CheckedFuture<Boolean, ReadFailedException> existsFuture = tx.exists(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
assertEquals("exists", Boolean.TRUE, existsFuture.get());
// Test failed read
String errorMsg = "mock read error";
Throwable cause = new RuntimeException();
doReturn(Futures.immediateFailedCheckedFuture(new org.opendaylight.mdsal.common.api.ReadFailedException(errorMsg, cause))).when(mockReadTx).read(TestModel.TEST_PATH);
try {
tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH).checkedGet();
fail("Expected ReadFailedException");
} catch (ReadFailedException e) {
assertEquals("getMessage", errorMsg, e.getMessage());
assertEquals("getCause", cause, e.getCause());
}
// Test close
tx.close();
verify(mockReadTx).close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class TransactionProxyTest method testReadRoot.
@Test
public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
SchemaContext schemaContext = SchemaContextHelper.full();
Configuration configuration = mock(Configuration.class);
doReturn(configuration).when(mockActorContext).getConfiguration();
doReturn(schemaContext).when(mockActorContext).getSchemaContext();
doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(YangInstanceIdentifier.EMPTY).get(5, TimeUnit.SECONDS);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
NormalizedNode<?, ?> normalizedNode = readOptional.get();
assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
for (NormalizedNode<?, ?> node : collection) {
assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
}
assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class TransactionProxyTest method testRead.
@Test
public void testRead() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("NormalizedNode isPresent", false, readOptional.isPresent());
NormalizedNode<?, ?> expectedNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
readOptional = transactionProxy.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
assertEquals("Response NormalizedNode", expectedNode, readOptional.get());
}
Aggregations