Search in sources :

Example 6 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class NotificationListenerTest method notifi_cont_leafTest.

@Test
public void notifi_cont_leafTest() {
    final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-cont"));
    final DOMNotification notificationData = mock(DOMNotification.class);
    final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
    final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), leaf);
    final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), cont);
    when(notificationData.getType()).thenReturn(schemaPathNotifi);
    when(notificationData.getBody()).thenReturn(notifiBody);
    final String result = prepareJson(notificationData, schemaPathNotifi);
    assertTrue(result.contains("ietf-restconf:notification"));
    assertTrue(result.contains("event-time"));
    assertTrue(result.contains("notifi-module:notifi-cont"));
    assertTrue(result.contains("cont"));
    assertTrue(result.contains("lf" + '"' + ":" + '"' + "value"));
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Example 7 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class NotificationsCounter method onNotification.

@Override
public void onNotification(@NonNull DOMNotification domNotification) {
    final long andDecrement = notifCounter.getAndDecrement();
    if (andDecrement == expectedNotificationCount) {
        this.stopWatch = Stopwatch.createStarted();
        LOG.info("First notification received at {}", stopWatch);
    }
    LOG.debug("Notification received, {} to go.", andDecrement);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Notification received: {}", domNotification);
    }
    final Notification notification = serializer.fromNormalizedNodeNotification(domNotification.getType(), domNotification.getBody());
    if (notification instanceof VRFPREFIXTABLE) {
        totalPrefixesReceived += ((VRFPREFIXTABLE) notification).getVrfPrefixes().getVrfPrefix().size();
    }
    if (andDecrement == 1) {
        this.stopWatch.stop();
        LOG.info("Last notification received at {}", stopWatch);
        LOG.info("Elapsed ms for {} notifications: {}", expectedNotificationCount, stopWatch.elapsed(TimeUnit.MILLISECONDS));
        LOG.info("Performance (notifications/second): {}", (expectedNotificationCount * 1.0 / stopWatch.elapsed(TimeUnit.MILLISECONDS)) * 1000);
        LOG.info("Performance (prefixes/second): {}", (totalPrefixesReceived * 1.0 / stopWatch.elapsed(TimeUnit.MILLISECONDS)) * 1000);
    }
}
Also used : VRFPREFIXTABLE(org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ip._static.cfg.rev130722.VRFPREFIXTABLE) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification)

Example 8 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class XmlNotificationListenerTest method notifi_augmTest.

@Test
public void notifi_augmTest() throws Exception {
    final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-augm"));
    final DOMNotification notificationData = mock(DOMNotification.class);
    final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf-augm"));
    final AugmentationNode augm = mockAugm(leaf);
    final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), augm);
    when(notificationData.getType()).thenReturn(schemaPathNotifi);
    when(notificationData.getBody()).thenReturn(notifiBody);
    final String result = prepareXmlResult(notificationData, schemaPathNotifi);
    final String control = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">" + "<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-augm xmlns=\"notifi:mod\">" + "<lf-augm>value</lf-augm></notifi-augm></notification>";
    assertXmlMatches(result, control);
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) Test(org.junit.Test)

Example 9 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class XmlNotificationListenerTest method notifi_grpTest.

@Test
public void notifi_grpTest() throws Exception {
    final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-grp"));
    final DOMNotification notificationData = mock(DOMNotification.class);
    final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
    final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), leaf);
    when(notificationData.getType()).thenReturn(schemaPathNotifi);
    when(notificationData.getBody()).thenReturn(notifiBody);
    final String result = prepareXmlResult(notificationData, schemaPathNotifi);
    final String control = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">" + "<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-grp xmlns=\"notifi:mod\">" + "<lf>value</lf></notifi-grp></notification>";
    assertXmlMatches(result, control);
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Example 10 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class JsonNotificationListenerTest method notifi_grpTest.

@Test
public void notifi_grpTest() throws Exception {
    final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-grp"));
    final DOMNotification notificationData = mock(DOMNotification.class);
    final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
    final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), leaf);
    when(notificationData.getType()).thenReturn(schemaPathNotifi);
    when(notificationData.getBody()).thenReturn(notifiBody);
    final String result = prepareJson(notificationData, schemaPathNotifi);
    assertTrue(result.contains("ietf-restconf:notification"));
    assertTrue(result.contains("event-time"));
    assertTrue(result.contains("lf" + '"' + ":" + '"' + "value"));
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Aggregations

DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)25 Test (org.junit.Test)24 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)16 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)2 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Diff (org.custommonkey.xmlunit.Diff)1 BindingNormalizedNodeSerializer (org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer)1 DOMNotificationListener (org.opendaylight.mdsal.dom.api.DOMNotificationListener)1 DOMNotificationSubscriptionListener (org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener)1 VRFPREFIXTABLE (org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ip._static.cfg.rev130722.VRFPREFIXTABLE)1 TwoLevelListChangedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChangedBuilder)1 Notification (org.opendaylight.yangtools.yang.binding.Notification)1 QName (org.opendaylight.yangtools.yang.common.QName)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1