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=db5a359d7a16c72784911a447b2756de36356b42;hb=9c9d6e69da3aff2d0576d8c15ea0fa0692595b6d;hp=0ef2c285e407ac65b9eb62e0bbfc2d14b555c242;hpb=6fd408a04fe4a3611843e2246ece6d7c34b76903;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 0ef2c285e4..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,32 +18,25 @@ import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; -import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.yang.store.api.YangStoreService; -import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfOperationRouter; -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; 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.opendaylight.controller.netconf.mapping.api.NetconfOperationFilter; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -import javax.management.ObjectName; import java.io.DataOutputStream; import java.io.InputStream; import java.io.InputStreamReader; @@ -59,7 +52,6 @@ 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 { @@ -68,11 +60,6 @@ public class ConcurrentClientsTest { private EventLoopGroup nettyGroup; private NetconfClientDispatcher netconfClientDispatcher; - @Mock - private YangStoreService yangStoreService; - @Mock - private ConfigRegistryJMXClient jmxClient; - private final InetSocketAddress netconfAddress = new InetSocketAddress("127.0.0.1", 8303); static final Logger logger = LoggerFactory.getLogger(ConcurrentClientsTest.class); @@ -80,27 +67,23 @@ 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 { - { // init mocks - MockitoAnnotations.initMocks(this); - final YangStoreSnapshot yStore = mock(YangStoreSnapshot.class); - doReturn(yStore).when(this.yangStoreService).getYangStoreSnapshot(); - doReturn(Collections.emptyMap()).when(yStore).getModuleMXBeanEntryMap(); - - 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); + NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("uname", "10.10.10.1", "830", "tcp", "client"); + netconfClientDispatcher = new NetconfClientDispatcher( nettyGroup, nettyGroup, additionalHeader, 5000); NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); factoriesListener.onAddNetconfOperationServiceFactory(mockOpF()); @@ -108,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); @@ -133,7 +113,7 @@ public class ConcurrentClientsTest { private NetconfOperationServiceFactory mockOpF() { return new NetconfOperationServiceFactory() { @Override - public NetconfOperationService createService(long netconfSessionId, String netconfSessionIdForReporting) { + public NetconfOperationService createService(String netconfSessionIdForReporting) { return new NetconfOperationService() { @Override public Set getCapabilities() { @@ -149,8 +129,7 @@ public class ConcurrentClientsTest { } @Override - public Document handle(Document message, NetconfOperationRouter operationRouter) - throws NetconfDocumentedException { + public Document handle(Document requestMessage, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { try { return XmlUtil.readXmlToDocument(""); } catch (Exception e) { @@ -160,11 +139,6 @@ public class ConcurrentClientsTest { }); } - @Override - public Set getFilters() { - return Collections.emptySet(); - } - @Override public void close() { } @@ -287,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);