BUG-7739: Fix ParserToSalTest/Topology Tests 69/51469/6
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 6 Feb 2017 12:29:57 +0000 (13:29 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 8 Feb 2017 18:23:00 +0000 (18:23 +0000)
Fix ParserToSalTest/Topology failing test

Change-Id: I01cec1b9ab83c14cec8674465ed690e77d820adc
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java
bgp/topology-provider/pom.xml
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv4ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv6ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/LinkstateTopologyBuilderTest.java

index facaa64338b7f761e7881f07bbc8e517037a42d8..8838b94db93cbb8774fe25c57481d3793a59ccd5 100755 (executable)
@@ -11,6 +11,9 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.AS_NUMBER;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.BGP_ID;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
@@ -34,12 +37,12 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.protocol.bgp.inet.RIBActivator;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
@@ -51,9 +54,6 @@ import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivat
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
@@ -63,9 +63,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
@@ -74,19 +71,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
 public class ParserToSalTest extends AbstractDataBrokerTest {
 
     private static final String TEST_RIB_ID = "testRib";
+    private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+    private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
     private BGPMock mock;
     private AbstractRIBExtensionProviderActivator baseact, lsact;
     private RIBExtensionProviderContext ext1, ext2;
-    private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
     private String localAddress = "127.0.0.1";
-    private final IpAddress neighborAddress = new IpAddress(new Ipv4Address(localAddress));
     @Mock
-    BGPDispatcher dispatcher;
+    private BGPDispatcher dispatcher;
     @Mock
     private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     private BindingCodecTreeFactory codecFactory;
@@ -101,8 +99,11 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     @Override
-    protected java.lang.Iterable<org.opendaylight.yangtools.yang.binding.YangModuleInfo> getModuleInfos() throws Exception {
-        return ImmutableList.of(BindingReflections.getModuleInfo(Ipv4Route.class), BindingReflections.getModuleInfo(Ipv6Route.class), BindingReflections.getModuleInfo(LinkstateRoute.class));
+    protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+        return ImmutableList.of(
+            BindingReflections.getModuleInfo(Ipv4Route.class),
+            BindingReflections.getModuleInfo(Ipv6Route.class),
+            BindingReflections.getModuleInfo(LinkstateRoute.class));
     }
 
     @Override
@@ -123,10 +124,12 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         } catch (final IOException e) {
             throw Throwables.propagate(e);
         }
-        this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
+        this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext
+            .getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
 
-        Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher).createReconnectingClient(
-                Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class), Mockito.anyInt(), Mockito.any(Optional.class));
+        Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher)
+            .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class),
+                Mockito.anyInt(), Mockito.any(Optional.class));
 
         this.ext1 = new SimpleRIBExtensionProviderContext();
         this.ext2 = new SimpleRIBExtensionProviderContext();
@@ -144,14 +147,16 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     @Test
-    public void testWithLinkstate() throws InterruptedException, ExecutionException {
-        final List<BgpTableType> tables = ImmutableList.of(
-                new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
-        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"),
-            null, this.ext2, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
-            BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+    public void testWithLinkstate() throws InterruptedException, ExecutionException, ReadFailedException {
+        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class,
+            LinkstateSubsequentAddressFamily.class));
+        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID),
+            AS_NUMBER, new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher,
+            this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
+            BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+            GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
         rib.instantiateServiceInstance();
-        assertTablesExists(tables, true);
+        assertTablesExists(tables);
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         final BGPPeer peer = new BGPPeer(this.localAddress, rib, PeerRole.Ibgp, null, Collections.emptySet(),
             Collections.emptySet());
@@ -161,14 +166,16 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     @Test
-    public void testWithoutLinkstate() throws InterruptedException, ExecutionException {
-        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"), null,
-            this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
-            BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+    public void testWithoutLinkstate() throws InterruptedException, ExecutionException, ReadFailedException {
+        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
+            UnicastSubsequentAddressFamily.class));
+        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID,
+            null, this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables,
+            Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+            GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
         rib.instantiateServiceInstance();
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
-        assertTablesExists(tables, true);
+        assertTablesExists(tables);
         final BGPPeer peer = new BGPPeer(this.localAddress, rib, PeerRole.Ibgp, null, Collections.emptySet(),
             Collections.emptySet());
         peer.instantiateServiceInstance();
@@ -186,24 +193,23 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         });
     }
 
