X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FConcurrentClientsTest.java;h=db5a359d7a16c72784911a447b2756de36356b42;hp=c1a7b1478b3edde41ea5f13004afc48df540c6bf;hb=9c9d6e69da3aff2d0576d8c15ea0fa0692595b6d;hpb=d5759c52d69ba8725d9bbdc18e81848f319861d1 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 c1a7b1478b..db5a359d7a 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 @@ -18,10 +18,9 @@ import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClient; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; @@ -53,7 +52,7 @@ 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.MockitoAnnotations.initMocks; +import static org.mockito.Mockito.mock; public class ConcurrentClientsTest { @@ -68,14 +67,20 @@ public class ConcurrentClientsTest { private DefaultCommitNotificationProducer commitNot; private NetconfServerDispatcher dispatch; - @Mock - private SessionMonitoringService monitoring; + HashedWheelTimer hashedWheelTimer; + public static SessionMonitoringService createMockedMonitoringService() { + SessionMonitoringService monitoring = mock(SessionMonitoringService.class); + doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class)); + doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class)); + return monitoring; + } + @Before public void setUp() throws Exception { - initMocks(this); + nettyGroup = new NioEventLoopGroup(); NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("uname", "10.10.10.1", "830", "tcp", "client"); netconfClientDispatcher = new NetconfClientDispatcher( nettyGroup, nettyGroup, additionalHeader, 5000); @@ -86,16 +91,13 @@ public class ConcurrentClientsTest { SessionIdProvider idProvider = new SessionIdProvider(); hashedWheelTimer = new HashedWheelTimer(); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( - hashedWheelTimer, factoriesListener, idProvider, 5000); + hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, createMockedMonitoringService()); 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, monitoring); - NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory); + + NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory); dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup); ChannelFuture s = dispatch.createServer(netconfAddress); @@ -259,13 +261,13 @@ public class ConcurrentClientsTest { @Override public void run() { try { - final NetconfClient netconfClient = new NetconfClient(clientId, netconfAddress, netconfClientDispatcher); + final TestingNetconfClient netconfClient = new TestingNetconfClient(clientId, netconfAddress, netconfClientDispatcher); long sessionId = netconfClient.getSessionId(); logger.info("Client with sessionid {} hello exchanged", sessionId); final NetconfMessage getMessage = XmlFileLoader .xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - NetconfMessage result = netconfClient.sendMessage(getMessage); + NetconfMessage result = netconfClient.sendRequest(getMessage).get(); logger.info("Client with sessionid {} got result {}", sessionId, result); netconfClient.close(); logger.info("Client with session id {} ended", sessionId);