Remove deprecated class AbstractDataBrokerTest under PCEP 90/52990/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Tue, 7 Mar 2017 08:19:38 +0000 (09:19 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 8 Mar 2017 13:36:00 +0000 (13:36 +0000)
-Remove deprecated class AbstractDataBrokerTest on tests.
-Perform some code clean up under tests.

Change-Id: Iee8bdb1e190c80aa0ae883e52963afb6b29cc4f0
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
15 files changed:
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java
pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing/TopologyProviderTest.java
pcep/topology-provider/pom.xml
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/IncrementalSynchronizationProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPStatefulPeerProposalTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCETriggeredInitialSyncProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/StateSynchronizationAvoidanceProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListenerTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/SyncOptimizationTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgrammingTest.java
pcep/tunnel-provider/pom.xml
pcep/tunnel-provider/src/test/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListenerTest.java
pcep/tunnel-provider/src/test/java/org/opendaylight/bgpcep/pcep/tunnel/provider/TunnelProgrammingTest.java

index c738283f0c7e18518a37242c22859e263c412fc4..1a04a229502315b6bc3a1338ceb37ab07d83eb17 100755 (executable)
@@ -78,7 +78,9 @@ public class PCEPDispatcherImplTest {
             eventLoopGroup, eventLoopGroup);
 
         Mockito.doReturn("mockChannel").when(this.mockChannel).toString();
-        final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
+        final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg,
+            new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
+            eventLoopGroup, eventLoopGroup);
         this.disp2Spy = Mockito.spy(dispatcher2);
 
         this.pccMock = new PCCMock(new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0),
@@ -120,8 +122,10 @@ public class PCEPDispatcherImplTest {
         final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
         final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
         waitFutureSuccess(this.dispatcher.createServer(serverAddr, SimpleSessionListener::new, null));
-        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
-            RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+        final Future<PCEPSession> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
+            SimpleSessionListener::new);
+        waitFutureSuccess(futureClient);
+        final PCEPSessionImpl session1 = (PCEPSessionImpl) futureClient.get();
 
         try {
             this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
@@ -201,8 +205,8 @@ public class PCEPDispatcherImplTest {
             });
         }
 
-        Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer, final int connectTimeout,
-            final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
+        Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
+            final int connectTimeout, final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
             final Bootstrap b = new Bootstrap();
             final PCEPProtocolSessionPromise p = new PCEPProtocolSessionPromise(this.executor, address, retryTimer,
                 connectTimeout, b);
index 5f1ee6a9c466be4a87ebcc14af8285e1364fcfc6..0b8d9c8f3e19efc437e6c20ea8d5612f8a9130d9 100644 (file)
@@ -8,16 +8,18 @@
 
 package org.opendaylight.protocol.pcep.segment.routing;
 
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
 import com.google.common.collect.Lists;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.bgpcep.pcep.topology.provider.AbstractPCEPSessionTest;
 import org.opendaylight.bgpcep.pcep.topology.provider.AbstractTopologySessionListener;
 import org.opendaylight.bgpcep.pcep.topology.provider.Stateful07TopologySessionListenerFactory;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.protocol.pcep.PCEPSession;
 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;
@@ -46,9 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 
 public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
 
@@ -65,42 +65,51 @@ public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07Topo
     }
 
     @Test
-    public void testOnReportMessage() throws InterruptedException, ExecutionException {
+    public void testOnReportMessage() throws ReadFailedException {
         this.listener.onSessionUp(this.session);
 
         Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", 1L, true);
         this.listener.onMessage(this.session, pcRptMsg);
-        //check sr-path
-        Topology topology = getTopology().get();
-        List<ReportedLsp> reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
-        Assert.assertEquals(1, reportedLsps.size());
-        final ReportedLsp lsp = reportedLsps.get(0);
-        Assert.assertEquals("sr-path1", lsp.getName());
-        Assert.assertEquals(1, lsp.getPath().get(0).getAugmentation(Path1.class).getPathSetupType().getPst().intValue());
-        List<Subobject> subobjects = lsp.getPath().get(0).getEro().getSubobject();
-        Assert.assertEquals(1, subobjects.size());
-        Assert.assertEquals("1.1.1.1", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check sr-path
+            final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
+            Assert.assertEquals(1, reportedLsps.size());
+            final ReportedLsp lsp = reportedLsps.get(0);
+            Assert.assertEquals("sr-path1", lsp.getName());
+            Assert.assertEquals(1, lsp.getPath().get(0).getAugmentation(Path1.class).getPathSetupType()
+                .getPst().intValue());
+            final List<Subobject> subobjects = lsp.getPath().get(0).getEro().getSubobject();
+            Assert.assertEquals(1, subobjects.size());
+            Assert.assertEquals("1.1.1.1", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType())
+                .getNai()).getIpAddress().getIpv4Address().getValue());
+            return pcc;
+        });
 
         pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", 2L, false);
         this.listener.onMessage(this.session, pcRptMsg);
-        //check second lsp sr-path
-        topology = getTopology().get();
-        reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
-        Assert.assertEquals(2, reportedLsps.size());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check second lsp sr-path
+            Assert.assertEquals(2, pcc.getReportedLsp().size());
+            return pcc;
+        });
+
 
         pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", 1L, true);
         this.listener.onMessage(this.session, pcRptMsg);
