From 733321d7ef9ef253dd7312705f755b2d0ba8b748 Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Tue, 12 May 2015 11:19:31 +0200 Subject: [PATCH] BUG 2429 - not releasing dead connection threads Implementation of fix for this bug was added also to Lithium codebase. Change-Id: Id807d54b0f7f0eec0e83f078579f893f818fe0e1 Signed-off-by: Jozef Gloncak (cherry picked from commit 1510a4b08068939f3fb3342c5d47d5b42a629f6f) --- .../connection/ConnectionManagerImpl.java | 2 +- .../SystemNotificationsListenerImpl.java | 17 +++++++++------- .../SystemNotificationsListenerImplTest.java | 20 ++++++++++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java index 2bab423bed..4f8de11aa4 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java @@ -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"); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java index 952512edb7..d37777e33c 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java @@ -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); + } } - } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java index 4da270ad65..118d6dfa1e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java @@ -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(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() { -- 2.36.6