Search in sources :

Example 61 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpcWithNoOutput.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpcWithNoOutput() throws Exception {
    final ContainerNode rpcOutput = null;
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertNull(result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 62 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpc.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpc() throws Exception {
    final ContainerNode rpcOutput = makeRPCOutput("bar");
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 63 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class InMemoryDataStoreTest method testExistsForExistingData.

@Test
public void testExistsForExistingData() throws Exception {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    CheckedFuture<Boolean, ReadFailedException> exists = writeTx.exists(TestModel.TEST_PATH);
    assertEquals(true, exists.checkedGet());
    DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
    ready.preCommit().get();
    ready.commit().get();
    DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
    assertNotNull(readTx);
    exists = readTx.exists(TestModel.TEST_PATH);
    assertEquals(true, exists.checkedGet());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 64 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class InMemoryDataStoreTest method testMerge.

@Test
public void testMerge() throws Exception {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    assertThreePhaseCommit(writeTx.ready());
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", containerNode, afterCommitRead.get());
    // Merge a new list entry node
    writeTx = domStore.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    assertThreePhaseCommit(writeTx.ready());
    afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", containerNode, afterCommitRead.get());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 65 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project bgpcep by opendaylight.

the class BmpMonitorImplTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    doAnswer(invocationOnMock -> {
        BmpMonitorImplTest.this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
        this.singletonService.instantiateServiceInstance();
        return BmpMonitorImplTest.this.singletonServiceRegistration;
    }).when(this.clusterSSProv).registerClusterSingletonService(any(ClusterSingletonService.class));
    doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService.closeServiceInstance()).when(this.singletonServiceRegistration).close();
    doAnswer(invocationOnMock -> {
        this.singletonService2 = (ClusterSingletonService) invocationOnMock.getArguments()[0];
        this.singletonService2.instantiateServiceInstance();
        return BmpMonitorImplTest.this.singletonServiceRegistration2;
    }).when(this.clusterSSProv2).registerClusterSingletonService(any(ClusterSingletonService.class));
    doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService2.closeServiceInstance()).when(this.singletonServiceRegistration2).close();
    this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
    final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(InitiationMessage.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(CParameters1.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(DestinationIpv4Case.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(AdvertizedRoutes.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(SentOpen.class));
    moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(ReceivedOpen.class));
    this.mappingService.onGlobalContextUpdated(moduleInfoBackedContext.tryToCreateSchemaContext().get());
    this.ribActivator = new RIBActivator();
    this.ribExtension = new SimpleRIBExtensionProviderContext();
    this.ribActivator.startRIBExtensionProvider(this.ribExtension);
    this.bgpActivator = new BGPActivator();
    final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
    this.bgpActivator.start(context);
    final SimpleBmpExtensionProviderContext ctx = new SimpleBmpExtensionProviderContext();
    this.bmpActivator = new BmpActivator(context);
    this.bmpActivator.start(ctx);
    this.msgRegistry = ctx.getBmpMessageRegistry();
    this.dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx.getBmpMessageRegistry(), new DefaultBmpSessionFactory());
    final InetSocketAddress inetAddress = new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS), MONITOR_LOCAL_PORT);
    final DOMDataWriteTransaction wTx = getDomBroker().newWriteOnlyTransaction();
    final ContainerNode parentNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BmpMonitor.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build()).build();
    wTx.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(BmpMonitor.QNAME), parentNode);
    wTx.submit();
    final BmpDeployerDependencies bmpDependecies = new BmpDeployerDependencies(getDataBroker(), getDomBroker(), this.ribExtension, this.mappingService.getCodecFactory(), getSchemaContext(), this.clusterSSProv);
    this.bmpApp = new BmpMonitoringStationImpl(bmpDependecies, this.dispatcher, MONITOR_ID, inetAddress, null);
    readDataOperational(getDataBroker(), BMP_II, monitor -> {
        assertEquals(1, monitor.getMonitor().size());
        final Monitor bmpMonitor = monitor.getMonitor().get(0);
        assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
        assertEquals(0, bmpMonitor.getRouter().size());
        assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
        assertEquals(0, bmpMonitor.getRouter().size());
        return monitor;
    });
}
Also used : AdvertizedRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutes) RIBActivator(org.opendaylight.protocol.bgp.inet.RIBActivator) SimpleBmpExtensionProviderContext(org.opendaylight.protocol.bmp.spi.registry.SimpleBmpExtensionProviderContext) BindingToNormalizedNodeCodec(org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec) InetSocketAddress(java.net.InetSocketAddress) BindingNormalizedNodeCodecRegistry(org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) SimpleBGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext) BGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext) SimpleBGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext) BmpMonitor(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.BmpMonitor) Monitor(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor) BmpDeployerDependencies(org.opendaylight.protocol.bmp.impl.config.BmpDeployerDependencies) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BmpActivator(org.opendaylight.protocol.bmp.parser.BmpActivator) BGPActivator(org.opendaylight.protocol.bgp.parser.impl.BGPActivator) ReceivedOpen(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.ReceivedOpen) ModuleInfoBackedContext(org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext) InitiationMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.InitiationMessage) SimpleRIBExtensionProviderContext(org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext) BmpDispatcherImpl(org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl) MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability) SentOpen(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.SentOpen) ClusterSingletonService(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DefaultBmpSessionFactory(org.opendaylight.protocol.bmp.impl.session.DefaultBmpSessionFactory) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) DestinationIpv4Case(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case) Before(org.junit.Before)

Aggregations

ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)81 Test (org.junit.Test)46 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)28 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)12 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)9 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)8 ByteBuf (io.netty.buffer.ByteBuf)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 Map (java.util.Map)6 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)6 Collection (java.util.Collection)4 ExecutionException (java.util.concurrent.ExecutionException)4 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)4 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)4 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)4 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)4