-        //check updated sr-path
-        topology = getTopology().get();
-        reportedLsps = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getReportedLsp();
-        Assert.assertEquals(2, reportedLsps.size());
-        for (final ReportedLsp rlsp : reportedLsps) {
-            if (rlsp.getName().equals("sr-path1")) {
-                subobjects = rlsp.getPath().get(0).getEro().getSubobject();
-                Assert.assertEquals(1, subobjects.size());
-                Assert.assertEquals("1.1.1.2", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check updated sr-path
+            final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
+            Assert.assertEquals(2, reportedLsps.size());
+            for (final ReportedLsp rlsp : reportedLsps) {
+                if (rlsp.getName().equals("sr-path1")) {
+                    final List<Subobject> subobjects = rlsp.getPath().get(0).getEro().getSubobject();
+                    Assert.assertEquals(1, subobjects.size());
+                    Assert.assertEquals("1.1.1.2", ((IpNodeId)((SrEroType)subobjects.get(0)
+                        .getSubobjectType()).getNai()).getIpAddress().getIpv4Address().getValue());
+                }
             }
-        }
+            return pcc;
+        });
     }
 
     private static Pcrpt createSrPcRpt(final String nai, final String pathName, final long plspId, final boolean hasLspIdTlv) {
index 90026ad95a0ad8a02b38b1c70fc85a5358a004f1..44ab45cfe831229b9fb6535dfde4bb3aa7a7cf86 100644 (file)
         </dependency>
 
         <!-- Test dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index 12c052d85d57adc464be3a69859ee35b5c138682..729752081f42e54f19cf6acd7b90c97e19f5d66f 100644 (file)
@@ -14,37 +14,29 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import com.google.common.base.Optional;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelPipeline;
 import io.netty.channel.EventLoop;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
 import java.lang.reflect.ParameterizedType;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeMXBean;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeRegistration;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeMXBean;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistration;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistrator;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
@@ -62,18 +54,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 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.TopologyKey;
+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.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
-public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerFactory> extends AbstractDataBrokerTest {
+public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerFactory> extends AbstractConcurrentDataBrokerTest {
 
     protected static final String TEST_TOPOLOGY_NAME = "testtopo";
-    protected static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
+    static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
             Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
     protected static final String IPV4_MASK = "/32";
     protected static final short DEAD_TIMER = 30;
@@ -81,10 +77,12 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
     protected static final int RPC_TIMEOUT = 4;
 
     protected final String testAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
-    protected final NodeId nodeId = new NodeId("pcc://" + testAddress);
-    protected final String eroIpPrefix = testAddress + IPV4_MASK;
+    protected final NodeId nodeId = new NodeId("pcc://" + this.testAddress);
+    protected final InstanceIdentifier<PathComputationClient> pathComputationClientIId = TOPO_IID.builder().child(Node.class,
+        new NodeKey(this.nodeId)).augmentation(Node1.class).child(PathComputationClient.class).build();
+    protected final String eroIpPrefix = this.testAddress + IPV4_MASK;
     protected final String newDestinationAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
-    protected final String dstIpPrefix = newDestinationAddress + IPV4_MASK;
+    protected final String dstIpPrefix = this.newDestinationAddress + IPV4_MASK;
 
     protected List<Notification> receivedMsgs;
 
@@ -107,7 +105,7 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
 
     private final Open localPrefs = new OpenBuilder().setDeadTimer((short) 30).setKeepalive((short) 10).setSessionId((short) 0).build();
 
-    private final Open remotePrefs = localPrefs;
+    private final Open remotePrefs = this.localPrefs;
 
     protected ServerSessionManager manager;
 
@@ -119,13 +117,10 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         this.receivedMsgs = new ArrayList<>();
-        doAnswer(new Answer<Object>() {
-            @Override
-            public Object answer(final InvocationOnMock invocation) {
-                final Object[] args = invocation.getArguments();
-                AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
-                return channelFuture;
-            }
+        doAnswer(invocation -> {
+            final Object[] args = invocation.getArguments();
+            AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
+            return this.channelFuture;
         }).when(this.clientListener).writeAndFlush(any(Notification.class));
         doReturn(null).when(this.channelFuture).addListener(Mockito.any());
         doReturn("TestingChannel").when(this.clientListener).toString();
@@ -134,9 +129,9 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
         doReturn(this.eventLoop).when(this.clientListener).eventLoop();
         doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
         doReturn(true).when(this.clientListener).isActive();
-        final SocketAddress ra = new InetSocketAddress(testAddress, 4189);
+        final SocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
         doReturn(ra).when(this.clientListener).remoteAddress();
-        final SocketAddress la = new InetSocketAddress(testAddress, InetSocketAddressUtil.getRandomPort());
+        final SocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
         doReturn(la).when(this.clientListener).localAddress();
 
         doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
@@ -161,14 +156,8 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
         this.manager.close();
     }
 
-    protected Optional<Topology> getTopology() throws InterruptedException, ExecutionException {
-        try (ReadOnlyTransaction t = getDataBroker().newReadOnlyTransaction()) {
-            return t.read(LogicalDatastoreType.OPERATIONAL, TOPO_IID).get();
-        }
-    }
-
     protected Ero createEroWithIpPrefixes(final List<String> ipPrefixes) {
-        final List<Subobject> subobjs = new ArrayList<Subobject>(ipPrefixes.size());
+        final List<Subobject> subobjs = new ArrayList<>(ipPrefixes.size());
         final SubobjectBuilder subobjBuilder = new SubobjectBuilder();
         for (final String ipPrefix : ipPrefixes) {
             subobjBuilder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(
@@ -195,6 +184,6 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
     }
 
     protected final PCEPSession getPCEPSession(final Open localOpen, final Open remoteOpen) {
-        return neg.createSession(this.clientListener, localOpen, remoteOpen);
+        return this.neg.createSession(this.clientListener, localOpen, remoteOpen);
     }
 }
index 505acdb71f14ff493500762bb7d0fafed33a9099..ab46aa9bba757f6660d94c7683b5185a7508835c 100644 (file)
@@ -9,14 +9,15 @@
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -35,24 +36,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 
 public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
 
     private Stateful07TopologySessionListener listener;
 
-    private PCEPSession session;
-
     @Override
     @Before
     public void setUp() throws Exception {
@@ -61,84 +56,100 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
     }
 
     @Test
-    public void testStateSynchronizationPerformed() throws InterruptedException, ExecutionException {
-        this.session = getPCEPSession(getOpen(null), getOpen(null));
+    public void testStateSynchronizationPerformed() throws Exception {
+        PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
         this.listener.onSessionUp(session);
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrpt(1L, "test");
         this.listener.onMessage(session, pcRpt);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
-        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertFalse(pcc.getReportedLsp().isEmpty());
         this.listener.onSessionDown(session, new IllegalArgumentException());
         this.listener = (Stateful07TopologySessionListener) getSessionListener();
 
         //session up - expect sync (LSP-DBs do not match)
         final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
-        this.session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
+        session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
         this.listener.onSessionUp(session);
-
-        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - IncrementalSync state
-        Assert.assertEquals(PccSyncState.IncrementalSync, pcc2.getStateSync());
-        //check reported LSP - persisted from previous session
-        Assert.assertFalse(pcc2.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - IncrementalSync state
+            assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
+            //check reported LSP - persisted from previous session
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
         //report LSP2 + LSP-DB version number 2
         final Pcrpt pcRpt2 = getPcrpt(2L,"testsecond");
         this.listener.onMessage(session, pcRpt2);
-
-        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.IncrementalSync, pcc3.getStateSync());
-        //check reported LSP is not empty
-        Assert.assertEquals(2, pcc3.getReportedLsp().size());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
+            //check reported LSP is not empty
+            assertEquals(2, pcc.getReportedLsp().size());
+            return pcc;
+        });
 
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getSyncPcrt();
         this.listener.onMessage(session, syncMsg);
-        final PathComputationClient pcc4 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc4.getStateSync());
-        //check reported LSP is empty, LSP state from previous session was purged
-        Assert.assertEquals(2, pcc4.getReportedLsp().size());
-
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP is empty, LSP state from previous session was purged
+            assertEquals(2, pcc.getReportedLsp().size());
+            return pcc;
+        });
 
         //report LSP3 + LSP-DB version number 4
         final Pcrpt pcRpt3 = getPcrpt(3L,"testthird");
         this.listener.onMessage(session, pcRpt3);
-
-        final PathComputationClient pcc5 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc5.getStateSync());
-        Assert.assertEquals(3,pcc5.getReportedLsp().size());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            assertEquals(3,pcc.getReportedLsp().size());
+            return pcc;
+        });
     }
 
     private Open getOpen(final LspDbVersion dbVersion) {
-        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
-            .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
-            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+            new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class,
+                new Stateful1Builder().setInitiation(Boolean.TRUE).build())
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+                optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+                .ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
                 .setIncludeDbVersion(Boolean.TRUE).setDeltaLspSyncCapability(Boolean.TRUE).build())
-            .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+            .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build())
+            .build()).build();
     }
 
-    private Pcrpt getPcrpt(Long val, String pathname) {
+    private Pcrpt getPcrpt(final Long val, final String pathname) {
         return MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(val)).setTlvs(
-            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.
-                TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(val)).build())
-                .setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(pathname.getBytes())).build())
-                .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
-                    .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(val)).build()).build()).build()).setPlspId(new PlspId(val)
-        ).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(), createPath(Collections.emptyList()));
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.
+                object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(val)).build())
+                .setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(
+                    pathname.getBytes())).build()).addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params
+                .xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.
+                urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
+                .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(val)).build())
+                .build()).build()).setPlspId(new PlspId(val)
+        ).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(),
+            createPath(Collections.emptyList()));
     }
 
     private Pcrpt getSyncPcrt() {
         return MsgBuilderUtil.createPcRtpMessage(createLsp(0, false, Optional.of(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.
+                    lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+                        xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
                     new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
-                        .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(3L)).build()).build()).build()), true, false), Optional.<Srp>absent(),
+                        .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+                        .setLspDbVersionValue(BigInteger.valueOf(3L)).build()).build()).build()),
+            true, false), Optional.absent(),
             createPath(Collections.emptyList()));
     }
 }
index 0dc8f0b7eed3d053160ac56e74a790dec84617c7..213c9481676ad2b2d66cedcd9015fc85bc000cf7 100644 (file)
@@ -21,8 +21,6 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -49,7 +47,7 @@ public class PCEPStatefulPeerProposalTest {
             .child(Topology.class, new TopologyKey(new TopologyId("topology")));
     private static final NodeId NODE_ID = new NodeId("node");
     private static final LspDbVersion LSP_DB_VERSION = new LspDbVersionBuilder().setLspDbVersionValue(
-            BigInteger.valueOf(1L)).build();
+            BigInteger.ONE).build();
 
     @Mock
     private DataBroker dataBroker;
