import io.netty.util.HashedWheelTimer;
import org.apache.commons.io.IOUtils;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.controller.netconf.client.NetconfClient;
import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
+import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
import org.opendaylight.controller.netconf.mapping.api.Capability;
import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
import org.w3c.dom.Document;
import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
public class ConcurrentClientsTest {
private static final int CONCURRENCY = 16;
- private static EventLoopGroup nettyGroup = new NioEventLoopGroup();
- public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(
- Optional.<SSLContext> absent(), nettyGroup, nettyGroup);
+ private EventLoopGroup nettyGroup;
+ private NetconfClientDispatcher netconfClientDispatcher;
@Mock
private YangStoreService yangStoreService;
private DefaultCommitNotificationProducer commitNot;
private NetconfServerDispatcher dispatch;
+ @Mock
+ private SessionMonitoringService monitoring;
+
+ HashedWheelTimer hashedWheelTimer;
@Before
public void setUp() throws Exception {
final YangStoreSnapshot yStore = mock(YangStoreSnapshot.class);
doReturn(yStore).when(this.yangStoreService).getYangStoreSnapshot();
doReturn(Collections.emptyMap()).when(yStore).getModuleMXBeanEntryMap();
- doReturn(Collections.emptyMap()).when(yStore).getModuleMap();
final ConfigTransactionJMXClient mockedTCl = mock(ConfigTransactionJMXClient.class);
doReturn(mockedTCl).when(this.jmxClient).getConfigTransactionClient(any(ObjectName.class));
doReturn(Collections.emptySet()).when(jmxClient).lookupConfigBeans();
}
+ nettyGroup = new NioEventLoopGroup();
+ netconfClientDispatcher = new NetconfClientDispatcher( nettyGroup, nettyGroup, 5000);
+
NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
factoriesListener.onAddNetconfOperationServiceFactory(mockOpF());
SessionIdProvider idProvider = new SessionIdProvider();
+ hashedWheelTimer = new HashedWheelTimer();
NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
- new HashedWheelTimer(5000, TimeUnit.MILLISECONDS), factoriesListener, idProvider);
+ hashedWheelTimer, factoriesListener, idProvider, 5000);
commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
+ doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class));
+ doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class));
+
NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
- factoriesListener, commitNot, idProvider);
- NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
- Optional.<SSLContext> absent(), serverNegotiatorFactory, listenerFactory);
+ factoriesListener, commitNot, idProvider, monitoring);
+ NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
ChannelFuture s = dispatch.createServer(netconfAddress);
s.await();
}
- @AfterClass
- public static void tearDownStatic() {
+ @After
+ public void tearDown(){
+ hashedWheelTimer.stop();
nettyGroup.shutdownGracefully();
}
@Override
public void run() {
try {
- final NetconfClient netconfClient = new NetconfClient(clientId, netconfAddress, NETCONF_CLIENT_DISPATCHER);
+ final NetconfClient netconfClient = new NetconfClient(clientId, netconfAddress, netconfClientDispatcher);
long sessionId = netconfClient.getSessionId();
logger.info("Client with sessionid {} hello exchanged", sessionId);