tests for 739

This commit is contained in:
Alex Heneveld 2011-11-14 01:41:39 +00:00
parent f4656c9e05
commit 524bf68dd9
2 changed files with 65 additions and 0 deletions

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

@ -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));
}
}