@@ -68,45 +66,42 @@ public class PCEPStatefulPeerProposalTest {
                         new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder().build()).build())
                         .build());
         final ReadOnlyTransaction rTxMock = Mockito.mock(ReadOnlyTransaction.class);
-        Mockito.doReturn(rTxMock).when(dataBroker).newReadOnlyTransaction();
-        Mockito.doReturn(listenableFutureMock).when(rTxMock)
+        Mockito.doReturn(rTxMock).when(this.dataBroker).newReadOnlyTransaction();
+        Mockito.doReturn(this.listenableFutureMock).when(rTxMock)
                 .read(Mockito.any(LogicalDatastoreType.class), Mockito.any(InstanceIdentifier.class));
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable runnable = (Runnable) invocation.getArguments()[0];
-                runnable.run();
-                return null;
-            }
-        }).when(listenableFutureMock).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
+        Mockito.doAnswer(invocation -> {
+            final Runnable runnable = (Runnable) invocation.getArguments()[0];
+            runnable.run();
+            return null;
+        }).when(this.listenableFutureMock).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
     }
 
     @Test
     public void testSetPeerProposalSuccess() throws InterruptedException, ExecutionException {
-        Mockito.doReturn(Optional.of(LSP_DB_VERSION)).when(listenableFutureMock).get();
-        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+        Mockito.doReturn(Optional.of(LSP_DB_VERSION)).when(this.listenableFutureMock).get();
+        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
                 TOPOLOGY_IID);
-        peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
-        assertEquals(LSP_DB_VERSION, tlvsBuilder.getAugmentation(Tlvs3.class).getLspDbVersion());
+        peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+        assertEquals(LSP_DB_VERSION, this.tlvsBuilder.getAugmentation(Tlvs3.class).getLspDbVersion());
     }
 
     @Test
     public void testSetPeerProposalAbsent() throws InterruptedException, ExecutionException {
-        Mockito.doReturn(Optional.absent()).when(listenableFutureMock).get();
-        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+        Mockito.doReturn(Optional.absent()).when(this.listenableFutureMock).get();
+        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
                 TOPOLOGY_IID);
-        peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
-        assertNull(tlvsBuilder.getAugmentation(Tlvs3.class));
+        peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+        assertNull(this.tlvsBuilder.getAugmentation(Tlvs3.class));
     }
 
     @Test
     public void testSetPeerProposalFailure() throws InterruptedException, ExecutionException {
-        Mockito.doThrow(new RuntimeException()).when(listenableFutureMock).get();
-        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(dataBroker,
+        Mockito.doThrow(new RuntimeException()).when(this.listenableFutureMock).get();
+        final PCEPStatefulPeerProposal peerProposal = PCEPStatefulPeerProposal.createStatefulPeerProposal(this.dataBroker,
                 TOPOLOGY_IID);
-        peerProposal.setPeerProposal(NODE_ID, tlvsBuilder);
-        assertNull(tlvsBuilder.getAugmentation(Tlvs3.class));
+        peerProposal.setPeerProposal(NODE_ID, this.tlvsBuilder);
+        assertNull(this.tlvsBuilder.getAugmentation(Tlvs3.class));
     }
 
 }
index c40d740f7041c717866866743a01b66fbb5ecbe0..542416e71ec01554d7d425f9bea574971e453c82 100644 (file)
@@ -7,15 +7,16 @@
  */
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -35,25 +36,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
 
 public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
     private Stateful07TopologySessionListener listener;
 
     private PCEPSession session;
+    private final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
 
     @Override
     @Before
@@ -63,104 +61,120 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
     }
 
     @Test
-    public void testTriggeredResynchronization() throws InterruptedException, ExecutionException {
+    public void testTriggeredResynchronization() throws Exception {
         //session up - sync skipped (LSP-DBs match)
-        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
-        this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
-        this.listener.onSessionUp(session);
+        this.session = getPCEPSession(getOpen(), getOpen());
+        this.listener.onSessionUp(this.session);
 
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrt();
-        this.listener.onMessage(session, pcRpt);
+        this.listener.onMessage(this.session, pcRpt);
 
-        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
-        Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
         //PCEP Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
-
-        final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
+            return pcc;
+        });
 
         //end of sync
         final Pcrpt syncMsg = getSyncMsg();
-        this.listener.onMessage(session, syncMsg);
-        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
-
-        this.listener.onMessage(session, pcRpt);
-        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertEquals(1, pcc3.getReportedLsp().size());
+        this.listener.onMessage(this.session, syncMsg);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            return pcc;
+        });
+
+        this.listener.onMessage(this.session, pcRpt);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(1, pcc.getReportedLsp().size());
+            return pcc;
+        });
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
-        this.listener.onMessage(session, pcRpt);
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
+        this.listener.onMessage(this.session, pcRpt);
         //end of sync
-        this.listener.onMessage(session, syncMsg);
-        final PathComputationClient pcc4 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc4.getStateSync());
-        //check reported LSP is not empty, Stale LSP state were purged
-        Assert.assertEquals(1, pcc4.getReportedLsp().size());
+        this.listener.onMessage(this.session, syncMsg);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP is not empty, Stale LSP state were purged
+            assertEquals(1, pcc.getReportedLsp().size());
+            return pcc;
+        });
     }
 
     @Test
-    public void testTriggeredResynchronizationLsp() throws InterruptedException, ExecutionException {
+    public void testTriggeredResynchronizationLsp() throws Exception {
         //session up - sync skipped (LSP-DBs match)
-        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
-        this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
-        this.listener.onSessionUp(session);
+
+        this.session = getPCEPSession(getOpen(), getOpen());
+        this.listener.onSessionUp(this.session);
 
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrt();
-        this.listener.onMessage(session, pcRpt);
-
-        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
-        final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
-        Assert.assertFalse(reportedLspPcc.isEmpty());
+        this.listener.onMessage(this.session, pcRpt);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
+            assertFalse(reportedLspPcc.isEmpty());
+            return pcc;
+        });
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
-
-        final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
-        Assert.assertFalse(pcc1.getReportedLsp().isEmpty());
-
-        this.listener.onMessage(session, pcRpt);
-
-        Assert.assertFalse(reportedLspPcc.isEmpty());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
+
+        this.listener.onMessage(this.session, pcRpt);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getSyncMsg();
-        this.listener.onMessage(session, syncMsg);
-        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc2.getStateSync());
-        //check reported LSP
-        Assert.assertEquals(1, pcc2.getReportedLsp().size());
+        this.listener.onMessage(this.session, syncMsg);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP
+            assertEquals(1, pcc.getReportedLsp().size());
+            return pcc;
+        });
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
-        this.listener.onMessage(session, syncMsg);
-
-        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
-        //check reported LSP
-        Assert.assertEquals(0, pcc3.getReportedLsp().size());
-
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
+        this.listener.onMessage(this.session, syncMsg);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP
+            assertEquals(0, pcc.getReportedLsp().size());
+            return pcc;
+        });
     }
 
-    private Open getOpen(final LspDbVersion dbVersion) {
-        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
-            .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
-            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class,
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
-                    .setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE).build())
-            .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+    private Open getOpen() {
+        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+            new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder()
+                .setInitiation(Boolean.TRUE).build()).addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
+                    .params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations
+                    .rev150714.Stateful1Builder().setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE)
+                    .build()).build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder()
+            .setLspDbVersion(this.lspDbVersion).build()).build()).build();
     }
 
     private Pcrpt getSyncMsg() {
@@ -182,7 +196,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
                     new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
                     .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder()
-                            .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build())
+                            .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build())
                 .setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(),
             createPath(Collections.emptyList()));
     }
index cd7aaa67871c9ef3e007caffd3f9ab180d94bdd7..7c177a6928462d78cd7ac013d33912076952ef63 100644 (file)
@@ -8,14 +8,16 @@
 
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -34,23 +36,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 
 public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
     private Stateful07TopologySessionListener listener;
 
