Improve logging in NetconfClient, logging-bridge. Increase connection timeout in...
[controller.git] / opendaylight / netconf / netconf-client / src / test / java / org / opendaylight / controller / netconf / client / SSHNetconfClientLiveTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.client;
10
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;
18
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;
24
25 @Ignore
26 public class SSHNetconfClientLiveTest {
27     private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class);
28
29     NioEventLoopGroup nettyThreadgroup;
30     NetconfSshClientDispatcher netconfClientDispatcher;
31     InetSocketAddress address;
32     final int connectionAttempts = 10, attemptMsTimeout = 1000;
33     final int connectionTimeoutMillis = 20000;
34
35     @Before
36     public void setUp() {
37         nettyThreadgroup = new NioEventLoopGroup();
38
39         netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword(
40                 System.getProperty("username"), System.getProperty("password")),
41                 nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis);
42
43         address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port")));
44     }
45
46     @Ignore
47     @Test
48     public void test() throws Exception {
49         //runnable.run();
50     }
51
52     @Test
53     public void testInExecutor() throws Exception {
54         int threads = 4;
55         ExecutorService executorService = Executors.newFixedThreadPool(threads);
56         try {
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);
62             }
63             executorService.shutdown();
64             executorService.awaitTermination(1, TimeUnit.MINUTES);
65
66
67         } finally {
68             executorService.shutdownNow();
69         }
70     }
71
72     class NetconfRunnable implements Runnable {
73         private final InetSocketAddress address;
74
75         NetconfRunnable(InetSocketAddress address) {
76             this.address = address;
77         }
78
79         @Override
80         public void run() {
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);
86             }
87         }
88     };
89 }