*/
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;
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();
}
});
connectionContext.propagateClosingConnection();
+ try {
+ handshakeContext.close();
+ } catch (Exception e) {
+ LOG.debug("Closing of handshake context wasn't successfull. {}", e);
+ }
}
-
}
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;
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
Mockito.verify(connectionAdapter).disconnect();
Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
Mockito.verify(connectionContext).propagateClosingConnection();
+ assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
}
/**
Mockito.verify(connectionAdapter).disconnect();
Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
Mockito.verify(connectionContext).propagateClosingConnection();
+ assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
}
/**
Mockito.verify(connectionAdapter).disconnect();
Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
Mockito.verify(connectionContext).propagateClosingConnection();
+ assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
}
/**
Mockito.verify(connectionAdapter, Mockito.never()).disconnect();
Mockito.verify(connectionContext).setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
Mockito.verify(connectionContext).propagateClosingConnection();
+ assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
}
/**
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());
}
/**
Mockito.verify(connectionAdapter).disconnect();
Mockito.verify(connectionContext).propagateClosingConnection();
+ assertTrue(systemNotificationsListener.handshakeContext.getHandshakePool().isTerminated());
}
private void verifyCommonInvocations() {