-    private PCEPSession session;
-
     @Override
     @Before
     public void setUp() throws Exception {
@@ -62,32 +58,41 @@ public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTes
      * Test Triggered Initial Sync procedure
      **/
     @Test
-    public void testPcepTriggeredInitialSyncPerformed() throws InterruptedException, ExecutionException {
+    public void testPcepTriggeredInitialSyncPerformed() throws Exception {
         this.listener = (Stateful07TopologySessionListener) getSessionListener();
 
         //session up - expect triggered sync (LSP-DBs do not match)
-        final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
+        final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
         final LspDbVersion localDbVersion2 = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
-        this.session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
+        final PCEPSession session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
         this.listener.onSessionUp(session);
 
-        final PathComputationClient pcc2 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - not synchronized and TriggeredInitialSync state
-        Assert.assertEquals(PccSyncState.TriggeredInitialSync, pcc2.getStateSync());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - not synchronized and TriggeredInitialSync state
+            assertEquals(PccSyncState.TriggeredInitialSync, pcc.getStateSync());
+            return pcc;
+        });
+
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getsyncMsg();
         this.listener.onMessage(session, syncMsg);
-        final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
-        //check reported LSP is empty, LSP state from previous session was purged
-        Assert.assertTrue(pcc3.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP is empty, LSP state from previous session was purged
+            assertTrue(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrpt();
         this.listener.onMessage(session, pcRpt);
-        final PathComputationClient pcc = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
+
     }
 
     private Open getOpen(final LspDbVersion dbVersion, final boolean incremental) {
index 767994f01a973543135579fd9bd06a816270fdaf..7df6dcad82e62ff0dda3022e034649e7167e75ef 100644 (file)
@@ -8,16 +8,19 @@
 
 package org.opendaylight.bgpcep.pcep.topology.provider;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.PathComputationClient1;
@@ -35,25 +38,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 
-public class StateSynchronizationAvoidanceProcedureTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
+public class StateSynchronizationAvoidanceProcedureTest extends
+    AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
 
     private Stateful07TopologySessionListener listener;
 
-    private PCEPSession session;
-
     @Override
     @Before
     public void setUp() throws Exception {
@@ -62,83 +59,112 @@ public class StateSynchronizationAvoidanceProcedureTest extends AbstractPCEPSess
     }
 
     @Test
-    public void testNodePersisted() throws InterruptedException, ExecutionException {
-        this.session = getPCEPSession(getOpen(null), getOpen(null));
+    public void testNodePersisted() throws ReadFailedException {
+        final PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
         this.listener.onSessionUp(session);
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setTlvs(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder()
                     .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
-                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
+                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
         this.listener.onMessage(session, pcRpt);
         //check topology
-        final Topology topo1 = getTopology().get();
-        final LspDbVersion lspDb1 = topo1.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getAugmentation(PathComputationClient1.class).getLspDbVersion();
-        Assert.assertEquals(1L, lspDb1.getLspDbVersionValue().longValue());
+        readData(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
+            .child(LspDbVersion.class).build(), dbVersion -> {
+            assertEquals(1L, dbVersion.getLspDbVersionValue().longValue());
+            return dbVersion;
+        });
+
         //drop session
         this.listener.onSessionDown(session, new IllegalStateException());
+        readData(getDataBroker(), TOPO_IID, topology -> {
+            assertFalse(topology.getNode().isEmpty());
+            return topology;
+        });
         //check topology - node is persisted
-        final Topology topo2 = getTopology().get();
-        Assert.assertFalse(topo2.getNode().isEmpty());
     }
 
     @Test
-    public void testStateSynchronizationSkipped() throws InterruptedException, ExecutionException {
+    public void testStateSynchronizationSkipped() throws Exception {
         //session up - sync skipped (LSP-DBs match)
-        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build();
-        this.session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
+        final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build();
+        final PCEPSession session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
         this.listener.onSessionUp(session);
         //check node - synchronized
-        final Topology topo = getTopology().get();
-        Assert.assertEquals(PccSyncState.Synchronized, topo.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient().getStateSync());
-    }
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            return pcc;
+        });
+  }
 
     @Test
-    public void testStateSynchronizationPerformed() throws InterruptedException, ExecutionException {
-        this.session = getPCEPSession(getOpen(null), getOpen(null));
+    public void testStateSynchronizationPerformed() throws Exception {
+        PCEPSession session = getPCEPSession(getOpen(null), getOpen(null));
         this.listener.onSessionUp(session);
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(1L)).setTlvs(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
-                    .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
-                            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(1L)).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.absent(), createPath(Collections.emptyList()));
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.
+                    object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder()
+                    .setLspId(new LspId(1L)).build()).setSymbolicPathName(new SymbolicPathNameBuilder()
+                    .setPathName(new SymbolicPathName("test".getBytes())).build()).addAugmentation(org.opendaylight.
+                        yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714
+                        .Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller
+                    .pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+                    .setLspDbVersionValue(BigInteger.ONE).build()).build()).build())
+            .setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active)
+            .build(), Optional.absent(), createPath(Collections.emptyList()));
         this.listener.onMessage(session, pcRpt);
-        final Topology topo = getTopology().get();
-        final PathComputationClient pcc = topo.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        Assert.assertFalse(pcc.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
+
         this.listener.onSessionDown(session, new IllegalArgumentException());
         this.listener = (Stateful07TopologySessionListener) getSessionListener();
 
         //session up - expect sync (LSP-DBs do not match)
-        final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
-        this.session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
+        final LspDbVersion localDbVersion = new LspDbVersionBuilder()
+            .setLspDbVersionValue(BigInteger.valueOf(2L)).build();
+        session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
         this.listener.onSessionUp(session);
 
-        final Topology topo2 = getTopology().get();
-        final PathComputationClient pcc2 = topo2.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - not synchronized
-        Assert.assertEquals(PccSyncState.InitialResync, pcc2.getStateSync());
-        //check reported LSP - persisted from previous session
-        Assert.assertFalse(pcc2.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - not synchronized
+            assertEquals(PccSyncState.InitialResync, pcc.getStateSync());
+            //check reported LSP - persisted from previous session
+            assertFalse(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
+
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = MsgBuilderUtil.createPcRtpMessage(createLsp(0, false, Optional.of(
-            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build()).build()).build()), true, false), Optional.absent(),
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222
+                .lsp.object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.
+                    params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
+                    .optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
+                    .setLspDbVersionValue(BigInteger.valueOf(2L)).build()).build()).build()),
+            true, false), Optional.absent(),
                 createPath(Collections.emptyList()));
         this.listener.onMessage(session, syncMsg);
-        final Topology topo3 = getTopology().get();
-        final PathComputationClient pcc3 = topo3.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        //check node - synchronized
-        Assert.assertEquals(PccSyncState.Synchronized, pcc3.getStateSync());
-        //check reported LSP is empty, LSP state from previous session was purged
-        Assert.assertTrue(pcc3.getReportedLsp().isEmpty());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            //check node - synchronized
+            assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
+            //check reported LSP is empty, LSP state from previous session was purged
+            assertTrue(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
     }
 
-    protected Open getOpen(final LspDbVersion dbVersion) {
-        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
+    private Open getOpen(final LspDbVersion dbVersion) {
+        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+            new Tlvs1Builder().setStateful(new StatefulBuilder()
             .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
-            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder().setIncludeDbVersion(Boolean.TRUE).build())
-            .build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+                optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+                xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+                .setIncludeDbVersion(Boolean.TRUE).build()).build()).build()).addAugmentation(Tlvs3.class,
+            new Tlvs3Builder().setLspDbVersion(dbVersion).build()).build()).build();
     }
 
 }
index 5be6c20411496f4ec6bdb372219a44f3e5b8ea47..401a3d9a6d55637e66cd16990d15f603d1689463 100755 (executable)
@@ -17,6 +17,9 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs;
+import static org.opendaylight.protocol.util.CheckUtil.checkNull;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import java.net.UnknownHostException;
@@ -29,6 +32,7 @@ import java.util.concurrent.TimeoutException;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -71,12 +75,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
@@ -84,7 +86,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInputBuilder;
@@ -92,15 +93,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
 
-    private final String TUNNEL_NAME = "pcc_" + testAddress + "_tunnel_0";
+    private final String TUNNEL_NAME = "pcc_" + this.testAddress + "_tunnel_0";
 
     private Stateful07TopologySessionListener listener;
 
