Skip to content

Commit b4c1ace

Browse files
author
eugenp
committed
httpclient - timeout simulation for a domain
1 parent 8f7f048 commit b4c1ace

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

httpclient/src/test/java/org/baeldung/httpclient/HttpClientTimeoutLiveTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,20 @@ public final void givenUsingNewApi_whenSettingTimeoutViaHighLevelApi_thenCorrect
9292
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
9393
}
9494

95+
/**
96+
* This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP)
97+
*/
98+
@Test
99+
public final void givenTimeoutIsConfigured_whenTimingOut_thenCorrect() throws ClientProtocolException, IOException {
100+
final int timeout = 3;
101+
102+
final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();
103+
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
104+
105+
final HttpGet request = new HttpGet("http://www.google.com:81");
106+
response = client.execute(request);
107+
108+
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
109+
}
110+
95111
}

0 commit comments

Comments
 (0)