Fixed broken test case

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1059273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-01-15 08:24:18 +00:00
parent a877471bb9
commit 6ba7afe88a
1 changed files with 23 additions and 26 deletions

View File

@ -35,8 +35,6 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SchemeSocketFactory;
@ -50,48 +48,28 @@ import org.junit.Test;
public class TestRequestRetryHandler {
@Test(expected=HttpHostConnectException.class)
@Test(expected=UnknownHostException.class)
public void testUseRetryHandlerInConnectionTimeOutWithThreadSafeClientConnManager()
throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
ClientConnectionManager connManager = new ThreadSafeClientConnManager(schemeRegistry);
assertOnRetry(connManager);
}
@Test(expected=HttpHostConnectException.class)
@Test(expected=UnknownHostException.class)
public void testUseRetryHandlerInConnectionTimeOutWithSingleClientConnManager()
throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
ClientConnectionManager connManager = new SingleClientConnManager(schemeRegistry);
assertOnRetry(connManager);
}
protected void assertOnRetry(ClientConnectionManager connManager) throws Exception {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, new SchemeSocketFactory() {
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
return false;
}
public Socket createSocket(final HttpParams params) throws IOException {
throw new UnknownHostException("Ooopsie");
}
public Socket connectSocket(
final Socket sock,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
throw new UnknownHostException("Ooopsie");
}
}));
DefaultHttpClient client = new DefaultHttpClient(connManager);
TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler();
client.setHttpRequestRetryHandler(testRetryHandler);
@ -121,4 +99,23 @@ public class TestRequestRetryHandler {
}
static class OppsieSchemeSocketFactory implements SchemeSocketFactory {
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
return false;
}
public Socket createSocket(final HttpParams params) throws IOException {
return new Socket();
}
public Socket connectSocket(
final Socket sock,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
throw new UnknownHostException("Ooopsie");
}
}
}