@@ -118,17 +117,17 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     public void testStateful07TopologySessionListener() throws Exception {
         this.listener.onSessionUp(this.session);
 
-        assertEquals(testAddress, this.listener.getPeerId());
+        assertEquals(this.testAddress, this.listener.getPeerId());
         final SessionState state = this.listener.getSessionState();
         assertNotNull(state);
         assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
         assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
         assertEquals(0, state.getLocalPref().getSessionId().intValue());
-        assertEquals(testAddress, state.getLocalPref().getIpAddress());
+        assertEquals(this.testAddress, state.getLocalPref().getIpAddress());
         assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
         assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
         assertEquals(0, state.getPeerPref().getSessionId().intValue());
-        assertEquals(testAddress, state.getPeerPref().getIpAddress());
+        assertEquals(this.testAddress, state.getPeerPref().getIpAddress());
 
         // add-lsp
         this.topologyRpcs.addLsp(createAddLspInput());
@@ -138,32 +137,34 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-            testAddress, testAddress, testAddress, Optional.absent());
-        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
-        final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
+            this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp())
+            .setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false)
+            .setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)),
+            MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+        final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(),
+            Optional.of(MsgBuilderUtil.createSrp(0L)), null);
         this.listener.onMessage(this.session, esm);
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(this.testAddress, pcc.getIpAddress().getIpv4Address().getValue());
+            // reported lsp so far empty, has not received response (PcRpt) yet
+            assertTrue(pcc.getReportedLsp().isEmpty());
+            return pcc;
+        });
 
-        final Optional<Topology> topoOptional = getTopology();
-        assertTrue(topoOptional.isPresent());
-        Topology topology = topoOptional.get();
-        assertEquals(1, topology.getNode().size());
-        final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
-        assertNotNull(node);
-        PathComputationClient pcc = node.getPathComputationClient();
-        assertEquals(testAddress, pcc.getIpAddress().getIpv4Address().getValue());
-        // reported lsp so far empty, has not received response (PcRpt) yet
-        assertTrue(pcc.getReportedLsp().isEmpty());
         this.listener.onMessage(this.session, pcRpt);
         // check created lsp
-        topology = getTopology().get();
-        pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        assertEquals(1, pcc.getReportedLsp().size());
-        ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
-        assertEquals(TUNNEL_NAME, reportedLsp.getName());
-        assertEquals(1, reportedLsp.getPath().size());
-        Path path = reportedLsp.getPath().get(0);
-        assertEquals(1, path.getEro().getSubobject().size());
-        assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(1, pcc.getReportedLsp().size());
+            final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
+            assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
+            assertEquals(1, reportedLsp.getPath().size());
+            final Path path = reportedLsp.getPath().get(0);
+            assertEquals(1, path.getEro().getSubobject().size());
+            assertEquals(this.eroIpPrefix, getLastEroIpPrefix(path.getEro()));
+            return pcc;
+        });
+
         // check stats
         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
         assertTrue(this.listener.getSynchronized());
@@ -174,10 +175,15 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertNotNull(this.listener.getSessionState());
 
         // update-lsp
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
-        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
-        updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args
+            .ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+            topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
+        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix, this.dstIpPrefix)));
+        updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder()
+            .setDelegate(true).setAdministrative(true).build()).build());
+        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build())
+            .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID))
+            .setNode(this.nodeId).build();
         this.topologyRpcs.updateLsp(update);
         assertEquals(2, this.receivedMsgs.size());
         assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
@@ -185,19 +191,25 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
         final long srpId2 = upd.getSrp().getOperationId().getValue();
         final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
-            newDestinationAddress, testAddress, testAddress, Optional.absent());
-        final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
+            this.newDestinationAddress, this.testAddress, this.testAddress, Optional.absent());
+        final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2)
+            .setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(),
+            Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath()
+                .getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt2);
+
         //check updated lsp
-        topology = getTopology().get();
-        pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        assertEquals(1, pcc.getReportedLsp().size());
-        reportedLsp = pcc.getReportedLsp().get(0);
-        assertEquals(TUNNEL_NAME, reportedLsp.getName());
-        assertEquals(1, reportedLsp.getPath().size());
-        path = reportedLsp.getPath().get(0);
-        assertEquals(2, path.getEro().getSubobject().size());
-        assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(1, pcc.getReportedLsp().size());
+            final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
+            assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
+            assertEquals(1, reportedLsp.getPath().size());
+            final Path path = reportedLsp.getPath().get(0);
+            assertEquals(2, path.getEro().getSubobject().size());
+            assertEquals(this.dstIpPrefix, getLastEroIpPrefix(path.getEro()));
+            return pcc;
+        });
+
         // check stats
         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
         assertTrue(this.listener.getSynchronized());
@@ -212,15 +224,21 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertTrue(this.listener.getPeerCapabilities().getStateful());
 
         // ensure-operational
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
-        ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
-        final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.
+            operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.
+            xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
+        ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active)
+            .build());
+        final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build())
+            .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID))
+            .setNode(this.nodeId).build();
         final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
         //check result
         assertNull(result.getFailure());
 
         // remove-lsp
-        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(this.TUNNEL_NAME)
+            .setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
         this.topologyRpcs.removeLsp(remove);
         assertEquals(3, this.receivedMsgs.size());
         assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
@@ -228,13 +246,17 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
         final long srpId3 = req2.getSrp().getOperationId().getValue();
         final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
-            testAddress, testAddress, testAddress, Optional.absent());
-        final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
+            this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+        final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3)
+            .setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(),
+            Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
         this.listener.onMessage(this.session, pcRpt3);
+
         // check if lsp was removed
-        topology = getTopology().get();
-        pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
-        assertEquals(0, pcc.getReportedLsp().size());
+        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+            assertEquals(0, pcc.getReportedLsp().size());
+            return pcc;
+        });
         // check stats
         assertEquals(0, this.listener.getDelegatedLspsCount().intValue());
         assertTrue(this.listener.getSynchronized());
@@ -294,7 +316,8 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
      * @throws TransactionCommitFailedException
      */
     @Test
-    public void testOnServerSessionManagerDown() throws InterruptedException, ExecutionException, TransactionCommitFailedException {
+    public void testOnServerSessionManagerDown() throws InterruptedException, ExecutionException,
+        TransactionCommitFailedException {
         this.listener.onSessionUp(this.session);
         verify(this.listenerReg, times(0)).close();
         // send request
@@ -314,13 +337,14 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
      * @throws TransactionCommitFailedException
      */
     @Test
-    public void testOnServerSessionManagerUnstarted() throws InterruptedException, ExecutionException, TransactionCommitFailedException {
+    public void testOnServerSessionManagerUnstarted() throws InterruptedException, ExecutionException,
+        TransactionCommitFailedException, ReadFailedException {
         this.manager.close();
         // the registration should not be closed since it's never initialized
         verify(this.listenerReg, times(0)).close();
         this.listener.onSessionUp(this.session);
         // verify the session was NOT added to topology
-        assertFalse(getTopology().isPresent());
+        checkNull(getDataBroker(), TOPO_IID);
         // still, the session should not be registered and thus close() is never called
         verify(this.listenerReg, times(0)).close();
         // send request
@@ -331,7 +355,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     }
 
     @Test
-    public void testOnSessionTermination() throws UnknownHostException, InterruptedException, ExecutionException {
+    public void testOnSessionTermination() throws Exception {
         this.listener.onSessionUp(this.session);
         verify(this.listenerReg, times(0)).close();
 
@@ -341,37 +365,53 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-            testAddress, testAddress, testAddress, Optional.absent());
-        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+            this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true)
+            .setRemove(false).setOperational(OperationalStatus.Active).build(),
+            Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
-        assertEquals(1, getTopology().get().getNode().size());
+        readData(getDataBroker(), TOPO_IID, topology -> {
+            assertEquals(1, topology.getNode().size());
+            return topology;
+        });
 
         // node should be removed after termination
         this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
         verify(this.listenerReg, times(1)).close();
-        assertEquals(0, getTopology().get().getNode().size());
+        checkNull(getDataBroker(), this.pathComputationClientIId);
     }
 
     @Test
     public void testUnknownLsp() throws Exception {
-        final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
-                new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
-                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(
-                                new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
-        final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
+        final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder()
+            .setEro(new EroBuilder().build()).build()).setLsp(new LspBuilder().setPlspId(new PlspId(5L))
+            .setSync(false).setRemove(false).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.
+                yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(
+                    new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(
+                        new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 }))
+                            .build()).build()).build()).build());
+        final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build())
+            .build();
         this.listener.onSessionUp(this.session);
         this.listener.onMessage(this.session, rptmsg);
