X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnetty%2FSSHTest.java;h=ab731260216f4452f6ba3d5e8c6b64c8179bdad2;hb=d2d4cefa4d8d662554b7f2fc0b0dd568d0db1180;hp=34b236b4611f0e8586388e7ff22b1022effc2cd0;hpb=1b69a9ae877e79ba6addb1b0e343692b2acff1ec;p=controller.git diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java index 34b236b461..ab73126021 100644 --- a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java +++ b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java @@ -19,6 +19,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.HashedWheelTimer; +import java.io.File; import java.net.InetSocketAddress; import java.nio.file.Files; import java.util.concurrent.ExecutorService; @@ -41,7 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SSHTest { - public static final Logger logger = LoggerFactory.getLogger(SSHTest.class); + private static final Logger LOG = LoggerFactory.getLogger(SSHTest.class); public static final String AHOJ = "ahoj\n"; private static EventLoopGroup nettyGroup; @@ -67,6 +68,8 @@ public class SSHTest { @Test public void test() throws Exception { + File sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile(); + sshKeyPair.deleteOnExit(); new Thread(new EchoServer(), "EchoServer").start(); final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831); @@ -77,16 +80,16 @@ public class SSHTest { public boolean authenticate(final String username, final String password, final ServerSession session) { return true; } - }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration()); + }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration()); final EchoClientHandler echoClientHandler = connectClient(addr); - Stopwatch stopwatch = new Stopwatch().start(); + Stopwatch stopwatch = Stopwatch.createStarted(); while(echoClientHandler.isConnected() == false && stopwatch.elapsed(TimeUnit.SECONDS) < 30) { Thread.sleep(500); } assertTrue(echoClientHandler.isConnected()); - logger.info("connected, writing to client"); + LOG.info("connected, writing to client"); echoClientHandler.write(AHOJ); // check that server sent back the same string @@ -99,7 +102,7 @@ public class SSHTest { final String read = echoClientHandler.read(); assertTrue(read + " should end with " + AHOJ, read.endsWith(AHOJ)); } finally { - logger.info("Closing socket"); + LOG.info("Closing socket"); sshProxyServer.close(); } } @@ -128,12 +131,12 @@ public class SSHTest { public void testClientWithoutServer() throws Exception { final InetSocketAddress address = new InetSocketAddress(12345); final EchoClientHandler echoClientHandler = connectClient(address); - final Stopwatch stopwatch = new Stopwatch().start(); + final Stopwatch stopwatch = Stopwatch.createStarted(); while(echoClientHandler.getState() == State.CONNECTING && stopwatch.elapsed(TimeUnit.SECONDS) < 5) { Thread.sleep(100); } assertFalse(echoClientHandler.isConnected()); - assertEquals(State.CONNECTION_CLOSED, echoClientHandler.getState()); + assertEquals(State.FAILED_TO_CONNECT, echoClientHandler.getState()); } }