2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.client;
11 import io.netty.channel.nio.NioEventLoopGroup;
12 import org.junit.Before;
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import java.io.IOException;
20 import java.net.InetSocketAddress;
21 import java.util.concurrent.ExecutorService;
22 import java.util.concurrent.Executors;
23 import java.util.concurrent.TimeUnit;
26 public class SSHNetconfClientLiveTest {
27 private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class);
29 NioEventLoopGroup nettyThreadgroup;
30 NetconfSshClientDispatcher netconfClientDispatcher;
31 InetSocketAddress address;
32 final int connectionAttempts = 10, attemptMsTimeout = 1000;
33 final int connectionTimeoutMillis = 20000;
37 nettyThreadgroup = new NioEventLoopGroup();
39 netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword(
40 System.getProperty("username"), System.getProperty("password")),
41 nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis);
43 address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port")));
48 public void test() throws Exception {
53 public void testInExecutor() throws Exception {
55 ExecutorService executorService = Executors.newFixedThreadPool(threads);
57 for (int i= 0;i< threads;i++) {
58 InetSocketAddress address = new InetSocketAddress(System.getProperty("host"),
59 Integer.parseInt(System.getProperty("port")));
60 NetconfRunnable runnable = new NetconfRunnable(address);
61 executorService.execute(runnable);
63 executorService.shutdown();
64 executorService.awaitTermination(1, TimeUnit.MINUTES);
68 executorService.shutdownNow();
72 class NetconfRunnable implements Runnable {
73 private final InetSocketAddress address;
75 NetconfRunnable(InetSocketAddress address) {
76 this.address = address;
81 try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts,
82 attemptMsTimeout, netconfClientDispatcher);) {
83 logger.info("OK {}", address);
84 } catch (InterruptedException | IOException e) {
85 logger.error("Failed {}", address, e);