-        final Topology topology = getTopology().get();
-        assertFalse(topology.getNode().isEmpty());
+        readData(getDataBroker(), TOPO_IID, node -> {
+            assertFalse(node.getNode().isEmpty());
+            return node;
+        });
     }
 
     @Test
     public void testUpdateUnknownLsp() throws InterruptedException, ExecutionException {
         this.listener.onSessionUp(this.session);
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
-        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
-        updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args
+            .ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
+            topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
+        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix, this.dstIpPrefix)));
+        updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder()
+            .setDelegate(true).setAdministrative(true).build()).build());
+        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build())
+            .setName(this.TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId)
+            .build();
         final UpdateLspOutput result = this.topologyRpcs.updateLsp(update).get().getResult();
         assertEquals(FailureType.Unsent, result.getFailure());
         assertEquals(1, result.getError().size());
@@ -383,7 +423,8 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     @Test
     public void testRemoveUnknownLsp() throws InterruptedException, ExecutionException {
         this.listener.onSessionUp(this.session);
-        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(this.TUNNEL_NAME).setNetworkTopologyRef(
+            new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
         final OperationResult result = this.topologyRpcs.removeLsp(remove).get().getResult();
         assertEquals(FailureType.Unsent, result.getFailure());
         assertEquals(1, result.getError().size());
@@ -402,8 +443,11 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-            testAddress, testAddress, testAddress, Optional.absent());
-        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
+            this.testAddress, this.testAddress, this.testAddress, Optional.absent());
+        final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs)
+            .setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active)
+            .build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro()
+            .getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
 
         //try to add already existing LSP
@@ -412,30 +456,35 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertEquals(1, result.getError().size());
         final ErrorObject errorObject = result.getError().get(0).getErrorObject();
         assertNotNull(errorObject);
-        assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
+        assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(),
+            errorObject.getValue()));
     }
 
     @Test
     public void testPccResponseTimeout() throws InterruptedException, ExecutionException {
         this.listener.onSessionUp(this.session);
-        Future<RpcResult<AddLspOutput>> addLspResult = this.topologyRpcs.addLsp(createAddLspInput());
+        final Future<RpcResult<AddLspOutput>> addLspResult = this.topologyRpcs.addLsp(createAddLspInput());
         try {
             addLspResult.get(2, TimeUnit.SECONDS);
             fail();
-        } catch (Exception e) {
+        } catch (final Exception e) {
             assertTrue(e instanceof TimeoutException);
         }
         Thread.sleep(AbstractPCEPSessionTest.RPC_TIMEOUT);
-        RpcResult<AddLspOutput> rpcResult = addLspResult.get();
+        final RpcResult<AddLspOutput> rpcResult = addLspResult.get();
         assertNotNull(rpcResult);
         assertEquals(rpcResult.getResult().getFailure(), FailureType.Unsent);
     }
 
     @Override
     protected Open getLocalPref() {
-        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
+        return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
+            new Tlvs1Builder().setStateful(new StatefulBuilder()
             .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
-            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder().setTriggeredInitialSync(Boolean.TRUE).build())
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.
+                optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.
+                ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder()
+                .setTriggeredInitialSync(Boolean.TRUE).build())
             .build()).build()).build()).build();
     }
 
@@ -447,10 +496,13 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     private AddLspInput createAddLspInput() {
         final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
         final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
-        ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(testAddress)).setDestinationIpv4Address(new Ipv4Address(testAddress)).build());
+        ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(this.testAddress))
+            .setDestinationIpv4Address(new Ipv4Address(this.testAddress)).build());
         argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
-        argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix)));
-        argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
+        argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(this.eroIpPrefix)));
+        argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder()
+            .setDelegate(true).setAdministrative(true).build()).build());
+        return new AddLspInputBuilder().setName(this.TUNNEL_NAME).setArguments(argsBuilder.build())
+            .setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(this.nodeId).build();
     }
 }
