public void testRetriesLoggedAtInfoWithCount() throws Exception {
    SSHClientConnection mockConnection = createMock(SSHClientConnection.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.sshClientConnection = mockConnection;
    BufferLogger logcheck = new BufferLogger(ssh.getClass().getCanonicalName());
    ssh.logger = logcheck;
    logcheck.setLevel(Level.INFO);

    ssh.connect();

    Assert.assertEquals(ssh.sshClientConnection, mockConnection);
    verify(mockConnection);
    verify(mockClient);
    Record r = logcheck.assertLogContains("attempt 1 of 5");
    logcheck.assertLogDoesntContain("attempt 2 of 5");
    Assert.assertEquals(Level.INFO, r.getLevel());
  }
 public void testOnlyRetryAuthWhenSetViaProperties() {
   Properties props = new Properties();
   props.setProperty("jclouds.ssh.retry-auth", "true");
   SshjSshClient ssh1 = createClient(props);
   assert ssh1.shouldRetry(new AuthorizationException("problem", null));
   assert ssh1.shouldRetry(new UserAuthException("problem", null));
 }
 public void testRetryNotOnToStringCustomMismatch() {
   Exception nex = new ExceptionWithStrangeToString();
   Properties props = new Properties();
   props.setProperty("jclouds.ssh.retryable-messages", "foo-baR");
   SshjSshClient ssh1 = createClient(props);
   assert !ssh1.shouldRetry(new RuntimeException(nex));
 }
 public void testRetryOnToStringNpe() {
   Exception nex = new NullPointerException();
   Properties props = new Properties();
   // ensure we test toString on the exception independently
   props.setProperty("jclouds.ssh.retryable-messages", nex.toString());
   SshjSshClient ssh1 = createClient(props);
   assert ssh1.shouldRetry(new RuntimeException(nex));
 }
 public void testCausalChainHasMessageContaining() {
   assert ssh.causalChainHasMessageContaining(
           new SSHException("Session.connect: java.io.IOException: End of IO Stream Read"))
       .apply(" End of IO Stream Read");
   assert ssh.causalChainHasMessageContaining(
           new SSHException("Session.connect: java.net.SocketException: Connection reset"))
       .apply("java.net.Socket");
   assert !ssh.causalChainHasMessageContaining(new NullPointerException())
       .apply(" End of IO Stream Read");
 }
 public void testOnlyRetryAuthWhenSet() {
   SshjSshClient ssh1 = createClient();
   assert !ssh1.shouldRetry(new AuthorizationException("problem", null));
   assert !ssh1.shouldRetry(new UserAuthException("problem", null));
   ssh1.retryAuth = true;
   assert ssh1.shouldRetry(new AuthorizationException("problem", null));
   assert ssh1.shouldRetry(new UserAuthException("problem", null));
 }
 public void testExceptionClassesRetry() {
   assert ssh.shouldRetry(
       new ConnectionException(
           "Read timed out",
           new SSHException("Read timed out", new SocketTimeoutException("Read timed out"))));
   assert ssh.shouldRetry(new SFTPException("Failure!"));
   assert ssh.shouldRetry(new SocketTimeoutException("connect timed out"));
   assert ssh.shouldRetry(new TransportException("socket closed"));
   assert ssh.shouldRetry(new ConnectionException("problem"));
   assert ssh.shouldRetry(new ConnectException("Connection refused"));
   assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
 }
 @Test(expectedExceptions = AuthorizationException.class)
 public void testPropateConvertsAuthException() {
   ssh.propagate(new UserAuthException(""), "");
 }
 public void testExceptionMessagesRetry() {
   assert !ssh.shouldRetry(new SSHException(""));
   assert !ssh.shouldRetry(new NullPointerException((String) null));
 }
 public void testExceptionClassesRetry() {
   assert ssh.shouldRetry(new TransportException("socket closed"));
   assert ssh.shouldRetry(new ConnectionException("problem"));
   assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException()));
 }