-    private void assertTablesExists(final List<BgpTableType> expectedTables, final boolean uptodate) throws InterruptedException, ExecutionException {
-        final Optional<LocRib> lockRib = getLocRibTable();
-        assertTrue(lockRib.isPresent());
-        final List<Tables> tables = lockRib.get().getTables();
-        assertFalse(tables.isEmpty());
-        for (final BgpTableType tableType : expectedTables) {
-            boolean found = false;
-            for (final Tables table : tables) {
-                if(table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
-                    found = true;
-                    assertTrue(Boolean.valueOf(uptodate).equals(table.getAttributes().isUptodate()));
+    private void assertTablesExists(final List<BgpTableType> expectedTables)
+        throws InterruptedException, ExecutionException, ReadFailedException {
+        readData(getDataBroker(), BGP_IID, bgpRib -> {
+            final List<Tables> tables = bgpRib.getRib().get(0).getLocRib().getTables();
+            assertFalse(tables.isEmpty());
+
+            for (final BgpTableType tableType : expectedTables) {
+                boolean found = false;
+                for (final Tables table : tables) {
+                    if (table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
+                        found = true;
+                        assertTrue(Boolean.valueOf(true).equals(table.getAttributes().isUptodate()));
+                    }
                 }
+                assertTrue(found);
             }
-            assertTrue(found);
-        }
-    }
-
-    private Optional<LocRib> getLocRibTable() throws InterruptedException, ExecutionException {
-        return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId(TEST_RIB_ID))).child(LocRib.class).build()).get();
+            return bgpRib;
+        });
     }
 }
index 65b9c8d7de79db88eef45fbf22efcd52e2743f94..362bdc953ee4d5204ee5aa9761e618202549d088 100644 (file)
         </dependency>
 
         <!-- Test dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-config-loader-impl</artifactId>
index e961ecacb8a678db49aed3238fa6a12360150aed..80e23c7e67b38c648e1bb89338768eff3c80c34f 100755 (executable)
@@ -11,13 +11,13 @@ package org.opendaylight.bgpcep.bgp.topology.provider;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
-import com.google.common.base.Optional;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -33,7 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -53,39 +53,49 @@ public class Ipv4ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         super.setupWithDataBroker(dataBroker);
         this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
         this.ipv4TopoBuilder.start();
-        final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
-            new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
+        final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class,
+            UnicastSubsequentAddressFamily.class);
+        this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class)
+            .child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
+                new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
     }
 
     @Test
-    public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create route
         updateIpv4Route(createIpv4Route(NEXT_HOP));
-        final Optional<Topology> topologyMaybe = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv4ReachabilityTopology());
-        assertEquals(1, topology.getNode().size());
-        final Node node = topology.getNode().get(0);
-        assertEquals(NEXT_HOP, node.getNodeId().getValue());
-        assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+
+        readData(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            final TopologyTypes1 topologyTypes = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+            assertNotNull(topologyTypes);
+            assertNotNull(topologyTypes.getBgpIpv4ReachabilityTopology());
+            assertEquals(1, topology.getNode().size());
+            final Node node = topology.getNode().get(0);
+            assertEquals(NEXT_HOP, node.getNodeId().getValue());
+            assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0)
+                .getPrefix().getIpv4Prefix().getValue());
+            return topology;
+        });
 
         // update route
         updateIpv4Route(createIpv4Route(NEW_NEXT_HOP));
-        final Topology topologyUpdated = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topologyUpdated.getNode().size());
-        final Node nodeUpdated = topologyUpdated.getNode().get(0);
-        assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
-        assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+        readData(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node nodeUpdated = topology.getNode().get(0);
+            assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+            assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes()
+                .getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+            return topology;
+        });
 
         // delete route
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv4RouteIID);
         wTx.submit();
-        final Topology topologyDeleted = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topologyDeleted.getNode().size());
+        readData(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            return topology;
+        });
 
         this.ipv4TopoBuilder.close();
         assertFalse(getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).isPresent());
@@ -99,8 +109,8 @@ public class Ipv4ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
 
     private Ipv4Route createIpv4Route(final String nextHop) {
         final Attributes attribute = new AttributesBuilder()
-            .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address(nextHop)).build()).build())
-            .build();
+            .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+                .setGlobal(new Ipv4Address(nextHop)).build()).build()).build();
         return new Ipv4RouteBuilder().setKey(new Ipv4RouteKey(new PathId(PATH_ID), new Ipv4Prefix(ROUTE_IP4PREFIX)))
             .setPrefix(new Ipv4Prefix(ROUTE_IP4PREFIX)).setAttributes(attribute).build();
     }
