X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fit%2FNetconfITSecureTest.java;h=a9e8dbe86b06b76087c902521022ff06e239b870;hp=56f674bc34f287d74224ad269a1274c657109e68;hb=1ee96d196dae671041258600cf56d02e9d95e003;hpb=96e61c15761ca887620f53d6f20ac574d16287f8 diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java index 56f674bc34..a9e8dbe86b 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java @@ -9,13 +9,16 @@ package org.opendaylight.controller.netconf.it; import static java.util.Arrays.asList; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import io.netty.channel.ChannelFuture; +import com.google.common.collect.Lists; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GlobalEventExecutor; import java.io.IOException; import java.io.InputStream; @@ -23,6 +26,7 @@ import java.lang.management.ManagementFactory; import java.net.InetSocketAddress; import java.util.Collection; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import junit.framework.Assert; import org.junit.After; import org.junit.Before; @@ -68,27 +72,27 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, getModuleFactories().toArray( new ModuleFactory[0]))); - NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + final NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore())); commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); final NetconfServerDispatcher dispatchS = createDispatcher(factoriesListener); - ChannelFuture s = dispatchS.createLocalServer(NetconfConfigUtil.getNetconfLocalAddress()); - s.await(); - EventLoopGroup bossGroup = new NioEventLoopGroup(); + dispatchS.createLocalServer(NetconfConfigUtil.getNetconfLocalAddress()).await(); + final EventLoopGroup bossGroup = new NioEventLoopGroup(); sshServer = NetconfSSHServer.start(tlsAddress.getPort(), NetconfConfigUtil.getNetconfLocalAddress(), getAuthProvider(), bossGroup); } - private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) { + private NetconfServerDispatcher createDispatcher(final NetconfOperationServiceFactoryListenerImpl factoriesListener) { return super.createDispatcher(factoriesListener, NetconfITTest.getNetconfMonitoringListenerService(), commitNot); } @After public void tearDown() throws Exception { - sshServer.stop(); + sshServer.close(); commitNot.close(); + sshServer.join(); } private HardcodedYangStoreService getYangStore() throws YangStoreException, IOException { @@ -102,13 +106,13 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { @Test public void testSecure() throws Exception { - NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); + final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration())) { NetconfMessage response = netconfClient.sendMessage(getConfig); Assert.assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), NetconfMessageUtil.isErrorMessage(response)); - NetconfMessage gs = new NetconfMessage(XmlUtil.readXmlToDocument("\n" + " \n" + " config\n" + @@ -121,6 +125,41 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { } } + /** + * Test all requests are handled properly and no mismatch occurs in listener + */ + @Test(timeout = 3*60*1000) + public void testSecureStress() throws Exception { + final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); + try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration())) { + + final AtomicInteger responseCounter = new AtomicInteger(0); + final List> futures = Lists.newArrayList(); + + final int requests = 1000; + for (int i = 0; i < requests; i++) { + final Future netconfMessageFuture = netconfClient.sendRequest(getConfig); + futures.add(netconfMessageFuture); + netconfMessageFuture.addListener(new GenericFutureListener>() { + @Override + public void operationComplete(final Future future) throws Exception { + assertTrue("Request unsuccessful " + future.cause(), future.isSuccess()); + responseCounter.incrementAndGet(); + } + }); + } + + for (final Future future : futures) { + future.await(); + } + + // Give future listeners some time to finish counter incrementation + Thread.sleep(5000); + + org.junit.Assert.assertEquals(requests, responseCounter.get()); + } + } + public NetconfClientConfiguration getClientConfiguration() throws IOException { final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create(); b.withAddress(tlsAddress); @@ -133,7 +172,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { } public AuthProvider getAuthProvider() throws Exception { - AuthProvider mock = mock(AuthProviderImpl.class); + final AuthProvider mock = mock(AuthProviderImpl.class); doReturn(true).when(mock).authenticated(anyString(), anyString()); doReturn(PEMGenerator.generate().toCharArray()).when(mock).getPEMAsCharArray(); return mock;