index 571c2553c1cf398eae2710f2a85d7637a263fd34..6617781a6f56d42b2a5f8413f6b7f8e7d40e9b77 100644 (file)
@@ -42,9 +42,9 @@ public class SyncOptimizationTest {
     @Test
     public void testDoesLspDbMatchPositive() {
         final Tlvs tlvs = createTlvs(1L, false, false);
-        Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertTrue(syncOpt.doesLspDbMatch());
     }
 
@@ -52,18 +52,18 @@ public class SyncOptimizationTest {
     public void testDoesLspDbMatchNegative() {
         final Tlvs localTlvs = createTlvs(1L, false, false);
         final Tlvs remoteTlvs = createTlvs(2L, false, false);
-        Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertFalse(syncOpt.doesLspDbMatch());
     }
 
     @Test
     public void testIsSyncAvoidanceEnabledPositive() {
         final Tlvs tlvs = createTlvs(1L, true, false);
-        Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertTrue(syncOpt.isSyncAvoidanceEnabled());
     }
 
@@ -71,18 +71,18 @@ public class SyncOptimizationTest {
     public void testIsSyncAvoidanceEnabledNegative() {
         final Tlvs localTlvs = createTlvs(1L, true, false);
         final Tlvs remoteTlvs = createTlvs(2L, false, false);
-        Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertFalse(syncOpt.isSyncAvoidanceEnabled());
     }
 
     @Test
     public void testIsDeltaSyncEnabledPositive() {
         final Tlvs tlvs = createTlvs(1L, true, true);
-        Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertTrue(syncOpt.isDeltaSyncEnabled());
     }
 
@@ -90,9 +90,9 @@ public class SyncOptimizationTest {
     public void testIsDeltaSyncEnabledNegative() {
         final Tlvs localTlvs = createTlvs(1L, true, true);
         final Tlvs remoteTlvs = createTlvs(2L, false, false);
-        Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertFalse(syncOpt.isDeltaSyncEnabled());
     }
 
@@ -100,18 +100,18 @@ public class SyncOptimizationTest {
     public void testIsDbVersionPresentPositive() {
         final Tlvs localTlvs = createTlvs(null, false, false);
         final Tlvs remoteTlvs = createTlvs(2L, false, false);
-        Mockito.doReturn(localTlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(remoteTlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(localTlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertTrue(syncOpt.isDbVersionPresent());
     }
 
     @Test
     public void testIsDbVersionPresentNegative() {
         final Tlvs tlvs = createTlvs(null, true, false);
-        Mockito.doReturn(tlvs).when(pcepSession).localSessionCharacteristics();
-        Mockito.doReturn(tlvs).when(pcepSession).getRemoteTlvs();
-        final SyncOptimization syncOpt = new SyncOptimization(pcepSession);
+        Mockito.doReturn(tlvs).when(this.pcepSession).localSessionCharacteristics();
+        Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
+        final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
         assertFalse(syncOpt.isDbVersionPresent());
     }
 
@@ -124,5 +124,4 @@ public class SyncOptimizationTest {
             .addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(
                 new LspDbVersionBuilder().setLspDbVersionValue(lspDbVersion != null ? BigInteger.valueOf(lspDbVersion) : null).build()).build()).build();
     }
-
 }
index 93cd460edab4ae11a55ed1696f3d76487584365a..4c7af1a3440a1a643efac394f844d2ad661c99f8 100644 (file)
@@ -10,14 +10,11 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.bgpcep.pcep.topology.provider.TopologyProgrammingTest.MockedTopologySessionListenerFactory;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
@@ -83,161 +80,126 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
 
     private TopologyProgramming topologyProgramming;
 
-    private PCEPSession session;
-
     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
         Mockito.doReturn(true).when(this.instruction).checkedExecutionStart();
         Mockito.doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.instructionFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureAddLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureUpdateLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureRemoveLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureTriggerSyncOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureEnsureLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<AddLspOutput>>>() {
-            @Override
-            public Future<RpcResult<AddLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureAddLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
+            return TopologyProgrammingTest.this.futureAddLspOutput;
         }).when(listener).addLsp(Mockito.any(AddLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<UpdateLspOutput>>>() {
-            @Override
-            public Future<RpcResult<UpdateLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureUpdateLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
+            return TopologyProgrammingTest.this.futureUpdateLspOutput;
         }).when(listener).updateLsp(Mockito.any(UpdateLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<RemoveLspOutput>>>() {
-            @Override
-            public Future<RpcResult<RemoveLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureRemoveLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
+            return TopologyProgrammingTest.this.futureRemoveLspOutput;
         }).when(listener).removeLsp(Mockito.any(RemoveLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<TriggerSyncOutput>>>() {
-            @Override
-            public Future<RpcResult<TriggerSyncOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureTriggerSyncOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
+            return TopologyProgrammingTest.this.futureTriggerSyncOutput;
         }).when(listener).triggerSync(Mockito.any(TriggerSyncInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<EnsureLspOperationalOutput>>>() {
-            @Override
-            public Future<RpcResult<EnsureLspOperationalOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
-                return TopologyProgrammingTest.this.futureEnsureLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
+            return TopologyProgrammingTest.this.futureEnsureLspOutput;
         }).when(listener).ensureLspOperational(Mockito.any(EnsureLspOperationalInput.class));
         Mockito.doNothing().when(listener).close();
-        Mockito.doReturn(instruction).when(this.instructionFuture).get();
+        Mockito.doReturn(this.instruction).when(this.instructionFuture).get();
         Mockito.doNothing().when(this.instruction).executionCompleted(Mockito.any(InstructionStatus.class), Mockito.any(Details.class));
         Mockito.doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(Mockito.any(SubmitInstructionInput.class));
         this.topologyProgramming = new TopologyProgramming(this.scheduler, this.manager);
-        this.session = getPCEPSession(getLocalPref(), getRemotePref());
-        listener.onSessionUp(this.session);
+        final PCEPSession session = getPCEPSession(getLocalPref(), getRemotePref());
+        listener.onSessionUp(session);
     }
 
     @Test
     public void testSubmitAddLsp() throws InterruptedException, ExecutionException {
         final SubmitAddLspInputBuilder inputBuilder = new SubmitAddLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(nodeId);
+        inputBuilder.setNode(this.nodeId);
         inputBuilder.setArguments(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder().build());
         this.topologyProgramming.submitAddLsp(inputBuilder.build());
         Assert.assertNotNull(this.addLspArgs);
         Assert.assertEquals(NAME, this.addLspArgs.getName());
-        Assert.assertEquals(nodeId, this.addLspArgs.getNode());
+        Assert.assertEquals(this.nodeId, this.addLspArgs.getNode());
     }
 
     @Test
     public void testSubmitUpdateLsp() {
         final SubmitUpdateLspInputBuilder inputBuilder = new SubmitUpdateLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(nodeId);
+        inputBuilder.setNode(this.nodeId);
         this.topologyProgramming.submitUpdateLsp(inputBuilder.build());
         Assert.assertNotNull(this.updateLspArgs);
         Assert.assertEquals(NAME, this.updateLspArgs.getName());
-        Assert.assertEquals(nodeId, this.updateLspArgs.getNode());
+        Assert.assertEquals(this.nodeId, this.updateLspArgs.getNode());
     }
 
     @Test
     public void testSubmitEnsureLsp() {
         final SubmitEnsureLspOperationalInputBuilder inputBuilder = new SubmitEnsureLspOperationalInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(nodeId);
+        inputBuilder.setNode(this.nodeId);
         inputBuilder.setArguments(new ArgumentsBuilder().build());
         this.topologyProgramming.submitEnsureLspOperational(inputBuilder.build());
         Assert.assertNotNull(this.ensureLspInput);
         Assert.assertEquals(NAME, this.ensureLspInput.getName());
-        Assert.assertEquals(nodeId, this.ensureLspInput.getNode());
+        Assert.assertEquals(this.nodeId, this.ensureLspInput.getNode());
     }
 
     @Test
     public void testSubmitRemoveLsp() {
         final SubmitRemoveLspInputBuilder inputBuilder = new SubmitRemoveLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(nodeId);
+        inputBuilder.setNode(this.nodeId);
         this.topologyProgramming.submitRemoveLsp(inputBuilder.build());
         Assert.assertNotNull(this.removeLspArgs);
         Assert.assertEquals(NAME, this.removeLspArgs.getName());
-        Assert.assertEquals(nodeId, this.removeLspArgs.getNode());
+        Assert.assertEquals(this.nodeId, this.removeLspArgs.getNode());
     }
 
     @Test
     public void testSubmitTriggerSync() {
         final SubmitTriggerSyncInputBuilder inputBuilder = new SubmitTriggerSyncInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(nodeId);
+        inputBuilder.setNode(this.nodeId);
         this.topologyProgramming.submitTriggerSync(inputBuilder.build());
         Assert.assertNotNull(this.triggerSyncArgs);
         Assert.assertEquals(NAME, this.triggerSyncArgs.getName());
-        Assert.assertEquals(nodeId, this.triggerSyncArgs.getNode());
+        Assert.assertEquals(this.nodeId, this.triggerSyncArgs.getNode());
     }
 
     protected static final class MockedTopologySessionListenerFactory implements TopologySessionListenerFactory {
index 0ce023a64604b44d6148cada86fa2c595838d97c..567067ec3c2be177463029da883c81b484925102 100644 (file)
         </dependency>
 
         <!-- Testing dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index eb1ec2095f8baa74493cdc8df6c90e27c4827d19..d693bb184d261d5276adea64faef3478acc55d65 100644 (file)
@@ -8,16 +8,19 @@
 
 package org.opendaylight.bgpcep.pcep.tunnel.provider;
 
-import com.google.common.base.Optional;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
+
 import com.google.common.collect.Lists;
+import java.util.Collections;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 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;
@@ -59,7 +62,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class NodeChangedListenerTest extends AbstractDataBrokerTest {
+public class NodeChangedListenerTest extends AbstractConcurrentDataBrokerTest {
 
     private static final TopologyId PCEP_TOPOLOGY_ID = new TopologyId("pcep-topology");
     private static final TopologyId TUNNEL_TOPOLOGY_ID = new TopologyId("tunnel-topology");
@@ -74,40 +77,50 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
     private static final String LSP2_NAME = "lsp2";
     private static final long LSP2_ID = 2;
 
-    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
-    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
+    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
+        .child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.
+        builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
 
     private ListenerRegistration<NodeChangedListener> listenerRegistration;
 
     @Before
     public void setUp() throws TransactionCommitFailedException {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList()).setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
-        wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder()
+            .setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList())
+            .setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder()
+            .setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
         wTx.submit().checkedGet();
-        final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(), PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
-        this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
+        final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(),
+            PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
+        this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(
+            LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
     }
 
     @Test
     public void testNodeChangedListener() throws ReadFailedException, TransactionCommitFailedException {
         // add node -> create two nodes with TPs and link
         createNode(NODE1_ID, NODE1_IPV4, LSP1_NAME, LSP1_ID, NODE2_IPV4);
-        final Topology tunnelTopo = readTunnelTopology().get();
-        Assert.assertEquals(2, tunnelTopo.getNode().size());
+        final Topology tunnelTopo = readData(getDataBroker(), TUNNEL_TOPO_IID, tunnelTopo1 -> {
+            assertNotNull(tunnelTopo1.getNode());
+            assertEquals(2, tunnelTopo1.getNode().size());
+            return tunnelTopo1;
+        });
 
         final NodeId srcId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE1_IPV4)));
         final NodeId dstId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE2_IPV4)));
 
-        Node dst;
-        Node src;
+        final Node dst;
+        final Node src;
 
         if (tunnelTopo.getNode().get(0).getNodeId().equals(srcId)) {
             src = tunnelTopo.getNode().get(0);
-            dst =  tunnelTopo.getNode().get(1);
+            dst = tunnelTopo.getNode().get(1);
         } else {
             src = tunnelTopo.getNode().get(1);
-            dst =  tunnelTopo.getNode().get(0);
+            dst = tunnelTopo.getNode().get(0);
         }
 
         Assert.assertEquals(srcId, src.getNodeId());
@@ -136,41 +149,47 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
 
         // update second node -> adds supporting node and second link
         createNode(NODE2_ID, NODE2_IPV4, LSP2_NAME, LSP2_ID, NODE1_IPV4);
-        final Topology updatedNodeTopo = readTunnelTopology().get();
-        Assert.assertEquals(2, updatedNodeTopo.getNode().size());
-
-        Node updatedNode;
-
-        if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
-            updatedNode = updatedNodeTopo.getNode().get(1);
-        } else {
-            updatedNode = updatedNodeTopo.getNode().get(0);
-        }
-
-        Assert.assertEquals(1, updatedNode.getSupportingNode().size());
-        final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
-        Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
-
-        Assert.assertEquals(2, updatedNodeTopo.getLink().size());
-
-        Link link2;
-        if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
-            link2 = updatedNodeTopo.getLink().get(1);
-        } else {
-            link2 = updatedNodeTopo.getLink().get(0);
-        }
-
-        Assert.assertEquals(dstId, link2.getSource().getSourceNode());
-        Assert.assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
-        Assert.assertEquals(srcId, link2.getDestination().getDestNode());
-        Assert.assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+        readData(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+            assertNotNull(updatedNodeTopo.getNode());
+            Assert.assertEquals(2, updatedNodeTopo.getNode().size());
+            final Node updatedNode;
+            if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
+                updatedNode = updatedNodeTopo.getNode().get(1);
+            } else {
+                updatedNode = updatedNodeTopo.getNode().get(0);
+            }
+
+            assertNotNull(updatedNode.getSupportingNode());
+            Assert.assertEquals(1, updatedNode.getSupportingNode().size());
+            final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
+            Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
+            Assert.assertEquals(2, updatedNodeTopo.getLink().size());
+            return updatedNodeTopo;
+
+        });
+
+        readData(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+            final Link link2;
+            if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
+                link2 = updatedNodeTopo.getLink().get(1);
+            } else {
+                link2 = updatedNodeTopo.getLink().get(0);
+            }
+            assertEquals(dstId, link2.getSource().getSourceNode());
+            assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
+            assertEquals(srcId, link2.getDestination().getDestNode());
+            assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+            return updatedNodeTopo;
+        });
 
         // remove nodes -> remove link
         removeNode(NODE1_ID);
         removeNode(NODE2_ID);