index 6da7770ad6164475ca13e70d9b98e482c95d5cce..eedb74cc28a910f74534918462b84cc7a774306f 100755 (executable)
@@ -11,14 +11,14 @@ package org.opendaylight.bgpcep.bgp.topology.provider;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.opendaylight.bgpcep.bgp.topology.provider.Ipv4ReachabilityTopologyBuilderTest.PATH_ID;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
-import com.google.common.base.Optional;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
@@ -34,7 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -53,39 +53,50 @@ public class Ipv6ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         super.setupWithDataBroker(dataBroker);
         this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
         this.ipv6TopoBuilder.start();
-        final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder.tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
-            new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
+        final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder
+            .tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class)
+            .child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
+                new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
     }
 
     @Test
-    public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create route
         updateIpv6Route(createIpv6Route(NEXT_HOP));
-        final Optional<Topology> topologyMaybe = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv6ReachabilityTopology());
-        assertEquals(1, topology.getNode().size());
-        final Node node = topology.getNode().get(0);
-        assertEquals(NEXT_HOP, node.getNodeId().getValue());
-        assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+        readData(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            final TopologyTypes1 topologyType = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+            assertNotNull(topologyType);
+            assertNotNull(topologyType.getBgpIpv6ReachabilityTopology());
+            assertEquals(1, topology.getNode().size());
+            final Node node = topology.getNode().get(0);
+            assertEquals(NEXT_HOP, node.getNodeId().getValue());
+            assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+                .get(0).getPrefix().getIpv6Prefix().getValue());
+            return topology;
+        });
 
         // update route
         updateIpv6Route(createIpv6Route(NEW_NEXT_HOP));
-        final Topology topologyUpdated = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topologyUpdated.getNode().size());
-        final Node nodeUpdated = topologyUpdated.getNode().get(0);
-        assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
-        assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+        readData(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node nodeUpdated = topology.getNode().get(0);
+            assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+            assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+                .get(0).getPrefix().getIpv6Prefix().getValue());
+            return topology;
+        });
 
         // delete route
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv6RouteIID);
         wTx.submit();
-        final Topology topologyDeleted = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topologyDeleted.getNode().size());
+        readData(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            return topology;
+        });
 
         this.ipv6TopoBuilder.close();
         assertFalse(getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).isPresent());
@@ -97,10 +108,10 @@ public class Ipv6ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         wTx.submit();
     }
 
-    public Ipv6Route createIpv6Route(final String netxHop) {
+    private Ipv6Route createIpv6Route(final String netxHop) {
         final Attributes attribute = new AttributesBuilder()
-            .setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address(netxHop)).build()).build())
-            .build();
+            .setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(
+                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address(netxHop)).build()).build()).build();
         return new Ipv6RouteBuilder().setKey(new Ipv6RouteKey(new PathId(PATH_ID), new Ipv6Prefix(ROUTE_IP6PREFIX)))
             .setPrefix(new Ipv6Prefix(ROUTE_IP6PREFIX)).setAttributes(attribute).build();
     }
index 6a702db55b66bf09c604bdb8b62677260ef05cd5..966e24bb20e05a8b1ea9fb3f4aa95d21b1049a35 100755 (executable)
@@ -24,8 +24,8 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import io.netty.buffer.Unpooled;
 import java.math.BigInteger;
@@ -39,6 +39,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -84,7 +85,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
@@ -119,7 +119,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
         this.linkstateTopoBuilder = new LinkstateTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID, LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
         this.linkstateTopoBuilder.start();
         final InstanceIdentifier<Tables> path = this.linkstateTopoBuilder.tableInstanceIdentifier(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
-        this.linkstateRouteIID = path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+        this.linkstateRouteIID = path.builder().child((Class) LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
     }
 
     @After
@@ -129,106 +129,122 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     }
 
     @Test
-    public void testLinkstateTopologyBuilderTopologyTypes() {
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+    public void testLinkstateTopologyBuilderTopologyTypes() throws ReadFailedException {
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
+            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+            return topology;
+        });
     }
 
     @Test
