Clean up check tests and util tests 11/51911/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 15 Feb 2017 12:15:21 +0000 (13:15 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 15 Feb 2017 14:43:23 +0000 (15:43 +0100)
Remove duplicated code on check utils for tests.
Clean up PCC mock tests

Change-Id: I1347f6561cb4ede6c8f4147680d92c3a84f92520
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
26 files changed:
bgp/openconfig-state/pom.xml
bgp/openconfig-state/src/test/java/org/opendaylight/protocol/bgp/state/StateProviderImplTest.java
bgp/peer-acceptor/src/test/java/org/opendaylight/protocol/bgp/peer/acceptor/BGPPeerAcceptorImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPDispatcherTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/CheckUtil.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SimpleSessionListener.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCEndPointIpv4ObjectParserTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCIncrementalSyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSessionListenerTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncAvoidanceProcedureTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredFullDBResyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredLspResyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredSyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelManagerImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/TestingSessionListener.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/TestingSessionListenerFactory.java
testtool-util/src/main/java/org/opendaylight/protocol/util/CheckUtil.java

index d9b686fe533e6ef8a61d5507cda6e8d91a1dec60..f3594dec72ac04e41ee5122c04e70a235021880f 100644 (file)
             <scope>test</scope>
             <type>test-jar</type>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-binding-broker-impl</artifactId>
index d150c456b92c5655c75b95b2425c38c9f67a7052..8bf9f71bc69476b856bb4898e5faa42699c3d671 100644 (file)
@@ -8,13 +8,12 @@
 
 package org.opendaylight.protocol.bgp.state;
 
-import static org.junit.Assert.assertFalse;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.util.CheckUtil.checkNull;
+import static org.opendaylight.protocol.util.CheckUtil.readData;
 
-import com.google.common.base.Stopwatch;
-import com.google.common.util.concurrent.Uninterruptibles;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -22,20 +21,14 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.LongAdder;
-import java.util.function.Function;
 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.opendaylight.controller.md.sal.binding.api.DataBroker;
-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.common.api.data.ReadFailedException;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
@@ -110,7 +103,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
@@ -404,49 +396,6 @@ public class StateProviderImplTest extends AbstractDataBrokerTest {
         return gracefulRestart;
     }
 
-    private static <T extends DataObject> void checkNull(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
-        throws ReadFailedException {
-        AssertionError lastError = null;
-        final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
-            try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
-                final com.google.common.base.Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
-                    try {
-                        assertFalse(data.isPresent());
-                        return;
-                    } catch (final AssertionError e) {
-                        lastError = e;
-                        Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
-                    }
-            }
-        }
-        Assert.fail(lastError.getMessage());
-        throw lastError;
-    }
-
-    private static <R, T extends DataObject> void readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
-        final Function<T, R> function)
-        throws ReadFailedException {
-        AssertionError lastError = null;
-        final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
-            try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
-                final com.google.common.base.Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
-                if (data.isPresent()) {
-                    try {
-                        function.apply(data.get());
-                        return;
-                    } catch (final AssertionError e) {
-                        lastError = e;
-                        Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
-                    }
-                }
-            }
-        }
-        Assert.fail(lastError.getMessage());
-        throw lastError;
-    }
-
     private Global buildGlobalExpected(final long PrefixesAndPaths) {
         return new GlobalBuilder()
             .setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.
index d412d3233e6a5aba91a95b58dabf5a553a7347d4..7268026639d1f46c521d14ae328e32ee15d35ca7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.peer.acceptor;
 
+import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.collect.Sets;
index 81a44ebfebb2858b0ef2570396049c5674ab2e87..41c438dd554deae2322e12336577dfa779ac7908 100644 (file)
@@ -278,6 +278,7 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
             new InetSocketAddress(RIB_ID, PORT), RETRY_TIMER, true);
         Thread.sleep(200);
         waitFutureSuccess(future);
+        Thread.sleep(100);
         return future.getNow();
     }
 
index ac69f2419cac6f1bb080953aa43a35f207e91777..ade042d1e7bb577a43b7c64bf3a3f8d571015dd1 100644 (file)
@@ -11,9 +11,7 @@ import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Stopwatch;
 import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.Uninterruptibles;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
@@ -23,7 +21,6 @@ import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BgpExtendedMessageUtil;
@@ -32,7 +29,6 @@ import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.spi.State;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -109,18 +105,6 @@ public class AbstractBGPDispatcherTest {
         return new BGPSessionPreferences(AS_NUMBER, HOLD_TIMER, bgpId, AS_NUMBER, tlvs, Optional.absent());
     }
 