-        final Topology removedNodeTopo = readTunnelTopology().get();
-        Assert.assertEquals(0, removedNodeTopo.getNode().size());
-        Assert.assertEquals(0, removedNodeTopo.getLink().size());
+        readData(getDataBroker(), TUNNEL_TOPO_IID, removedNodeTopo -> {
+            assertEquals(0, removedNodeTopo.getNode().size());
+            assertEquals(0, removedNodeTopo.getLink().size());
+            return removedNodeTopo;
+        });
     }
 
     @After
@@ -178,20 +197,30 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
         this.listenerRegistration.close();
     }
 
-    private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
+    private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId,
+        final String dstIpv4Address) throws TransactionCommitFailedException {
         final NodeBuilder nodeBuilder = new NodeBuilder();
         nodeBuilder.setKey(new NodeKey(nodeId));
         nodeBuilder.setNodeId(nodeId);
         final PathBuilder pathBuilder = new PathBuilder();
         pathBuilder.setKey(new PathKey(new LspId(lspId)));
-        pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] {0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
-        pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
-        final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Lists.newArrayList(pathBuilder.build())).build();
+        pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(
+            new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
+        pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder()
+            .setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(
+                new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(
+                    new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address))
+                    .build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
+        final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(
+            Collections.singletonList(pathBuilder.build())).build();
         final Node1Builder node1Builder = new Node1Builder();
-        node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
+        node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized)
+            .setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address)))
+            .build());
         nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
+        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class,
+            new NodeKey(nodeId)).build(), nodeBuilder.build());
         wTx.submit().checkedGet();
     }
 
@@ -200,9 +229,4 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
         wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
         wTx.submit().checkedGet();
     }
-
-    private Optional<Topology> readTunnelTopology() throws ReadFailedException {
-        final ReadTransaction rTx = getDataBroker().newReadOnlyTransaction();
-        return rTx.read(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID).checkedGet();
-    }
 }
index 59b49a0112e885f65642ba3e15e36b9fa9aef8ed..efeb669c9617de7228d05efc5b97d2b6683ddfbf 100644 (file)
@@ -13,20 +13,17 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
 import org.opendaylight.bgpcep.programming.spi.SchedulerException;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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.IpAddress;
@@ -97,7 +94,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public class TunnelProgrammingTest extends AbstractDataBrokerTest {
+public class TunnelProgrammingTest extends AbstractConcurrentDataBrokerTest {
 
     private static final TopologyId TOPOLOGY_ID = new TopologyId("tunnel-topo");
     private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).build();
@@ -142,64 +139,43 @@ public class TunnelProgrammingTest extends AbstractDataBrokerTest {
         MockitoAnnotations.initMocks(this);
         Mockito.doReturn(true).when(this.instruction).checkedExecutionStart();
         Mockito.doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.instructionFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureAddLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureUpdateLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(final InvocationOnMock invocation) throws Throwable {
-                final Runnable callback = (Runnable) invocation.getArguments()[0];
-                callback.run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            final Runnable callback = (Runnable) invocation.getArguments()[0];
+            callback.run();
+            return null;
         }).when(this.futureRemoveLspOutput).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<AddLspOutput>>>() {
-            @Override
-            public Future<RpcResult<AddLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TunnelProgrammingTest.this.addLspInput = (AddLspInput) invocation.getArguments()[0];
-                return TunnelProgrammingTest.this.futureAddLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TunnelProgrammingTest.this.addLspInput = (AddLspInput) invocation.getArguments()[0];
+            return TunnelProgrammingTest.this.futureAddLspOutput;
         }).when(this.topologyService).addLsp(Mockito.any(AddLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<UpdateLspOutput>>>() {
-            @Override
-            public Future<RpcResult<UpdateLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TunnelProgrammingTest.this.updateLspInput = (UpdateLspInput) invocation.getArguments()[0];
-                return TunnelProgrammingTest.this.futureUpdateLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TunnelProgrammingTest.this.updateLspInput = (UpdateLspInput) invocation.getArguments()[0];
+            return TunnelProgrammingTest.this.futureUpdateLspOutput;
         }).when(this.topologyService).updateLsp(Mockito.any(UpdateLspInput.class));
-        Mockito.doAnswer(new Answer<Future<RpcResult<RemoveLspOutput>>>() {
-            @Override
-            public Future<RpcResult<RemoveLspOutput>> answer(final InvocationOnMock invocation) throws Throwable {
-                TunnelProgrammingTest.this.removeLspInput = (RemoveLspInput) invocation.getArguments()[0];
-                return TunnelProgrammingTest.this.futureRemoveLspOutput;
-            }
+        Mockito.doAnswer(invocation -> {
+            TunnelProgrammingTest.this.removeLspInput = (RemoveLspInput) invocation.getArguments()[0];
+            return TunnelProgrammingTest.this.futureRemoveLspOutput;
         }).when(this.topologyService).removeLsp(Mockito.any(RemoveLspInput.class));
-        Mockito.doReturn(instruction).when(this.instructionFuture).get();
+        Mockito.doReturn(this.instruction).when(this.instructionFuture).get();
         Mockito.doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(Mockito.any(SubmitInstructionInput.class));
 
         createInitialTopology();
-        this.tunnelProgramming = new TunnelProgramming(scheduler, getDataBroker(), topologyService);
+        this.tunnelProgramming = new TunnelProgramming(this.scheduler, getDataBroker(), this.topologyService);
     }
 
     @Test