X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FConcurrentClientsTest.java;h=0ef2c285e407ac65b9eb62e0bbfc2d14b555c242;hb=6fd408a04fe4a3611843e2246ece6d7c34b76903;hp=a74a347d3bbf5d29811ddf28dd2c9c825cb460cc;hpb=d105455084f43d9423b7c0e6af785302e6a3ea93;p=controller.git diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index a74a347d3b..0ef2c285e4 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -11,10 +11,11 @@ package org.opendaylight.controller.netconf.impl; import com.google.common.base.Optional; import com.google.common.collect.Sets; import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; 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; @@ -29,6 +30,7 @@ import org.opendaylight.controller.netconf.api.NetconfOperationRouter; 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; @@ -42,7 +44,6 @@ import org.slf4j.LoggerFactory; 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; @@ -53,18 +54,20 @@ import java.util.ArrayList; 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.assertTrue; +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; - public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(Optional.absent()); + private EventLoopGroup nettyGroup; + private NetconfClientDispatcher netconfClientDispatcher; + @Mock private YangStoreService yangStoreService; @Mock @@ -77,6 +80,11 @@ public class ConcurrentClientsTest { private DefaultCommitNotificationProducer commitNot; private NetconfServerDispatcher dispatch; + @Mock + private SessionMonitoringService monitoring; + + HashedWheelTimer hashedWheelTimer; + @Before public void setUp() throws Exception { { // init mocks @@ -84,7 +92,6 @@ public class ConcurrentClientsTest { 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)); @@ -92,26 +99,35 @@ public class ConcurrentClientsTest { 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); - dispatch = new NetconfServerDispatcher(Optional. 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() { - NETCONF_CLIENT_DISPATCHER.close(); + @After + public void tearDown(){ + hashedWheelTimer.stop(); + nettyGroup.shutdownGracefully(); } private NetconfOperationServiceFactory mockOpF() { @@ -160,7 +176,6 @@ public class ConcurrentClientsTest { @After public void cleanUp() throws Exception { commitNot.close(); - dispatch.close(); } @Test @@ -176,7 +191,11 @@ public class ConcurrentClientsTest { for (TestingThread thread : threads) { thread.join(); - assertTrue(thread.success); + if(thread.thrownException.isPresent()) { + Exception exception = thread.thrownException.get(); + logger.error("Thread for testing client failed", exception); + fail("Client thread " + thread + " failed: " + exception.getMessage()); + } } } @@ -196,12 +215,16 @@ public class ConcurrentClientsTest { for (BlockingThread thread : threads) { thread.join(); - assertTrue(thread.success); + if(thread.thrownException.isPresent()) { + Exception exception = thread.thrownException.get(); + logger.error("Thread for testing client failed", exception); + fail("Client thread " + thread + " failed: " + exception.getMessage()); + } } } class BlockingThread extends Thread { - Boolean success; + private Optional thrownException; public BlockingThread(String name) { super("client-" + name); @@ -211,10 +234,9 @@ public class ConcurrentClientsTest { public void run() { try { run2(); - success = true; + thrownException = Optional.absent(); } catch (Exception e) { - success = false; - throw new RuntimeException(e); + thrownException = Optional.of(e); } } @@ -254,7 +276,7 @@ public class ConcurrentClientsTest { private final String clientId; private final int attempts; - private Boolean success; + private Optional thrownException; TestingThread(String clientId, int attempts) { this.clientId = clientId; @@ -265,7 +287,7 @@ public class ConcurrentClientsTest { @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); @@ -275,10 +297,9 @@ public class ConcurrentClientsTest { logger.info("Client with sessionid {} got result {}", sessionId, result); netconfClient.close(); logger.info("Client with session id {} ended", sessionId); - success = true; + thrownException = Optional.absent(); } catch (final Exception e) { - success = false; - throw new RuntimeException(e); + thrownException = Optional.of(e); } } }