BUG-2208: Cancel PCEPSessionNegotiator Timers on session down 45/32145/7
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 5 Jan 2016 15:59:27 +0000 (16:59 +0100)
committerMilos Fabian <milfabia@cisco.com>
Sun, 10 Jan 2016 23:35:57 +0000 (23:35 +0000)
On session goes down PCEPSessionNegotiator Timers need to
be canceled

Change-Id: I82091efb6e8ffcda992f08bc3fdcbf1cf63a1ab5
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java

index eee8434de4b5511157649afd7ecf6681f0aacc9f..f9886551e1735e6b7707458cdaacbe79156890b3 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.pcep.impl;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
 import io.netty.handler.ssl.SslHandler;
 import io.netty.util.concurrent.Promise;
 import java.util.concurrent.Future;
@@ -186,6 +188,16 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
         } else {
             startNegotiationWithOpen();
         }
+        this.channel.closeFuture().addListener(new ChannelFutureListener() {
+            @Override
+            public void operationComplete(final ChannelFuture f) {
+                cancelTimers();
+            }
+        });
+    }
+
+    private void cancelTimers() {
+        failTimer.cancel(false);
     }
 
     private void startNegotiationWithOpen() {
@@ -315,7 +327,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
 
     @Override
     protected final void handleMessage(final Message msg) {
-        this.failTimer.cancel(false);
+        cancelTimers();
 
         LOG.debug("Channel {} handling message {} in state {}", this.channel, msg, this.state);
 
index 8eac65ae0b35c85632ad3dc2432f1b0d38bf5c86..9b78a5b9abe5233e054219833dabb3d9f8d69078 100644 (file)
@@ -20,6 +20,7 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelPipeline;
 import io.netty.channel.DefaultChannelPromise;
 import io.netty.channel.EventLoop;
+import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.ScheduledFuture;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -50,6 +51,9 @@ public class AbstractPCEPSessionTest {
     @Mock
     protected Channel channel;
 
+    @Mock
+    private ChannelFuture channelFuture;
+
     @Mock
     private EventLoop eventLoop;
 
@@ -84,6 +88,8 @@ public class AbstractPCEPSessionTest {
                 return future;
             }
         }).when(this.channel).writeAndFlush(any(Notification.class));
+        doReturn(this.channelFuture).when(this.channel).closeFuture();
+        doReturn(this.channelFuture).when(this.channelFuture).addListener(any(GenericFutureListener.class));
         doReturn("TestingChannel").when(this.channel).toString();
         doReturn(this.pipeline).when(this.channel).pipeline();
         doReturn(this.address).when(this.channel).localAddress();