From: Marian Dubai Date: Thu, 4 Dec 2014 11:53:42 +0000 (+0100) Subject: Bug-2342: Add stress test with more threads and start of testtool device. X-Git-Tag: release/lithium~750^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=12db0a738ac10ae139248c253b0bf2980752658d Bug-2342: Add stress test with more threads and start of testtool device. Change-Id: Ic8cadf339d330d9e165db4b0eafe8e8408601abd Signed-off-by: Marian Dubai --- diff --git a/opendaylight/netconf/netconf-it/pom.xml b/opendaylight/netconf/netconf-it/pom.xml index 7218ac7872..6e4c16d20f 100644 --- a/opendaylight/netconf/netconf-it/pom.xml +++ b/opendaylight/netconf/netconf-it/pom.xml @@ -122,6 +122,12 @@ netconf-ssh test + + ${project.groupId} + netconf-testtool + ${project.version} + test + ${project.groupId} netconf-ssh 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 5f316d11c1..bd8e2ed4df 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 @@ -41,8 +41,6 @@ import org.apache.sshd.server.session.ServerSession; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.auth.AuthProvider; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; @@ -116,7 +114,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { @Test public void testSecure() throws Exception { final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); - try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener()))) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener(), TLS_ADDRESS))) { NetconfMessage response = netconfClient.sendMessage(getGetConfig()); assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), NetconfMessageUtil.isErrorMessage(response)); @@ -143,7 +141,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); final NetconfDeviceCommunicator sessionListener = getSessionListener(); - try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener))) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener, TLS_ADDRESS))) { final AtomicInteger responseCounter = new AtomicInteger(0); final List>> futures = Lists.newArrayList(); @@ -182,15 +180,15 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { } } - private NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException { + public static NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException { String s = XmlUtil.toString(getConfig.getDocument(), false); s = s.replace("101", Integer.toString(i)); return new NetconfMessage(XmlUtil.readXmlToDocument(s)); } - public NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener) throws IOException { + static NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener,final InetSocketAddress tlsAddress) throws IOException { final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create(); - b.withAddress(TLS_ADDRESS); + b.withAddress(tlsAddress); // Using session listener from sal-netconf-connector since stress test cannot be performed with simple listener b.withSessionListener(sessionListener); b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)); @@ -200,11 +198,8 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { return b.build(); } - @Mock - private RemoteDevice mockedRemoteDevice; - - private NetconfDeviceCommunicator getSessionListener() { - MockitoAnnotations.initMocks(this); + static NetconfDeviceCommunicator getSessionListener() { + RemoteDevice mockedRemoteDevice = mock(RemoteDevice.class); doNothing().when(mockedRemoteDevice).onRemoteSessionUp(any(NetconfSessionCapabilities.class), any(RemoteDeviceCommunicator.class)); doNothing().when(mockedRemoteDevice).onRemoteSessionDown(); return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test"), mockedRemoteDevice); @@ -217,7 +212,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { return mockAuth; } - public AuthenticationHandler getAuthHandler() throws IOException { + public static AuthenticationHandler getAuthHandler() throws IOException { return new LoginPassword(USERNAME, PASSWORD); } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTestTool.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTestTool.java new file mode 100644 index 0000000000..02472733ba --- /dev/null +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTestTool.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html.html + */ + +package org.opendaylight.controller.netconf.it; + +import static java.lang.Thread.sleep; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.opendaylight.controller.netconf.it.NetconfITSecureTest.getSessionListener; + +import com.google.common.base.Throwables; +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.util.HashedWheelTimer; +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; +import org.opendaylight.controller.netconf.test.tool.Main.Params; +import org.opendaylight.controller.netconf.test.tool.NetconfDeviceSimulator; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; + +public class NetconfITSecureTestTool +{ + + //set up port both for testool device and test + public static final int PORT = 17833; + private static final InetSocketAddress TLS_ADDRESS = new InetSocketAddress("127.0.0.1", PORT); + + private String xmlFile = "netconfMessages/editConfig.xml"; + + private ExecutorService msgExec = Executors.newFixedThreadPool(8); + + Collection> tasks = new LinkedList>(); + + final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(); + + @Before + public void setUp() throws Exception { + + //Set up parameters for testtool device + Params params = new Params(); + params.debug = true; + params.deviceCount = 1; + params.startingPort = PORT; + params.ssh = true; + params.exi = true; + + final List openDevices = netconfDeviceSimulator.start(params); + } + + @After + public void tearDown() throws Exception { + + } + + /** + * Test all requests are handled properly and no mismatch occurs in listener + */ + @Test(timeout = 6*60*1000) + public void testSecureStress() throws Exception { + + final int requests = 4000; + + List> tasks = new ArrayList<>(); + + final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), new HashedWheelTimer()); + + final NetconfDeviceCommunicator sessionListener = getSessionListener(); + + try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, NetconfITSecureTest.getClientConfiguration(sessionListener, TLS_ADDRESS));) + { + + final AtomicInteger responseCounter = new AtomicInteger(0); + final List>> futures = Lists.newArrayList(); + + for (int i = 0; i < requests; i++) { + + NetconfMessage getConfig = XmlFileLoader.xmlFileToNetconfMessage(xmlFile); + + getConfig = NetconfITSecureTest.changeMessageId(getConfig,i); + + Runnable worker = new NetconfITSecureTestToolRunnable(getConfig,i, sessionListener, futures, responseCounter); + + tasks.add(msgExec.submit(worker)); + + } + + msgExec.shutdown(); + + // Wait for every future + for (final Future task : tasks){ + try + { + + task.get(3, TimeUnit.MINUTES); + } catch (final TimeoutException e) { + fail(String.format("Request %d is not responding", tasks.indexOf(task))); + } + } + + for (final ListenableFuture> future : futures) { + try { + + future.get(3, TimeUnit.MINUTES); + } catch (final TimeoutException e) { + fail(String.format("Reply %d is not responding", futures.indexOf(future))); + } + } + + sleep(5000); + + assertEquals(requests, responseCounter.get()); + + } + } + + class NetconfITSecureTestToolRunnable implements Runnable { + + private NetconfMessage getConfig; + private int it; + private NetconfDeviceCommunicator sessionListener; + private List>> futures; + private AtomicInteger responseCounter; + + public NetconfITSecureTestToolRunnable(NetconfMessage getConfig, int it, NetconfDeviceCommunicator sessionListener, List>> futures, AtomicInteger responseCounter){ + this.getConfig = getConfig; + this.it = it; + this.sessionListener = sessionListener; + this.futures = futures; + this.responseCounter = responseCounter; + } + + @Override + public void run(){ + + ListenableFuture> netconfMessageFuture; + + netconfMessageFuture = sessionListener.sendRequest(getConfig, QName.create("namespace", "2012-12-12", "get")); + + futures.add(netconfMessageFuture); + Futures.addCallback(netconfMessageFuture, new FutureCallback>() { + + @Override + public void onSuccess(final RpcResult result) { + + if(result.isSuccessful()&result.getErrors().isEmpty()) { + responseCounter.incrementAndGet(); + } else { + + fail(String.format("Message result not ok %s", result.getErrors().toString())); + + } + } + + @Override + public void onFailure(final Throwable t) { + + fail(String.format("Message failed %s", Throwables.getStackTraceAsString(t))); + + } + } + ); + } + } + +} diff --git a/opendaylight/netconf/netconf-it/src/test/resources/logback-test.xml b/opendaylight/netconf/netconf-it/src/test/resources/logback-test.xml index 91fb805e6a..e9ee13d8b6 100644 --- a/opendaylight/netconf/netconf-it/src/test/resources/logback-test.xml +++ b/opendaylight/netconf/netconf-it/src/test/resources/logback-test.xml @@ -6,8 +6,8 @@ - - + + diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/Main.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/Main.java index e441c709cc..e52fce7ae0 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/Main.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/Main.java @@ -46,7 +46,7 @@ public final class Main { private static final Logger LOG = LoggerFactory.getLogger(Main.class); - static class Params { + public static class Params { @Arg(dest = "schemas-dir") public File schemasDir; diff --git a/opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml b/opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml index 5dd5a90f7d..a0458c45e3 100644 --- a/opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml +++ b/opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml @@ -1,4 +1,4 @@ - +