PCEPSessionNegotiatorFactory is not generic 18/104018/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Jan 2023 13:08:34 +0000 (14:08 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Jan 2023 13:12:01 +0000 (14:12 +0100)
Having a type capture here is not that helpful -- all we really need is
to codify that PCEPSession.close() does not throw and have a few
explicit casts in tests.

JIRA: BGPCEP-856
Change-Id: I57246bc681707a853df2c087193d33c914842d1d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPDispatcher.java
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionNegotiator.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCsBuilder.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/api/PCCDispatcher.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/protocol/PCCDispatcherImpl.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java
pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java

index fcdf28cbefcfd80d8735655f727700a3462c1ac2..cf14d08d8fb6b321a91ce21d1006143d6f542cef 100644 (file)
@@ -22,5 +22,5 @@ public interface PCEPDispatcher {
      */
     @NonNull ChannelFuture createServer(@NonNull PCEPDispatcherDependencies dispatcherDependencies);
 
-    @NonNull PCEPSessionNegotiatorFactory<?> getPCEPSessionNegotiatorFactory();
+    @NonNull PCEPSessionNegotiatorFactory getPCEPSessionNegotiatorFactory();
 }
index af805b91229dbab6a559e3f41921bcaab1ab5fa0..c0efe6740bce78d56ed7b1880ec4406eae59aa6e 100644 (file)
@@ -31,6 +31,9 @@ public interface PCEPSession extends PCEPSessionState, AutoCloseable {
      */
     Future<Void> sendMessage(Message message);
 
+    @Override
+    void close();
+
     void close(TerminationReason reason);
 
     /**
index 33dfcfd0529d94400b29b45fbf2e6a98d00c95ac..ace6cfad7624684c8890a990c47e64d729522897 100644 (file)
@@ -13,10 +13,8 @@ import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * Factory for creating PCEP session negotiator.
- *
- * @param <S> PCEPSession implementation
  */
-public interface PCEPSessionNegotiatorFactory<S extends PCEPSession> {
+public interface PCEPSessionNegotiatorFactory {
 
     /**
      * Creates PCEPSessionNegotiator instance for income attributes.
@@ -28,7 +26,7 @@ public interface PCEPSessionNegotiatorFactory<S extends PCEPSession> {
      */
     @NonNull SessionNegotiator getSessionNegotiator(
             @NonNull PCEPSessionNegotiatorFactoryDependencies sessionNegotiatorDependencies,
-            @NonNull Channel channel, @NonNull Promise<S> promise);
+            @NonNull Channel channel, @NonNull Promise<PCEPSession> promise);
 
     /**
      * Returns a PCEPSessionProposalFactory.
index 185a3f15a6d0ed35bbd02616a2e824987d16affc..7daf793028e51d71a9a334ab2fec18477b57d9f3 100644 (file)
@@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.impl.spi.Util;
 import org.opendaylight.protocol.pcep.impl.tls.SslContextFactory;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
@@ -95,7 +96,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     private Open localPrefs;
     private Open remotePrefs;
 
-    protected AbstractPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
+    protected AbstractPCEPSessionNegotiator(final Promise<PCEPSession> promise, final Channel channel,
             final PcepSessionTls tlsConfiguration) {
         super(promise, channel);
         this.tlsConfiguration = tlsConfiguration;
index 1f7bd031e816d6450c4add42595ec19c4f007161..1a07ee291cba2ba0e29367f51e657c37f8b5ff8c 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.impl;
 
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
 import org.opendaylight.protocol.pcep.SessionNegotiator;
@@ -20,8 +21,7 @@ import org.slf4j.LoggerFactory;
  * SessionNegotiator which takes care of making sure sessions between PCEP peers are kept unique. This needs to be
  * further subclassed to provide either a client or server factory.
  */
-public abstract class AbstractPCEPSessionNegotiatorFactory implements PCEPSessionNegotiatorFactory<PCEPSessionImpl> {
-
+public abstract class AbstractPCEPSessionNegotiatorFactory implements PCEPSessionNegotiatorFactory {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class);
 
     private final PCEPPeerRegistry sessionRegistry = new PCEPPeerRegistry();
@@ -37,12 +37,12 @@ public abstract class AbstractPCEPSessionNegotiatorFactory implements PCEPSessio
      */
     protected abstract AbstractPCEPSessionNegotiator createNegotiator(
             PCEPSessionNegotiatorFactoryDependencies snd,
-            Promise<PCEPSessionImpl> promise,
+            Promise<PCEPSession> promise,
             Channel channel, Uint8 sessionId);
 
     @Override
     public final SessionNegotiator getSessionNegotiator(final PCEPSessionNegotiatorFactoryDependencies dependencies,
-            final Channel channel, final Promise<PCEPSessionImpl> promise) {
+            final Channel channel, final Promise<PCEPSession> promise) {
 
         LOG.debug("Instantiating bootstrap negotiator for channel {}", channel);
         return new PCEPSessionNegotiator(channel, promise, dependencies, this);
index 85cdc6ec1b38172b1c98060c0d9242c18c4f07d0..339e07a3e5b294883d7ad92f806fafa38e6de505 100644 (file)
@@ -15,6 +15,7 @@ import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.util.concurrent.Promise;
 import java.util.concurrent.ExecutionException;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.SessionNegotiator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
 import org.slf4j.Logger;
@@ -22,28 +23,29 @@ import org.slf4j.LoggerFactory;
 
 public abstract class AbstractSessionNegotiator extends ChannelInboundHandlerAdapter implements SessionNegotiator {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractSessionNegotiator.class);
+
     protected final Channel channel;
-    protected final Promise<PCEPSessionImpl> promise;
+    protected final Promise<PCEPSession> promise;
 
-    protected AbstractSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel) {
+    protected AbstractSessionNegotiator(final Promise<PCEPSession> promise, final Channel channel) {
         this.promise = requireNonNull(promise);
         this.channel = requireNonNull(channel);
     }
 
     protected final void negotiationSuccessful(final PCEPSessionImpl session) {
-        LOG.debug("Negotiation on channel {} successful with session {}", this.channel, session);
-        this.channel.pipeline().replace(this, "session", session);
-        this.promise.setSuccess(session);
+        LOG.debug("Negotiation on channel {} successful with session {}", channel, session);
+        channel.pipeline().replace(this, "session", session);
+        promise.setSuccess(session);
     }
 
     protected void negotiationFailed(final Throwable cause) {
-        LOG.debug("Negotiation on channel {} failed", this.channel, cause);
-        this.channel.close();
-        this.promise.setFailure(cause);
+        LOG.debug("Negotiation on channel {} failed", channel, cause);
+        channel.close();
+        promise.setFailure(cause);
     }
 
     protected final void sendMessage(final Message msg) {
-        this.channel.writeAndFlush(msg).addListener((ChannelFutureListener) f -> {
+        channel.writeAndFlush(msg).addListener((ChannelFutureListener) f -> {
             if (!f.isSuccess()) {
                 LOG.info("Failed to send message {}", msg, f.cause());
                 negotiationFailed(f.cause());
@@ -57,27 +59,26 @@ public abstract class AbstractSessionNegotiator extends ChannelInboundHandlerAda
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
     public final void channelActive(final ChannelHandlerContext ctx) {
-        LOG.debug("Starting session negotiation on channel {}", this.channel);
+        LOG.debug("Starting session negotiation on channel {}", channel);
 
         try {
-            this.startNegotiation();
+            startNegotiation();
         } catch (final Exception e) {
             LOG.warn("Unexpected negotiation failure", e);
-            this.negotiationFailed(e);
+            negotiationFailed(e);
         }
-
     }
 
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
     public final void channelRead(final ChannelHandlerContext ctx, final Object msg) {
-        LOG.debug("Negotiation read invoked on channel {}", this.channel);
+        LOG.debug("Negotiation read invoked on channel {}", channel);
 
         try {
-            this.handleMessage((Message) msg);
+            handleMessage((Message) msg);
         } catch (Exception e) {
             LOG.debug("Unexpected error while handling negotiation message {}", msg, e);
-            this.negotiationFailed(e);
+            negotiationFailed(e);
         }
 
     }
@@ -85,7 +86,7 @@ public abstract class AbstractSessionNegotiator extends ChannelInboundHandlerAda
     @Override
     public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
         LOG.info("Unexpected error during negotiation", cause);
-        this.negotiationFailed(cause);
+        negotiationFailed(cause);
     }
 
     protected abstract void startNegotiation() throws ExecutionException;
index 435b9d9d2c6b4109feca2a34065ac30618c50e77..4c32f42c9d1d8cf2642ed4c29591d287202c9b73 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.VisibleForTesting;
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionErrorPolicy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
@@ -23,7 +24,7 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
     private final PcepSessionErrorPolicy errorPolicy;
     private final PCEPSessionListener listener;
 
-    public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
+    public DefaultPCEPSessionNegotiator(final Promise<PCEPSession> promise, final Channel channel,
             final PCEPSessionListener listener, final Uint8 sessionId, final Open localPrefs,
             final PcepSessionErrorPolicy errorPolicy, final PcepSessionTls tlsConfiguration) {
         super(promise, channel, tlsConfiguration);
@@ -37,7 +38,7 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
                 .build();
     }
 
-    public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
+    public DefaultPCEPSessionNegotiator(final Promise<PCEPSession> promise, final Channel channel,
             final PCEPSessionListener listener, final Uint8 sessionId, final Open localPrefs,
             final PcepSessionErrorPolicy errorPolicy) {
         this(promise, channel, listener, sessionId, localPrefs, errorPolicy, null);
index 1aceefcbab14fd07e6dc93154ac60ccf83dc61ad..803f7c2c53ed84da11b9a1f3ec870ab9df1d8c3c 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PcepDispatcherConfig;
@@ -40,7 +41,7 @@ public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessi
     @Override
     protected AbstractPCEPSessionNegotiator createNegotiator(
             final PCEPSessionNegotiatorFactoryDependencies sessionNegotiatorDependencies,
-            final Promise<PCEPSessionImpl> promise,
+            final Promise<PCEPSession> promise,
             final Channel channel,
             final Uint8 sessionId) {
 
index 1e2b42ace84c4489bff7fd05f6f2b93aff20150e..cf9d165caceeed1d0bd85254551c988457546ae2 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
 import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.slf4j.Logger;
@@ -47,7 +48,7 @@ public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
     private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
     private static final Integer SOCKET_BACKLOG_SIZE = 128;
     private static final long TIMEOUT = 10;
-    private final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf;
+    private final PCEPSessionNegotiatorFactory snf;
     private final PCEPHandlerFactory hf;
     private final EventLoopGroup bossGroup;
     private final EventLoopGroup workerGroup;
@@ -64,7 +65,7 @@ public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
      * @param workerGroup       handles the traffic of accepted connection
      */
     public PCEPDispatcherImpl(final @NonNull MessageRegistry registry,
-            final @NonNull PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory,
+            final @NonNull PCEPSessionNegotiatorFactory negotiatorFactory,
             final @NonNull EventLoopGroup bossGroup, final @NonNull EventLoopGroup workerGroup) {
         snf = requireNonNull(negotiatorFactory);
         hf = new PCEPHandlerFactory(registry);
@@ -145,11 +146,11 @@ public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
     }
 
     @Override
-    public final PCEPSessionNegotiatorFactory<PCEPSessionImpl> getPCEPSessionNegotiatorFactory() {
+    public final PCEPSessionNegotiatorFactory getPCEPSessionNegotiatorFactory() {
         return snf;
     }
 
     protected interface ChannelPipelineInitializer {
-        void initializeChannel(SocketChannel socketChannel, Promise<PCEPSessionImpl> promise);
+        void initializeChannel(SocketChannel socketChannel, Promise<PCEPSession> promise);
     }
 }
index 6e156740beeac8ff2404039c1f94229cd16f5153..9ca55c8395f58309ce07dbdec732fe32d15c6c04 100644 (file)
@@ -15,6 +15,7 @@ import java.net.InetSocketAddress;
 import java.util.Comparator;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
 import org.opendaylight.protocol.pcep.impl.PCEPPeerRegistry.SessionReference;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
@@ -23,14 +24,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PCEPSessionNegotiator extends AbstractSessionNegotiator {
-
     private static final Logger LOG = LoggerFactory.getLogger(PCEPSessionNegotiator.class);
 
     private static final Comparator<byte[]> COMPARATOR = UnsignedBytes.lexicographicalComparator();
     private final AbstractPCEPSessionNegotiatorFactory negFactory;
     private final PCEPSessionNegotiatorFactoryDependencies nfd;
 
-    public PCEPSessionNegotiator(final Channel channel, final Promise<PCEPSessionImpl> promise,
+    public PCEPSessionNegotiator(final Channel channel, final Promise<PCEPSession> promise,
             final PCEPSessionNegotiatorFactoryDependencies dependencies,
             final AbstractPCEPSessionNegotiatorFactory negFactory) {
         super(promise, channel);
index 628fb1f59bc88109ac347ce949422debd02e3ad3..cc94f6bd982499a49987a0d9c3f09915052e7908 100644 (file)
@@ -47,6 +47,7 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
@@ -119,23 +120,23 @@ public class PCEPDispatcherImplTest {
         doReturn(new SimpleSessionListener()).when(listenerFactory).getSessionListener();
         final ChannelFuture futureChannel = dispatcher.createServer(dispatcherDependencies);
         futureChannel.sync();
-        final PCEPSessionImpl session1 = pccMock.createClient(clientAddr1,
-                RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
-        final PCEPSessionImpl session2 = pccMock.createClient(clientAddr2,
-                RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+        try (var session1 = (PCEPSessionImpl) pccMock.createClient(clientAddr1,
+            RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get()) {
 
-        assertTrue(futureChannel.channel().isActive());
-        assertEquals(clientAddr1.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
-        assertEquals(DEAD_TIMER.toJava(), session1.getDeadTimerValue());
-        assertEquals(KEEP_ALIVE.toJava(), session1.getKeepAliveTimerValue());
+            try (var session2 = (PCEPSessionImpl) pccMock.createClient(clientAddr2,
+                RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get()) {
 
-        assertEquals(clientAddr2.getAddress().getHostAddress(), session2.getPeerPref().getIpAddress());
-        assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
-        assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
+                assertTrue(futureChannel.channel().isActive());
+                assertEquals(clientAddr1.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
+                assertEquals(DEAD_TIMER.toJava(), session1.getDeadTimerValue());
+                assertEquals(KEEP_ALIVE.toJava(), session1.getKeepAliveTimerValue());
 
-        session1.close();
-        session2.close();
+                assertEquals(clientAddr2.getAddress().getHostAddress(), session2.getPeerPref().getIpAddress());
+                assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
+                assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
+            }
+        }
         assertTrue(futureChannel.channel().isActive());
     }
 
@@ -150,11 +151,11 @@ public class PCEPDispatcherImplTest {
         doReturn(new SimpleSessionListener()).when(listenerFactory).getSessionListener();
 
         dispatcher.createServer(dispatcherDependencies).sync();
-        final Future<PCEPSessionImpl> futureClient = pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
+        final Future<PCEPSession> futureClient = pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
                 SimpleSessionListener::new);
         futureClient.sync();
 
-        try (PCEPSessionImpl ignored = futureClient.get()) {
+        try (PCEPSession ignored = futureClient.get()) {
             final var cause = assertThrows(ExecutionException.class,
                 () -> pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get())
                 .getCause();
@@ -174,7 +175,7 @@ public class PCEPDispatcherImplTest {
         doReturn(listenerFactory).when(dispatcherDependencies).getListenerFactory();
         doReturn(new SimpleSessionListener()).when(listenerFactory).getSessionListener();
         dispatcher.createServer(dispatcherDependencies).sync();
-        final PCEPSessionImpl session1 = pccMock.createClient(clientAddr,
+        final PCEPSessionImpl session1 = (PCEPSessionImpl) pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
 
         assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
@@ -182,14 +183,13 @@ public class PCEPDispatcherImplTest {
         assertEquals(KEEP_ALIVE.toJava(), session1.getKeepAliveTimerValue());
         session1.closeChannel().sync();
 
-        final PCEPSessionImpl session2 = pccMock.createClient(clientAddr,
-                RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get();
+        try (var session2 = (PCEPSessionImpl) pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT,
+            SimpleSessionListener::new).get()) {
 
-        assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
-        assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
-        assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
-
-        session2.close();
+            assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
+            assertEquals(DEAD_TIMER.toJava(), session2.getDeadTimerValue());
+            assertEquals(KEEP_ALIVE.toJava(), session2.getKeepAliveTimerValue());
+        }
     }
 
     @Test(timeout = 20000)
@@ -215,12 +215,12 @@ public class PCEPDispatcherImplTest {
     }
 
     private static class PCCMock {
-        private final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory;
+        private final PCEPSessionNegotiatorFactory negotiatorFactory;
         private final PCEPHandlerFactory factory;
         private final EventExecutor executor;
         private final EventLoopGroup workerGroup;
 
-        PCCMock(final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory,
+        PCCMock(final PCEPSessionNegotiatorFactory negotiatorFactory,
                 final PCEPHandlerFactory factory) {
             workerGroup = new NioEventLoopGroup();
             this.negotiatorFactory = requireNonNull(negotiatorFactory);
@@ -228,7 +228,7 @@ public class PCEPDispatcherImplTest {
             executor = requireNonNull(GlobalEventExecutor.INSTANCE);
         }
 
-        Future<PCEPSessionImpl> createClient(final InetSocketAddress address, final int retryTimer,
+        Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
                 final int connectTimeout, final PCEPSessionListenerFactory listenerFactory) {
             return createClient(address, retryTimer, connectTimeout, (ch, promise) -> {
                 ch.pipeline().addLast(factory.getDecoders());
@@ -238,10 +238,10 @@ public class PCEPDispatcherImplTest {
             });
         }
 
-        Future<PCEPSessionImpl> createClient(final InetSocketAddress address, final int retryTimer,
+        Future<PCEPSession> createClient(final InetSocketAddress address, final int retryTimer,
                 final int connectTimeout, final PCEPDispatcherImpl.ChannelPipelineInitializer initializer) {
             final Bootstrap b = new Bootstrap();
-            final PCEPProtocolSessionPromise<PCEPSessionImpl> p = new PCEPProtocolSessionPromise<>(executor,
+            final PCEPProtocolSessionPromise<PCEPSession> p = new PCEPProtocolSessionPromise<>(executor,
                     address, retryTimer, connectTimeout, b);
             b.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE).handler(new ChannelInitializer<SocketChannel>() {
                 @Override
index 0f3d514860b8fc5ed7f65d1dbf16e81d19a31e7b..1441b2d126ac662127b78e144c70565e057ee642 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.pcc.mock;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timer;
@@ -24,7 +23,6 @@ import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
-import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
 import org.opendaylight.protocol.pcep.pcc.mock.api.PCCTunnelManager;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.MockPcepSessionErrorPolicy;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
@@ -89,7 +87,7 @@ final class PCCsBuilder {
 
     private void createPCC(final PCCDispatcherImpl pccDispatcher, final @NonNull InetSocketAddress plocalAddress,
             final PCCTunnelManager tunnelManager, final Uint64 initialDBVersion) {
-        final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
+        final PCEPSessionNegotiatorFactory snf = getSessionNegotiatorFactory();
         for (final InetSocketAddress pceAddress : remoteAddress) {
             pccDispatcher.createClient(pceAddress, reconnectTime,
                 () -> new PCCSessionListener(remoteAddress.indexOf(pceAddress), tunnelManager, pcError), snf,
@@ -98,9 +96,8 @@ final class PCCsBuilder {
         }
     }
 
-    private PCEPSessionNegotiatorFactory<PCEPSessionImpl> getSessionNegotiatorFactory() {
-        final List<PCEPCapability> capabilities = Lists.newArrayList(pcepCapabilities);
+    private PCEPSessionNegotiatorFactory getSessionNegotiatorFactory() {
         return new DefaultPCEPSessionNegotiatorFactory(new BasePCEPSessionProposalFactory(deadTimer,
-            keepAlive, capabilities), MockPcepSessionErrorPolicy.ZERO);
+            keepAlive, List.of(pcepCapabilities)), MockPcepSessionErrorPolicy.ZERO);
     }
 }
index 7254c5012958432341b827cd78492c14e1ecd486..08a804ebc14adc66c34ff99e44c2a532597a57e5 100644 (file)
@@ -20,11 +20,11 @@ public interface PCCDispatcher {
 
     @NonNull Future<PCEPSession> createClient(@NonNull InetSocketAddress remoteAddress,
             long reconnectTime, @NonNull PCEPSessionListenerFactory listenerFactory,
-            @NonNull PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, @NonNull KeyMapping keys,
+            @NonNull PCEPSessionNegotiatorFactory negotiatorFactory, @NonNull KeyMapping keys,
             @NonNull InetSocketAddress localAddress, @NonNull Uint64 dbVersion);
 
     @NonNull Future<PCEPSession> createClient(@NonNull InetSocketAddress remoteAddress,
             long reconnectTime, @NonNull PCEPSessionListenerFactory listenerFactory,
-            @NonNull PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, @NonNull KeyMapping keys,
+            @NonNull PCEPSessionNegotiatorFactory negotiatorFactory, @NonNull KeyMapping keys,
             @NonNull InetSocketAddress localAddress);
 }
index 0164c57ec650602ace523a9f66e5c55ad6b3fa85..ec81fefc5ad67511335801edae5b5d6a4dbe9e6a 100755 (executable)
@@ -59,9 +59,8 @@ public final class PCCDispatcherImpl implements PCCDispatcher, AutoCloseable {
 
     @Override
     public Future<PCEPSession> createClient(final InetSocketAddress remoteAddress, final long reconnectTime,
-            final PCEPSessionListenerFactory listenerFactory,
-            final PCEPSessionNegotiatorFactory<? extends PCEPSession> negotiatorFactory, final KeyMapping keys,
-            final InetSocketAddress localAddress) {
+            final PCEPSessionListenerFactory listenerFactory, final PCEPSessionNegotiatorFactory negotiatorFactory,
+            final KeyMapping keys, final InetSocketAddress localAddress) {
         return createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys, localAddress,
             Uint64.ONE);
     }
index dae5363ec1afadf0805d140492d56650f5e74db3..1c768eff3c1d34bdb9d6a75d8590bac4a91ebd2c 100644 (file)
@@ -42,7 +42,6 @@ import org.opendaylight.protocol.pcep.ietf.stateful.StatefulActivator;
 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
-import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
 import org.opendaylight.protocol.pcep.pcc.mock.api.PCCTunnelManager;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.MockPcepSessionErrorPolicy;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
@@ -215,7 +214,7 @@ public abstract class PCCMockCommon {
 
     Future<PCEPSession> createPCCSession(final Uint64 dbVersion) {
         final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(messageRegistry);
-        final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
+        final PCEPSessionNegotiatorFactory snf = getSessionNegotiatorFactory();
         final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(3, localAddress.getAddress(),
                 0, -1, new HashedWheelTimer(), Optional.empty());
 
@@ -225,7 +224,7 @@ public abstract class PCCMockCommon {
         }, snf, KeyMapping.of(), localAddress, dbVersion);
     }
 
-    private PCEPSessionNegotiatorFactory<PCEPSessionImpl> getSessionNegotiatorFactory() {
+    private PCEPSessionNegotiatorFactory getSessionNegotiatorFactory() {
         return new DefaultPCEPSessionNegotiatorFactory(new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE,
                 getCapabilities()), MockPcepSessionErrorPolicy.ZERO);
     }
index eba56b6b39ff359fe0219d338600f555226ae96b..9071281801fccf84e342ee416c01add5313911d1 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator;
 import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
@@ -104,7 +105,7 @@ public abstract class AbstractPCEPSessionTest extends AbstractConcurrentDataBrok
     @Mock
     private PCEPTopologyProviderDependencies topologyDependencies;
     @Mock
-    private Promise<PCEPSessionImpl> promise;
+    private Promise<PCEPSession> promise;
     @Mock
     private PcepSessionErrorPolicy errorPolicy;