From 067ed6d6ce48cef0096d7d74037f87e97d876d89 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Wed, 30 Nov 2011 18:27:16 +0000 Subject: [PATCH] test for 738, downgrading some warnings to info --- .../org/jclouds/sshj/SshjSshClientTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java index e94f0dd201..9b5a130b46 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.ConnectException; import java.net.SocketTimeoutException; import java.util.Properties; +import java.util.logging.Level; import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.common.SSHException; @@ -37,11 +38,14 @@ import net.schmizz.sshj.transport.TransportException; import net.schmizz.sshj.userauth.UserAuthException; import org.jclouds.domain.Credentials; +import org.jclouds.logging.BufferLogger; +import org.jclouds.logging.BufferLogger.Record; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -179,4 +183,33 @@ public class SshjSshClientTest { assert !ssh1.shouldRetry(new RuntimeException(nex)); } + public void testRetriesLoggedAtInfoWithCount() throws Exception { + @SuppressWarnings("unchecked") + SshjSshClient.Connection mockConnection = createMock(SshjSshClient.Connection.class); + net.schmizz.sshj.SSHClient mockClient = createMock(net.schmizz.sshj.SSHClient.class); + + mockConnection.clear(); expectLastCall(); + mockConnection.create(); expectLastCall().andThrow(new ConnectionException("test1")); + mockConnection.clear(); expectLastCall(); + //currently does two clears, one on failure (above) and one on next iteration (below) + mockConnection.clear(); expectLastCall(); + mockConnection.create(); expectLastCall().andReturn(mockClient); + replay(mockConnection); + replay(mockClient); + + ssh.sshConnection = mockConnection; + BufferLogger logcheck = new BufferLogger(ssh.getClass().getCanonicalName()); + ssh.logger = logcheck; + logcheck.setLevel(Level.INFO); + + ssh.connect(); + + Assert.assertEquals(ssh.ssh, mockClient); + verify(mockConnection); + verify(mockClient); + Record r = logcheck.assertLogContains("attempt 1 of 5"); + logcheck.assertLogDoesntContain("attempt 2 of 5"); + Assert.assertEquals(Level.INFO, r.getLevel()); + } + }