-    protected static void checkIdleState(final SimpleSessionListener listener) {
-        final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
-            if (State.IDLE != listener.getState()) {
-                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            } else {
-                return;
-            }
-        }
-        Assert.fail();
-    }
-
     protected Channel createServer(final InetSocketAddress serverAddress) throws InterruptedException {
         this.registry.addPeer(new IpAddress(new Ipv4Address(serverAddress.getAddress().getHostAddress())),
             this.serverListener, createPreferences(serverAddress));
index 2be5ce5d135ac742278d00f8f5a1f75b60535b84..f4520282760cb3b475e4b85eec34cbf06e4dd9a9 100644 (file)
@@ -11,21 +11,18 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkReceivedMessages;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
-import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.Uninterruptibles;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import java.net.InetSocketAddress;
 import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
@@ -52,11 +49,6 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
     private RIBImpl ribImpl;
     private Channel serverChannel;
 
-    @FunctionalInterface
-    private interface CheckEquals {
-        void check();
-    }
-
     @Before
     public void setUp() throws Exception {
         super.setUp();
@@ -303,20 +295,4 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         session4.close();
         session5.close();
     }
-
-    private static void checkEquals(final CheckEquals function) throws Exception {
-        AssertionError lastError = null;
-        final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
-            try {
-                function.check();
-                return;
-            } catch (final AssertionError e) {
-                lastError = e;
-                Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
-            }
-        }
-        Assert.fail(lastError.getMessage());
-        throw lastError;
-    }
 }
index f2ada6e6e6f961bfd2fa390bf38b2c13f184cb59..8cec9a283b59395a33541e18171e7c6f83501619 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkReceivedMessages;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.collect.ImmutableMap;
index ae662a2ee26e06bbf187d9ab2fbd81beb55f0be1..81dce3b1064e26ec2d5fd9ddeab1c990258dc69a 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkReceivedMessages;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.collect.ImmutableMap;
index d7e4bb3bcb8582f897cd48557aca397465d13865..308ca462551fe7e8de270f64be850304e8b196a6 100755 (executable)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 
+import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
index 6597ee98939962ade1934c986ae1a5e18f2af927..499ae8bbc8b6dc37fcc818391ead43d99ef058aa 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImplTest.checkIdleState;
+import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
 
 import com.google.common.collect.Lists;
 import io.netty.channel.Channel;
@@ -22,8 +22,6 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelPipeline;
 import io.netty.channel.EventLoop;
 import io.netty.channel.embedded.EmbeddedChannel;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
