Merge pull request #117 from ahgittin/tidy

patch as per issue 739 (scanning error messages)
This commit is contained in:
Adrian Cole 2011-11-14 05:26:36 -08:00
commit 7c019ab0b0
4 changed files with 69 additions and 2 deletions

View File

@ -342,7 +342,8 @@ public class JschSshClient implements SshClient {
@Override
public boolean apply(Throwable arg0) {
return arg0.getMessage() != null && arg0.getMessage().indexOf(input) != -1;
return (arg0.toString().indexOf(input) != -1)
|| (arg0.getMessage() != null && arg0.getMessage().indexOf(input) != -1);
}
});

View File

@ -31,6 +31,8 @@ import org.jclouds.net.IPSocket;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.sshj.SshjSshClient;
import org.jclouds.sshj.SshjSshClientTest.ExceptionWithStrangeToString;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -127,4 +129,35 @@ public class JschSshClientTest {
assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read");
}
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());
JschSshClient ssh1 = createClient(props);
assert ssh1.shouldRetry(new RuntimeException(nex));
}
private static class ExceptionWithStrangeToString extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final String MESSAGE = "foo-bar-exception-tostring";
public String toString() { return MESSAGE; }
}
public void testRetryOnToStringCustom() {
Exception nex = new ExceptionWithStrangeToString();
Properties props = new Properties();
props.setProperty("jclouds.ssh.retryable-messages", "foo-bar");
JschSshClient ssh1 = createClient(props);
assert ssh1.shouldRetry(new RuntimeException(nex));
}
public void testRetryNotOnToStringCustomMismatch() {
Exception nex = new ExceptionWithStrangeToString();
Properties props = new Properties();
props.setProperty("jclouds.ssh.retryable-messages", "foo-baR");
JschSshClient ssh1 = createClient(props);
assert !ssh1.shouldRetry(new RuntimeException(nex));
}
}

View File

@ -396,7 +396,8 @@ public class SshjSshClient implements SshClient {
@Override
public boolean apply(Throwable arg0) {
return arg0.getMessage() != null && arg0.getMessage().indexOf(input) != -1;
return (arg0.toString().indexOf(input) != -1)
|| (arg0.getMessage() != null && arg0.getMessage().indexOf(input) != -1);
}
});

View File

@ -124,4 +124,36 @@ public class SshjSshClientTest {
.apply("java.net.Socket");
assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read");
}
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));
}
private static class ExceptionWithStrangeToString extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final String MESSAGE = "foo-bar-exception-tostring";
public String toString() { return MESSAGE; }
}
public void testRetryOnToStringCustom() {
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 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));
}
}