X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FSSHNetconfClientLiveTest.java;h=1357201f5754d75ee6d7b4874aa78f6a6ceb48d7;hp=a3cc10417e389123169abe940d05cddf7f98b85b;hb=dbb635f96384aa204520ad7109fe072a7044ff6d;hpb=3c4c5f529dadea6a027cbb6430ae631da883d83d diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java index a3cc10417e..1357201f57 100644 --- a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java @@ -12,38 +12,78 @@ import io.netty.channel.nio.NioEventLoopGroup; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.util.NetconfUtil; import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; import java.net.InetSocketAddress; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; @Ignore public class SSHNetconfClientLiveTest { + private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class); NioEventLoopGroup nettyThreadgroup; NetconfSshClientDispatcher netconfClientDispatcher; + InetSocketAddress address; + final int connectionAttempts = 10, attemptMsTimeout = 1000; + final int connectionTimeoutMillis = 20000; @Before public void setUp() { nettyThreadgroup = new NioEventLoopGroup(); + netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword( System.getProperty("username"), System.getProperty("password")), - nettyThreadgroup, nettyThreadgroup, 5000); + nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis); + + address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port"))); } + @Ignore @Test public void test() throws Exception { - InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), 830); - int connectionAttempts = 10, attemptMsTimeout = 1000; + //runnable.run(); + } - NetconfClient netconfClient = new NetconfClient("client", address, connectionAttempts, - attemptMsTimeout, netconfClientDispatcher); + @Test + public void testInExecutor() throws Exception { + int threads = 4; + ExecutorService executorService = Executors.newFixedThreadPool(threads); + try { + for (int i= 0;i< threads;i++) { + InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), + Integer.parseInt(System.getProperty("port"))); + NetconfRunnable runnable = new NetconfRunnable(address); + executorService.execute(runnable); + } + executorService.shutdown(); + executorService.awaitTermination(1, TimeUnit.MINUTES); - netconfClient.getCapabilities(); - NetconfMessage netconfMessage = NetconfUtil.createMessage(getClass().getResourceAsStream("/get_schema.xml")); - NetconfMessage response = netconfClient.sendMessage(netconfMessage); - NetconfUtil.checkIsMessageOk(response); + } finally { + executorService.shutdownNow(); + } } + + class NetconfRunnable implements Runnable { + private final InetSocketAddress address; + + NetconfRunnable(InetSocketAddress address) { + this.address = address; + } + + @Override + public void run() { + try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts, + attemptMsTimeout, netconfClientDispatcher);) { + logger.info("OK {}", address); + } catch (InterruptedException | IOException e) { + logger.error("Failed {}", address, e); + } + } + }; }