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);
+ }
+ }
+ };
}