BUG 2429 - not releasing dead connection threads 15/20115/1
authorJozef Gloncak <jgloncak@cisco.com>
Tue, 12 May 2015 09:19:31 +0000 (11:19 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Tue, 12 May 2015 12:08:01 +0000 (14:08 +0200)
Implementation of fix for this bug was added also to
Lithium codebase.

Change-Id: Id807d54b0f7f0eec0e83f078579f893f818fe0e1
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
(cherry picked from commit 1510a4b08068939f3fb3342c5d47d5b42a629f6f)

openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java

index 2bab423bed457fedb2e74513eb1d6505eba98a5d..4f8de11aa4f952223345faab53ca790c9d145b0d 100644 (file)
@@ -69,7 +69,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
                 new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
         connectionAdapter.setMessageListener(ofMessageListener);
 
-        final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext);
+        final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext, handshakeContext);
         connectionAdapter.setSystemListener(systemListener);
 
         LOG.trace("connection ballet finished");
index 952512edb71fbd023568ae40dc350fb9d8353b31..d37777e33cfd8ece1628148e7eb060af57346698 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.impl.connection.listener;
 
+import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -35,21 +36,19 @@ import org.slf4j.LoggerFactory;
 public class SystemNotificationsListenerImpl implements SystemNotificationsListener {
 
     private ConnectionContext connectionContext;
+    HandshakeContext handshakeContext;
     private static final Logger LOG = LoggerFactory.getLogger(SystemNotificationsListenerImpl.class);
     @VisibleForTesting
     static final long MAX_ECHO_REPLY_TIMEOUT = 2000;
 
-
-    /**
-     * @param connectionContext
-     */
-    public SystemNotificationsListenerImpl(ConnectionContext connectionContext) {
+    public SystemNotificationsListenerImpl(final ConnectionContext connectionContext, 
+            final HandshakeContext handshakeContext) {
         this.connectionContext = connectionContext;
+        this.handshakeContext = handshakeContext;
     }
 
     @Override
     public void onDisconnectEvent(DisconnectEvent notification) {
-        // TODO Auto-generated method stub
         disconnect();
     }
 
@@ -145,6 +144,10 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
         });
 
         connectionContext.propagateClosingConnection();
+        try {
+            handshakeContext.close();
+        } catch (Exception e) {
+            LOG.debug("Closing of handshake context wasn't successfull. {}", e);
+        }
     }
-
 }
index 4da270ad65782634bdc3a1ec1572e70ac8c4159d..118d6dfa1e41ae3fb47080eef579c16850a2aee6 100644 (file)
@@ -8,6 +8,13 @@
 
 package org.opendaylight.openflowplugin.impl.connection.listener;
 
+import static org.junit.Assert.*;
+
+import org.opendaylight.openflowplugin.impl.connection.HandshakeContextImpl;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import java.net.InetSocketAddress;
@@ -66,7 +73,12 @@ public class SystemNotificationsListenerImplTest {
 
         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
-        systemNotificationsListener = new SystemNotificationsListenerImpl(connectionContext);
+
+        ThreadPoolLoggingExecutor threadPoolLoggingExecutor = new ThreadPoolLoggingExecutor(2000, 2000, 0L, TimeUnit.MILLISECONDS,
+                new ArrayBlockingQueue<Runnable>(20), "OFHandshake-test identifier");
+
+        systemNotificationsListener = new SystemNotificationsListenerImpl(connectionContext,
+               new HandshakeContextImpl(threadPoolLoggingExecutor, null));
     }
 
     @After
@@ -91,6 +103,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
         Mockito.verify(connectionContext).propagateClosingConnection();
+        assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     /**
@@ -110,6 +123,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
         Mockito.verify(connectionContext).propagateClosingConnection();
+        assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     /**
@@ -131,6 +145,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
         Mockito.verify(connectionContext).propagateClosingConnection();
+        assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     /**
@@ -151,6 +166,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter, Mockito.never()).disconnect();
         Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
         Mockito.verify(connectionContext).propagateClosingConnection();
+        assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     /**
@@ -182,6 +198,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(Matchers.any(EchoInput.class));
         Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT)).setConnectionState(ConnectionContext.CONNECTION_STATE.WORKING);
         Mockito.verify(connectionAdapter, Mockito.never()).disconnect();
+        assertFalse(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     /**
@@ -212,6 +229,7 @@ public class SystemNotificationsListenerImplTest {
 
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).propagateClosingConnection();
+        assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
     }
 
     private void verifyCommonInvocations() {