-    public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology1 = topologyMaybe.get();
-        assertEquals(1, topology1.getNode().size());
-        final Node node1 = topology1.getNode().get(0);
-        assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
-        final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("node1", igpNode1.getName().getValue());
-        final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
-        assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
-        assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
-        assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
-        assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node node1 = topology.getNode().get(0);
+            assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
+            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("node1", igpNode1.getName().getValue());
+            final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
+            assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
+            assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+            assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
+            assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+            return topology;
+        });
+
 
         // create link
         updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.IsisLevel2, NODE_1_AS, NODE_2_AS, "link1"));
-        final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topology2.getLink().size());
-        final Link link1 = topology2.getLink().get(0);
-        assertEquals(2, topology2.getNode().size());
-        assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
-        assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
-        assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
-        assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
-        assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
-        final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
-        assertEquals("link1", igpLink1.getName());
-        assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
-        assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getLink().size());
+            final Link link1 = topology.getLink().get(0);
+            assertEquals(2, topology.getNode().size());
+            assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+            assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+            assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+            assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
+            assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
+            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            assertEquals("link1", igpLink1.getName());
+            assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
+            assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+            return topology;
+        });
+
 
         // update node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "updated-node", NODE_1_AS, ROUTER_2_ID));
-        final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("updated-node", igpNode2.getName().getValue());
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("updated-node", igpNode2.getName().getValue());
+            return topology;
+        });
 
         // remove
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID);
         wTx.submit();
-        final Topology topology4 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topology4.getNode().size());
-        assertEquals(0, topology4.getLink().size());
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            assertEquals(0, topology.getLink().size());
+            return topology;
+        });
     }
 
     @Test
-    public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+    public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology1 = topologyMaybe.get();
-        assertEquals(1, topology1.getNode().size());
-        final Node node1 = topology1.getNode().get(0);
-        assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
-        final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("node1", igpNode1.getName().getValue());
-        assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
-        assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node node1 = topology.getNode().get(0);
+            assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
+            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("node1", igpNode1.getName().getValue());
+            assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
+            assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+            return topology;
+        });
 
         // update node with prefix
         updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
-        final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(1, igpNode2.getPrefix().size());
-        final Prefix prefix = igpNode2.getPrefix().get(0);
-        assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
-        assertEquals(500L, prefix.getMetric().longValue());
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(1, igpNode2.getPrefix().size());
+            final Prefix prefix = igpNode2.getPrefix().get(0);
+            assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
+            assertEquals(500L, prefix.getMetric().longValue());
+            return topology;
+        });
+
 
         // create link
         updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
-        final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topology2.getLink().size());
-        final Link link1 = topology2.getLink().get(0);
-        assertEquals(2, topology2.getNode().size());
-        assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
-        assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
-        assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
-        assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
-        assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
-        final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
-        assertEquals("link1", igpLink1.getName());
-        assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
-        assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
-        assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+        readData(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getLink().size());
+            final Link link1 = topology.getLink().get(0);
+            assertEquals(2, topology.getNode().size());
+            assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+            assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+            assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+            assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
+            assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
+            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            assertEquals("link1", igpLink1.getName());
+            assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
+            assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
+            assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+            return topology;
+        });
+
+
     }
 
     /**
@@ -314,7 +330,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
 
     private LinkstateRoute createLinkstateNodeRoute(final ProtocolId protocolId, final String nodeName, final AsNumber asNumber, final String ipv4RouterId) {
         return createBaseBuilder(protocolId)
-            .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).setAsNumber(asNumber).build()).build())
+            .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).setAsNumber(asNumber).build()).build())
             .setAttributes(new AttributesBuilder()
                 .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new NodeAttributesCaseBuilder().setNodeAttributes(new NodeAttributesBuilder()
                     .setDynamicHostname(nodeName)
@@ -330,13 +346,13 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
                 .build())
             .setAttributes(new AttributesBuilder()
                 .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new PrefixAttributesCaseBuilder().setPrefixAttributes(new PrefixAttributesBuilder().setOspfForwardingAddress(new IpAddress(new Ipv4Address(ospfFwdAddress))).setPrefixMetric(new IgpMetric(igpMetric)).build()).build()).build()).build())
-             .build();
+            .build();
     }
 
     private LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs, final AsNumber remoteAs, final String linkName) {
         return createBaseBuilder(protocolId)
             .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder()
-                .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).build())
+                .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).build())
                 .setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
                 .setLinkDescriptors(new LinkDescriptorsBuilder().setMultiTopologyId(new TopologyIdentifier(1)).build())
                 .build())