|
7 | 7 | import com.databricks.sdk.core.http.Request; |
8 | 8 | import com.databricks.sdk.core.http.Response; |
9 | 9 | import java.io.IOException; |
| 10 | +import java.lang.reflect.Field; |
10 | 11 | import java.net.HttpURLConnection; |
11 | 12 | import java.util.*; |
12 | 13 | import org.apache.commons.io.IOUtils; |
13 | 14 | import org.apache.http.client.config.RequestConfig; |
| 15 | +import org.apache.http.client.methods.Configurable; |
14 | 16 | import org.junit.jupiter.api.Test; |
15 | 17 |
|
16 | 18 | class CommonsHttpClientTest { |
@@ -90,20 +92,21 @@ public void testNoRedirection() throws IOException { |
90 | 92 | } |
91 | 93 |
|
92 | 94 | @Test |
93 | | - public void testCustomRequestConfig() throws IOException { |
94 | | - try (FixtureServer fixtures = new FixtureServer().with("GET", "/foo", "ok", 200)) { |
95 | | - RequestConfig requestConfig = |
96 | | - RequestConfig.custom() |
97 | | - .setConnectTimeout(10_000) |
98 | | - .setSocketTimeout(900_000) |
99 | | - .setConnectionRequestTimeout(300_000) |
100 | | - .build(); |
101 | | - HttpClient httpClient = |
102 | | - new CommonsHttpClient.Builder().withRequestConfig(requestConfig).build(); |
103 | | - Request in = new Request("GET", fixtures.getUrl() + "/foo"); |
104 | | - Response out = httpClient.execute(in); |
105 | | - assertEquals("ok", out.getDebugBody().trim()); |
106 | | - } |
| 95 | + public void testCustomRequestConfig() throws Exception { |
| 96 | + RequestConfig requestConfig = |
| 97 | + RequestConfig.custom() |
| 98 | + .setConnectTimeout(10_000) |
| 99 | + .setSocketTimeout(900_000) |
| 100 | + .setConnectionRequestTimeout(300_000) |
| 101 | + .build(); |
| 102 | + CommonsHttpClient httpClient = |
| 103 | + new CommonsHttpClient.Builder().withRequestConfig(requestConfig).build(); |
| 104 | + |
| 105 | + // Verify that the custom RequestConfig is passed to the underlying Apache HttpClient. |
| 106 | + Field hcField = CommonsHttpClient.class.getDeclaredField("hc"); |
| 107 | + hcField.setAccessible(true); |
| 108 | + Configurable internalClient = (Configurable) hcField.get(httpClient); |
| 109 | + assertSame(requestConfig, internalClient.getConfig()); |
107 | 110 | } |
108 | 111 |
|
109 | 112 | @Test |
|
0 commit comments