index 03aa2e9a54c1ceac8634c19f5bbabee3a3c93a7b..25e0274374194d5cfc34dfe5baddbd5643d37035 100644 (file)
@@ -11,18 +11,14 @@ import com.google.common.base.Stopwatch;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.protocol.bgp.rib.spi.State;
 
 public final class CheckUtil {
-    private static final int TIMEOUT = 40;
-    private static final int SLEEP_UNINTERRUPTIBLY = 50;
-
-    static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
-        throws ReadFailedException {
+    public static void checkIdleState(final SimpleSessionListener listener) {
         final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
-            if (listener.getListMsg().size() != numberOfMessages) {
-                Uninterruptibles.sleepUninterruptibly(SLEEP_UNINTERRUPTIBLY, TimeUnit.MILLISECONDS);
+        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
+            if (State.IDLE != listener.getState()) {
+                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
             } else {
                 return;
             }
index b24289ebbea12beacf40b6c188e20b4673763cff..1cc49d09e8d3fbc11d97ac40aab4d3c5f20a8527 100644 (file)
@@ -12,11 +12,13 @@ import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import javax.annotation.concurrent.GuardedBy;
 import org.junit.Assert;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
 import org.opendaylight.protocol.bgp.rib.spi.State;
+import org.opendaylight.protocol.util.CheckUtil.ListenerCheck;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
@@ -25,9 +27,10 @@ import org.slf4j.LoggerFactory;
 /**
  * Listener for the client.
  */
-public final class SimpleSessionListener implements BGPSessionListener {
+public final class SimpleSessionListener implements BGPSessionListener, ListenerCheck {
 
     private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
+    @GuardedBy("this")
     private final List<Notification> listMsg = Lists.newArrayList();
     private BGPSession session;
     private final CountDownLatch sessionLatch = new CountDownLatch(1);
@@ -35,7 +38,7 @@ public final class SimpleSessionListener implements BGPSessionListener {
     public SimpleSessionListener() {
     }
 
-    List<Notification> getListMsg() {
+    synchronized List<Notification> getListMsg() {
         return this.listMsg;
     }
 
@@ -62,7 +65,7 @@ public final class SimpleSessionListener implements BGPSessionListener {
     }
 
     @Override
-    public void onMessage(final BGPSession session, final Notification message) {
+    public synchronized void onMessage(final BGPSession session, final Notification message) {
         this.listMsg.add(message);
         LOG.debug("Message received: {}", message);
     }
@@ -87,4 +90,9 @@ public final class SimpleSessionListener implements BGPSessionListener {
         Assert.assertEquals("Session up", true, Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
         return (BGPSessionImpl) this.session;
     }
+
+    @Override
+    public int getListMessageSize() {
+        return this.listMsg.size();
+    }
 }
index 3066e46e4cf947ae755605568deaccb270528d4d..c0deae3a77cfc97f5385a0dab3d89e1e0fa02794 100644 (file)
@@ -39,7 +39,7 @@ import org.opendaylight.protocol.util.InetSocketAddressUtil;
 public class PCCDispatcherImplTest {
 
     private static final List<PCEPCapability> CAPS = new ArrayList<>();
-    private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(30, 120, CAPS);
+    private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(10, 40, CAPS);
     private final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(PROPOSAL, 0);
     private PCCDispatcherImpl dispatcher;
     private PCEPDispatcher pcepDispatcher;
@@ -65,7 +65,7 @@ public class PCCDispatcherImplTest {
         closeEventLoopGroups();
     }
 
-    private void closeEventLoopGroups() throws ExecutionException, InterruptedException {
+    private void closeEventLoopGroups() {
         this.workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
         this.bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
     }
index b0cd7ccb128ac8d4bf2623bd6e56472f092037ad..4504683e3f74c7056895b449eeae450565214202 100644 (file)
@@ -23,8 +23,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 
 public class PCCEndPointIpv4ObjectParserTest {
 
-    private final static String ip1 = "1.2.3.4";
-    private final static String ip2 = "1.2.3.5";
+    private final static String IP1 = "1.2.3.4";
+    private final static String IP2 = "1.2.3.5";
 
     @Test(expected=PCEPDeserializerException.class)
     public void testParseEmptyObject() throws PCEPDeserializerException {
@@ -38,12 +38,12 @@ public class PCCEndPointIpv4ObjectParserTest {
     public void testParseObject() throws PCEPDeserializerException {
         final ObjectHeader header = new ObjectHeaderImpl(false, false);
         final ByteBuf bytes = Unpooled.buffer();
-        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(this.ip1)));
-        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(this.ip2)));
+        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(IP1)));
+        bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4Address(IP2)));
         final EndpointsObj output = (EndpointsObj) new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
 
-        assertEquals(this.ip1, ((Ipv4Case) output.getAddressFamily()).getIpv4().getSourceIpv4Address().getValue());
-        assertEquals(this.ip2, ((Ipv4Case) output.getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue());
+        assertEquals(IP1, ((Ipv4Case) output.getAddressFamily()).getIpv4().getSourceIpv4Address().getValue());
+        assertEquals(IP2, ((Ipv4Case) output.getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue());
         assertFalse(output.isIgnore());
         assertFalse(output.isProcessingRule());
     }
index 1079e7e56c101c27aa55c13c3aaab64ea0778d77..4a71765f050e9a33956a3ec295616317edbee8c3 100644 (file)
@@ -8,15 +8,11 @@
 
 package org.opendaylight.protocol.pcep.pcc.mock;
 
-import static org.junit.Assert.assertFalse;
-
 import com.google.common.base.Optional;
 import io.netty.channel.Channel;
 import java.math.BigInteger;
-import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
@@ -33,24 +29,22 @@ public class PCCIncrementalSyncTest extends PCCMockCommon {
      */
     private final String[] mainInputIncrementalSync = new String[]{"--local-address", this.localAddress.getHostString(),
         "--remote-address", InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp",
-        lsp.toString(), "--log-level", "DEBUG", "-ka", "30", "-d", "120", "--reconnect", "-1", "--redelegation-timeout",
+        this.lsp.toString(), "--log-level", "DEBUG", "-ka", "30", "-d", "120", "--reconnect", "-1", "--redelegation-timeout",
         "0", "--state-timeout", "-1", "--incremental-sync-procedure", "10", "5", "5"};
 
     @Test
-    public void testSessionIncrementalSyncEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
+    public void testSessionIncrementalSyncEstablishment() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(8);
         final Channel channel = createServer(factory, this.remoteAddress, new PCCServerPeerProposal(numberOflspAndDBv));
-        Main.main(mainInputIncrementalSync);
-        Thread.sleep(1000);
+        Main.main(this.mainInputIncrementalSync);
         final TestingSessionListener pceSessionListener = getListener(factory);
         checkSynchronizedSession(8, pceSessionListener, numberOflspAndDBv);
-        Thread.sleep(4000);
-        assertFalse(pceSessionListener.isUp());
-        final int expetedNumberOfLspAndEndOfSync = 3;
+        Thread.sleep(6000);
+        final int expetecdNumberOfLspAndEndOfSync = 3;
         final BigInteger expectedFinalDBVersion = BigInteger.valueOf(10);
         final TestingSessionListener sessionListenerAfterReconnect = getListener(factory);
-        checkResyncSession(Optional.absent(), expetedNumberOfLspAndEndOfSync, numberOflspAndDBv, expectedFinalDBVersion, sessionListenerAfterReconnect);
+        checkResyncSession(Optional.absent(), expetecdNumberOfLspAndEndOfSync, 3, numberOflspAndDBv, expectedFinalDBVersion, sessionListenerAfterReconnect);
         channel.close().get();
     }
 
index 6a79f329c3f2e0e8e72a40638d08e3336f37b319..dd7024d104728c7704f47a110f2929ff3a276b0f 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
@@ -28,8 +29,8 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
-import org.junit.Assert;
 import org.junit.Before;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
 import org.opendaylight.protocol.pcep.PCEPPeerProposal;
@@ -59,12 +60,11 @@ public abstract class PCCMockCommon {
     private final static short KEEP_ALIVE = 30;
     private final static short DEAD_TIMER = 120;
     private static final long SLEEP_FOR = 50;
-    protected final int port = InetSocketAddressUtil.getRandomPort();
-    protected final InetSocketAddress remoteAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
-    protected final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", port);
+    private final int port = InetSocketAddressUtil.getRandomPort();
+    protected final InetSocketAddress remoteAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(this.port);
+    protected final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", this.port);
     protected PCCSessionListener pccSessionListener;
     private PCEPDispatcher pceDispatcher;
-    private PCCDispatcherImpl pccDispatcher;
 
     protected abstract List<PCEPCapability> getCapabilities();
 
@@ -81,24 +81,12 @@ public abstract class PCCMockCommon {
         Exception {
         final TestingSessionListener sessionListener = checkSessionListenerNotNull(factory, localAddress);
         assertTrue(sessionListener.isUp());
-        checkNumberOfMessages(numMessages, sessionListener);
+        checkReceivedMessages(sessionListener, numMessages);
         assertEquals(numMessages, sessionListener.messages().size());
         channel.close().get();
         return sessionListener;
     }
 
-    private static void checkNumberOfMessages(final int expectedNMessages, final TestingSessionListener listener) throws Exception {
-        final Stopwatch sw = Stopwatch.createStarted();
-        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
-            if (expectedNMessages != listener.messages().size()) {
-                Uninterruptibles.sleepUninterruptibly(SLEEP_FOR, TimeUnit.MILLISECONDS);
-            } else {
-                return;
-            }
-        }
-        Assert.assertEquals(expectedNMessages, listener.messages().size());
-    }
-
     static TestingSessionListener checkSessionListenerNotNull(final TestingSessionListenerFactory factory, final String localAddress) {
         final Stopwatch sw = Stopwatch.createStarted();
         TestingSessionListener listener;
@@ -119,7 +107,7 @@ public abstract class PCCMockCommon {
     }
 
     protected Channel createServer(final TestingSessionListenerFactory factory, final InetSocketAddress
-        serverAddress2, final PCEPPeerProposal peerProposal) throws InterruptedException {
+        serverAddress2, final PCEPPeerProposal peerProposal) {
         final PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
         final StatefulActivator activator07 = new StatefulActivator();
         final SyncOptimizationsActivator optimizationsActivator = new SyncOptimizationsActivator();
@@ -130,9 +118,8 @@ public abstract class PCCMockCommon {
         return future.channel();
     }
 
-    protected static void checkSynchronizedSession(final int numberOfLsp, final TestingSessionListener pceSessionListener, final BigInteger expectedeInitialDb) throws InterruptedException {
+    protected static void checkSynchronizedSession(final int numberOfLsp, final TestingSessionListener pceSessionListener, final BigInteger expectedeInitialDb) throws ReadFailedException {
         assertTrue(pceSessionListener.isUp());
-        Thread.sleep(1000);
         //Send Open with LspDBV = 1
         final List<Message> messages = pceSessionListener.messages();
         final int numberOfSyncMessage = 1;
@@ -141,7 +128,7 @@ public abstract class PCCMockCommon {
             checkSequequenceDBVersionSync(messages, expectedeInitialDb);
             numberOfLspExpected += numberOfSyncMessage;
         }
-        assertEquals(numberOfLspExpected, messages.size());
+        checkReceivedMessages(pceSessionListener, numberOfLspExpected);
         final PCEPSession session = pceSessionListener.getSession();
         checkSession(session, DEAD_TIMER, KEEP_ALIVE);
 
@@ -149,12 +136,13 @@ public abstract class PCCMockCommon {
         assertNull(session.localSessionCharacteristics().getAugmentation(Tlvs3.class).getLspDbVersion().getLspDbVersionValue());
     }
 
-    protected static void checkResyncSession(final Optional<Integer> startAtNumberLsp, final int expectedNumberOfLsp, final BigInteger startingDBVersion,
-        final BigInteger expectedDBVersion, final TestingSessionListener pceSessionListener) throws InterruptedException {
+    protected static void checkResyncSession(final Optional<Integer> startAtNumberLsp, final int expectedNumberOfLsp,
+        final int expectedTotalMessages, final BigInteger startingDBVersion, final BigInteger expectedDBVersion,
+        final TestingSessionListener pceSessionListener) throws Exception {
         assertNotNull(pceSessionListener.getSession());
         assertTrue(pceSessionListener.isUp());
-        Thread.sleep(50);
         final List<Message> messages;
+        checkReceivedMessages(pceSessionListener, expectedTotalMessages);
         if (startAtNumberLsp.isPresent()) {
             messages = pceSessionListener.messages().subList(startAtNumberLsp.get(), startAtNumberLsp.get() + expectedNumberOfLsp);
         } else {
@@ -197,15 +185,15 @@ public abstract class PCCMockCommon {
     }
 
     protected Future<PCEPSession> createPCCSession(final BigInteger DBVersion) {
-        this.pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
+        final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
         final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(3, this.localAddress.getAddress(), 0, -1, new HashedWheelTimer(),
             Optional.absent());
 
         return pccDispatcher.createClient(this.remoteAddress, -1,
                 () -> {
-                    pccSessionListener = new PCCSessionListener(1, tunnelManager, false);
-                    return pccSessionListener;
+                    this.pccSessionListener = new PCCSessionListener(1, tunnelManager, false);
+                    return this.pccSessionListener;
                 }, snf, null, this.localAddress, DBVersion);
     }
 
index cb989257dca4b9eb041965b4246d18250cfe4af6..1c4093cb24cbd8d8f75c13f3ca6acd33e24c0843 100644 (file)
@@ -28,7 +28,7 @@ public final class PCCMockTest extends PCCMockCommon {
     public void testSessionEstablishment() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final Channel channel = createServer(factory, this.remoteAddress);
-        Main.main(mainInput);
+        Main.main(this.mainInput);
         Thread.sleep(1000);
         //3 reported LSPs + syc
         final int numMessages = 4;
@@ -58,7 +58,7 @@ public final class PCCMockTest extends PCCMockCommon {
             "--pcc", "2"});
         Thread.sleep(1000);
         //PCE1
-        int numMessages = 2;
+        final int numMessages = 2;
         checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
         checkSessionListener(numMessages, channel, factory, localAddress2);
         //PCE2
index 90ce8817e31aa27d64ff1857d769b8508300f347..0d87ba3ed7097dc2dbb31d858ac842e3e13fde93 100644 (file)
@@ -71,7 +71,7 @@ public class PCCSessionListenerTest {
                 PCCSessionListenerTest.this.sendMessages.add((Message) invocation.getArguments()[0]);
                 return null;
             }
-        }).when(mockedSession).sendMessage(Mockito.any(Message.class));
+        }).when(this.mockedSession).sendMessage(Mockito.any(Message.class));
     }
 
     @After
@@ -81,65 +81,65 @@ public class PCCSessionListenerTest {
 
     @Test
     public void testOnMessage() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
-        listener.onMessage(mockedSession, createUpdMsg(true));
-        Mockito.verify(tunnelManager).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
-        Mockito.verify(tunnelManager, Mockito.never()).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
-        listener.onMessage(mockedSession, createUpdMsg(false));
-        Mockito.verify(tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
-        Mockito.verify(tunnelManager, Mockito.never()).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
-
-        listener.onMessage(mockedSession, createInitMsg(false, true));
-        Mockito.verify(tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
-        Mockito.verify(tunnelManager).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
-        listener.onMessage(mockedSession, createInitMsg(true, false));
-        Mockito.verify(tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
-        Mockito.verify(tunnelManager, Mockito.times(2)).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
-        listener.onMessage(mockedSession, createInitMsg(false, false));
-        Mockito.verify(tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
-        Mockito.verify(tunnelManager, Mockito.times(3)).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
+        listener.onMessage(this.mockedSession, createUpdMsg(true));
+        Mockito.verify(this.tunnelManager).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
+        Mockito.verify(this.tunnelManager, Mockito.never()).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+        listener.onMessage(this.mockedSession, createUpdMsg(false));
+        Mockito.verify(this.tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
+        Mockito.verify(this.tunnelManager, Mockito.never()).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+
+        listener.onMessage(this.mockedSession, createInitMsg(false, true));
+        Mockito.verify(this.tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
+        Mockito.verify(this.tunnelManager).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+        listener.onMessage(this.mockedSession, createInitMsg(true, false));
+        Mockito.verify(this.tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
+        Mockito.verify(this.tunnelManager, Mockito.times(2)).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+        listener.onMessage(this.mockedSession, createInitMsg(false, false));
+        Mockito.verify(this.tunnelManager, Mockito.times(2)).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
+        Mockito.verify(this.tunnelManager, Mockito.times(3)).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
     }
 
     @Test
     public void testOnMessageErrorMode() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, true);
-        listener.onMessage(mockedSession, createUpdMsg(true));
-        Mockito.verify(mockedSession).sendMessage(Mockito.any(Message.class));
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, true);
+        listener.onMessage(this.mockedSession, createUpdMsg(true));
+        Mockito.verify(this.mockedSession).sendMessage(Mockito.any(Message.class));
     }
 
     @Test
     public void testOnSessionUp() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
-        listener.onSessionUp(mockedSession);
-        Mockito.verify(tunnelManager).onSessionUp(Mockito.any(PCCSession.class));
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
+        listener.onSessionUp(this.mockedSession);
+        Mockito.verify(this.tunnelManager).onSessionUp(Mockito.any(PCCSession.class));
     }
 
     @Test
     public void testOnSessionDown() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
-        listener.onSessionDown(mockedSession, new Exception());
-        Mockito.verify(tunnelManager).onSessionDown(Mockito.any(PCCSession.class));
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
+        listener.onSessionDown(this.mockedSession, new Exception());
+        Mockito.verify(this.tunnelManager).onSessionDown(Mockito.any(PCCSession.class));
     }
 
     @Test
     public void testSendError() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
-        listener.onSessionUp(mockedSession);
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
+        listener.onSessionUp(this.mockedSession);
         listener.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.ATTEMPT_2ND_SESSION, 0));
-        Mockito.verify(mockedSession).sendMessage(Mockito.any());
+        Mockito.verify(this.mockedSession).sendMessage(Mockito.any());
     }
 
     @Test
     public void testSendReport() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
-        listener.onSessionUp(mockedSession);
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
+        listener.onSessionUp(this.mockedSession);
         listener.sendReport(null);
-        Mockito.verify(mockedSession).sendMessage(Mockito.any());
+        Mockito.verify(this.mockedSession).sendMessage(Mockito.any());
     }
 
     @Test
     public void testGetId() {
-        final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+        final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
         Assert.assertEquals(1, listener.getId());
     }
 
index c80dd5c97c2dfff871fcc11285f2fff891ac37d1..00df509619a3b255575c037fc848b8cb419c4ce8 100644 (file)
@@ -13,10 +13,8 @@ import static org.junit.Assert.assertNotNull;
 import com.google.common.base.Optional;
 import io.netty.channel.Channel;
 import java.math.BigInteger;
-import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.PCEPSession;
@@ -25,16 +23,16 @@ import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCPeerProposal;
 
 public class PCCSyncAvoidanceProcedureTest extends PCCMockCommon {
     @Test
-    public void testSessionAvoidanceDesynchronizedEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
+    public void testSessionAvoidanceDesynchronizedEstablishment() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
 
         final Channel channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
-        PCEPSession session = createPCCSession(BigInteger.TEN).get();
+        final PCEPSession session = createPCCSession(BigInteger.TEN).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
         assertNotNull(pceSessionListener);
         assertNotNull(pceSessionListener.getSession());
-        checkResyncSession(Optional.absent(), 11, null, BigInteger.valueOf(10), pceSessionListener);
+        checkResyncSession(Optional.absent(), 11, 11, null, BigInteger.valueOf(10), pceSessionListener);
         channel.close().get();
     }
 
index df48b5eb95b3ad8140a4f58a7fe27337e9fefcc7..4f5ea7098576e2fb56212994c1acc4d089e8c32b 100644 (file)
@@ -34,22 +34,21 @@ 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.types.rev131005.Message;
 
 public class PCCTriggeredFullDBResyncTest extends PCCMockCommon {
-    private Channel channel;
 
     @Test
     public void testSessionTriggeredFullDBReSync() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final int lspQuantity = 3;
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(lspQuantity);
-        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
-        PCEPSession session = createPCCSession(numberOflspAndDBv).get();
+        final Channel channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
+        final PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
         assertNotNull(pceSessionListener);
         checkSynchronizedSession(lspQuantity, pceSessionListener, numberOflspAndDBv);
-        pccSessionListener.onMessage(session, createTriggerLspResync());
+        this.pccSessionListener.onMessage(session, createTriggerLspResync());
         final TestingSessionListener sessionListenerAfterReconnect = getListener(factory);
-        checkResyncSession(Optional.of(lspQuantity), 4, null, numberOflspAndDBv, sessionListenerAfterReconnect);
+        checkResyncSession(Optional.of(lspQuantity), 4,8, null, numberOflspAndDBv, sessionListenerAfterReconnect);
         channel.close().get();
     }
 
index ed7bb6c231e846837a3510455c3a6bf6e06d1f19..1c923231e0ecf907a9723bb7dd257461ba20ac28 100644 (file)
@@ -34,23 +34,21 @@ 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.types.rev131005.Message;
 
 public class PCCTriggeredLspResyncTest extends PCCMockCommon {
-    private Channel channel;
-
     @Test
     public void testSessionTriggeredLspReSync() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final int lspQuantity = 3;
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(lspQuantity);
 
-        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
-        PCEPSession session = createPCCSession(numberOflspAndDBv).get();
+        final Channel channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
+        final PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
         assertNotNull(pceSessionListener);
         checkSynchronizedSession(lspQuantity, pceSessionListener, numberOflspAndDBv);
-        pccSessionListener.onMessage(session, createTriggerLspResync());
+        this.pccSessionListener.onMessage(session, createTriggerLspResync());
         final TestingSessionListener sessionListenerAfterReconnect = getListener(factory);
-        checkResyncSession(Optional.of(lspQuantity), 2, null, numberOflspAndDBv, sessionListenerAfterReconnect);
+        checkResyncSession(Optional.of(lspQuantity), 2, 6, null, numberOflspAndDBv, sessionListenerAfterReconnect);
         channel.close().get();
     }
 
index d129313db7b29d6892e26acc1ed676f100b352f4..b337c76b7a789855e22b561a784089811f469d4a 100644 (file)
@@ -33,22 +33,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.types.rev131005.Message;
 
 public class PCCTriggeredSyncTest extends PCCMockCommon {
-
-    private Channel channel;
-
     @Test
     public void testSessionTriggeredSync() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
-        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
+        final Channel channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(3);
-        PCEPSession session = createPCCSession(numberOflspAndDBv).get();
+        final PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
         assertNotNull(pceSessionListener);
         checkSynchronizedSession(0, pceSessionListener, BigInteger.ZERO);
-        pccSessionListener.onMessage(session, createTriggerMsg());
+        this.pccSessionListener.onMessage(session, createTriggerMsg());
         checkSynchronizedSession(3, pceSessionListener, numberOflspAndDBv);
-        this.channel.close().get();
+        channel.close().get();
     }
 
     private Message createTriggerMsg() {
index dac29864de95d39990188ec242e4144bfea949a7..aa960dad85cc7b917bdd8305a71ab9ad9f73267c 100644 (file)
@@ -75,24 +75,24 @@ public class PCCTunnelManagerImplTest {
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        Mockito.doNothing().when(session1).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.doNothing().when(this.session1).sendReport(Mockito.any(Pcrpt.class));
         Mockito.doAnswer(new Answer<Void>() {
             @Override
             public Void answer(final InvocationOnMock invocation) throws Throwable {
-                errorsSession1.add(getError((Pcerr) invocation.getArguments()[0]));
+                PCCTunnelManagerImplTest.this.errorsSession1.add(getError((Pcerr) invocation.getArguments()[0]));
                 return null;
             }
-        }).when(session1).sendError(Mockito.any(Pcerr.class));
-        Mockito.doReturn(0).when(session1).getId();
-        Mockito.doNothing().when(session2).sendReport(Mockito.any(Pcrpt.class));
+        }).when(this.session1).sendError(Mockito.any(Pcerr.class));
+        Mockito.doReturn(0).when(this.session1).getId();
+        Mockito.doNothing().when(this.session2).sendReport(Mockito.any(Pcrpt.class));
         Mockito.doAnswer(new Answer<Void>() {
             @Override
             public Void answer(final InvocationOnMock invocation) throws Throwable {
-                errorsSession2.add(getError((Pcerr) invocation.getArguments()[0]));
+                PCCTunnelManagerImplTest.this.errorsSession2.add(getError((Pcerr) invocation.getArguments()[0]));
                 return null;
             }
-        }).when(session2).sendError(Mockito.any(Pcerr.class));
-        Mockito.doReturn(1).when(session2).getId();
+        }).when(this.session2).sendError(Mockito.any(Pcerr.class));
+        Mockito.doReturn(1).when(this.session2).getId();
     }
 
     @After
@@ -104,19 +104,19 @@ public class PCCTunnelManagerImplTest {
     @Test
     public void testOnSessionUp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        checkSessionUp(session1, tunnelManager);
-        checkSessionUp(session2, tunnelManager);
+        checkSessionUp(this.session1, tunnelManager);
+        checkSessionUp(this.session2, tunnelManager);
     }
 
     @Test
     public void testOnSessionDownAndDelegateBack() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, 10, TIMER, this.timerHandler);
-        checkSessionUp(session1, tunnelManager);
-        checkSessionUp(session2, tunnelManager);
-        checkSessionDown(session1, tunnelManager);
-        tunnelManager.onSessionUp(session1);
-        Mockito.verify(session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        checkSessionUp(this.session1, tunnelManager);
+        checkSessionUp(this.session2, tunnelManager);
+        checkSessionDown(this.session1, tunnelManager);
+        tunnelManager.onSessionUp(this.session1);
+        Mockito.verify(this.session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     private static void checkSessionDown(final PCCSession session, final PCCTunnelManager tunnelManager) {
@@ -133,171 +133,171 @@ public class PCCTunnelManagerImplTest {
     @Test
     public void testOnSessionDownAndDelegateToOther() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, -1, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session2);
-        checkSessionUp(session1, tunnelManager);
-        checkSessionDown(session1, tunnelManager);
+        tunnelManager.onSessionUp(this.session2);
+        checkSessionUp(this.session1, tunnelManager);
+        checkSessionDown(this.session1, tunnelManager);
         //wait for re-delegation timeout expires
         Thread.sleep(500);
-        Mockito.verify(session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
-        tunnelManager.onSessionUp(session1);
-        Mockito.verify(session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        Mockito.verify(this.session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testReportToAll() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcupd(createUpdateDelegate(1), session1);
-        Mockito.verify(session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcupd(createUpdateDelegate(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testReportToAllUnknownLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcupd(createUpdateDelegate(2), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcupd(createUpdateDelegate(2), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
     }
 
     @Test
     public void testReportToAllNonDelegatedLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcupd(createUpdateDelegate(1), session2);
-        Mockito.verify(session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcupd(createUpdateDelegate(1), this.session2);
+        Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
     }
 
     @Test
     public void testReturnDelegationPccLsp() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, -1, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcupd(createUpdate(1), session1);
-        Mockito.verify(session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcupd(createUpdate(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
         //wait for re-delegation timer expires
         Thread.sleep(1200);
-        Mockito.verify(session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testReturnDelegationUnknownLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcupd(createUpdate(2), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcupd(createUpdate(2), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
     }
 
     @Test
     public void testReturnDelegationNonDelegatedLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcupd(createUpdate(1), session2);
-        Mockito.verify(session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcupd(createUpdate(1), this.session2);
+        Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
     }
 
     @Test
     public void testAddTunnel() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcInitiate(createRequests(1), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testRemoveTunnel() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcInitiate(createRequests(1), session1);
-        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
-        Mockito.verify(session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testRemoveTunnelUnknownLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
     }
 
     @Test
     public void testRemoveTunnelNotPceInitiatedLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, this.errorsSession1.get(0));
     }
 
     @Test
     public void testRemoveTunnelNotDelegated() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcInitiate(createRequests(1), session1);
-        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session2);
-        Mockito.verify(session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session2);
+        Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
     }
 
     @Test
     public void testTakeDelegation() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, -1, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcInitiate(createRequests(1), session1); //AddTunel
-        tunnelManager.onMessagePcupd(createUpdate(1), session1); //returnDelegation
-        Mockito.verify(session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcInitiate(createRequests(1), this.session1); //AddTunel
+        tunnelManager.onMessagePcupd(createUpdate(1), this.session1); //returnDelegation
+        Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
         Thread.sleep(500);
-        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session2);//takeDelegation
-        Mockito.verify(session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session2);//takeDelegation
+        Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
     }
 
     @Test
     public void testTakeDelegationUnknownLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
     }
 
     @Test
     public void testTakeDelegationNotPceInitiatedLsp() {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session1);
-        Mockito.verify(session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
-        assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, errorsSession1.get(0));
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session1);
+        Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
+        assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, this.errorsSession1.get(0));
     }
 
     @Test
     public void testReturnDelegationNoRetake() throws InterruptedException {
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
-        tunnelManager.onSessionUp(session1);
-        tunnelManager.onSessionUp(session2);
-        tunnelManager.onMessagePcInitiate(createRequests(1), session1);
-        tunnelManager.onMessagePcupd(createUpdate(1), session1);
+        tunnelManager.onSessionUp(this.session1);
+        tunnelManager.onSessionUp(this.session2);
+        tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
+        tunnelManager.onMessagePcupd(createUpdate(1), this.session1);
         //wait for state timeout expires
         Thread.sleep(500);
-        Mockito.verify(session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
-        Mockito.verify(session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+        Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
     }
     private Updates createUpdateDelegate(final long plspId) {
         return createUpdate(plspId, Optional.of(true));
index 8b68925003fb5f520e62c0d22d40e886bd00e355..a4ec5aadc26048e47c596fd4b597f3e319d3cfe1 100644 (file)
@@ -13,26 +13,29 @@ import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import javax.annotation.concurrent.GuardedBy;
 import org.junit.Assert;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
+import org.opendaylight.protocol.util.CheckUtil.ListenerCheck;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TestingSessionListener implements PCEPSessionListener {
+public class TestingSessionListener implements PCEPSessionListener, ListenerCheck {
 
     private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
     private final CountDownLatch sessionLatch = new CountDownLatch(1);
 
+    @GuardedBy("this")
     private final List<Message> messages = Lists.newArrayList();
 
     private boolean up = false;
     private PCEPSession session = null;
 
     @Override
-    public void onMessage(final PCEPSession session, final Message message) {
+    public synchronized void onMessage(final PCEPSession session, final Message message) {
         LOG.debug("Received message: {}", message);
         this.messages.add(message);
     }
@@ -42,7 +45,7 @@ public class TestingSessionListener implements PCEPSessionListener {
         LOG.debug("Session up.");
         this.up = true;
         this.session = session;
-        sessionLatch.countDown();
+        this.sessionLatch.countDown();
 
     }
 
@@ -58,7 +61,7 @@ public class TestingSessionListener implements PCEPSessionListener {
         LOG.debug("Session terminated. Cause : {}", cause);
     }
 
-    List<Message> messages() {
+    synchronized List<Message> messages() {
         return this.messages;
     }
 
@@ -67,7 +70,12 @@ public class TestingSessionListener implements PCEPSessionListener {
     }
 
     public PCEPSession getSession() {
-        Assert.assertEquals("Session up", true, Uninterruptibles.awaitUninterruptibly(sessionLatch, 10, TimeUnit.SECONDS));
+        Assert.assertEquals("Session up", true, Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
         return this.session;
     }
+
+    @Override
+    public synchronized int getListMessageSize() {
+        return this.messages.size();
+    }
 }
index c4a50e1d037f3638063485bb63ce964db1cb126a..c186deeb1865f98290c7dbb994afea23e17abad7 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
 
-public class TestingSessionListenerFactory implements PCEPSessionListenerFactory {
+class TestingSessionListenerFactory implements PCEPSessionListenerFactory {
 
     @GuardedBy("this")
     private final List<TestingSessionListener> sessionListeners = new ArrayList<>();
index 978f69a752bc2505bda3d217fac8de36eb12bf83..f1ae1fc8883ade0f641f717ccc07dc29f2c1778b 100644 (file)
@@ -25,7 +25,6 @@ public final class CheckUtil {
     private static final int LATCH_TIMEOUT = 10;
     private static final int SLEEP_FOR = 200;
     private static final int TIMEOUT = 60;
-
     private CheckUtil() {
         throw new UnsupportedOperationException();
     }
@@ -56,4 +55,60 @@ public final class CheckUtil {
         }
         throw lastError;
     }
+
+    public static <T extends DataObject> void checkNull(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
+        throws ReadFailedException {
+        AssertionError lastError = null;
+        final Stopwatch sw = Stopwatch.createStarted();
+        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
+            try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+                final com.google.common.base.Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
+                try {
+                    assert !data.isPresent();
+                    return;
+                } catch (final AssertionError e) {
+                    lastError = e;
+                    Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
+                }
+            }
+        }
+        throw lastError;
+    }
+
+    public static void checkEquals(final CheckEquals function) throws Exception {
+        AssertionError lastError = null;
+        final Stopwatch sw = Stopwatch.createStarted();
+        while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
+            try {
+                function.check();
+                return;
+            } catch (final AssertionError e) {
+                lastError = e;
+                Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
+            }
+        }
+        throw lastError;
+    }
+
+    public static void checkReceivedMessages(final ListenerCheck listener, final int numberOfMessages)
+        throws ReadFailedException {
+        final Stopwatch sw = Stopwatch.createStarted();
+        while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
+            if (listener.getListMessageSize() != numberOfMessages) {
+                Uninterruptibles.sleepUninterruptibly(SLEEP_FOR, TimeUnit.MILLISECONDS);
+            } else {
+                return;
+            }
+        }
+        throw new AssertionError("Expected " + numberOfMessages + " but received "
+            + listener.getListMessageSize());
+    }
+
+    public interface ListenerCheck {
+        int getListMessageSize();
+    }
+    @FunctionalInterface
+    public interface CheckEquals {
+        void check();
+    }
 }
\ No newline at end of file