|
15 | 15 | import static org.testng.Assert.assertEquals;
|
16 | 16 | import static org.testng.Assert.assertNotNull;
|
17 | 17 | import static org.testng.Assert.assertNull;
|
18 |
| - |
| 18 | +import static org.testng.Assert.assertTrue; |
| 19 | +import static org.testng.Assert.fail; |
| 20 | +import java.net.ConnectException; |
19 | 21 | import java.util.concurrent.TimeUnit;
|
20 | 22 |
|
| 23 | +import com.ning.http.client.Response; |
| 24 | +import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig; |
21 | 25 | import org.jboss.netty.channel.Channel;
|
22 | 26 | import org.testng.annotations.Test;
|
23 | 27 |
|
@@ -116,4 +120,36 @@ public void destroy() {
|
116 | 120 | client.close();
|
117 | 121 | }
|
118 | 122 | }
|
| 123 | + |
| 124 | + @Test |
| 125 | + public void testHostNotContactable() { |
| 126 | + NettyAsyncHttpProviderConfig conf = new NettyAsyncHttpProviderConfig(); |
| 127 | + conf.addProperty(NettyAsyncHttpProviderConfig.EXECUTE_ASYNC_CONNECT,false); |
| 128 | + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAsyncHttpClientProviderConfig(conf) |
| 129 | + .setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); |
| 130 | + try { |
| 131 | + String url = null; |
| 132 | + try { |
| 133 | + url = "http://127.0.0.1:" + findFreePort(); |
| 134 | + } catch (Exception e) { |
| 135 | + fail("unable to find free port to simulate downed host"); |
| 136 | + } |
| 137 | + int i; |
| 138 | + for (i = 0; i < 2; i++) { |
| 139 | + try { |
| 140 | + log.info("{} requesting url [{}]...", i, url); |
| 141 | + Response response = client.prepareGet(url).execute().get(); |
| 142 | + log.info("{} response [{}].", i, response); |
| 143 | + } catch (Exception ex) { |
| 144 | + assertNotNull(ex.getCause()); |
| 145 | + Throwable cause = ex.getCause(); |
| 146 | + assertTrue(cause instanceof ConnectException); |
| 147 | + } |
| 148 | + } |
| 149 | + } finally { |
| 150 | + client.close(); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + |
119 | 155 | }
|
0 commit comments