Skip to content

Commit 5fed991

Browse files
Verify custom RequestConfig is passed to underlying Apache HttpClient
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3f4cb74 commit 5fed991

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

databricks-sdk-java/src/test/java/com/databricks/sdk/core/commons/CommonsHttpClientTest.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import com.databricks.sdk.core.http.Request;
88
import com.databricks.sdk.core.http.Response;
99
import java.io.IOException;
10+
import java.lang.reflect.Field;
1011
import java.net.HttpURLConnection;
1112
import java.util.*;
1213
import org.apache.commons.io.IOUtils;
1314
import org.apache.http.client.config.RequestConfig;
15+
import org.apache.http.client.methods.Configurable;
1416
import org.junit.jupiter.api.Test;
1517

1618
class CommonsHttpClientTest {
@@ -90,20 +92,21 @@ public void testNoRedirection() throws IOException {
9092
}
9193

9294
@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());
107110
}
108111

109112
@Test

0 commit comments

Comments
 (0)