@@ -1013,6 +1013,99 @@ public void testHttpClientMldevDefaultClientOptions() throws Exception {
10131013 assertFalse (client .vertexAI ());
10141014 }
10151015
1016+ @ Test
1017+ public void testHttpClientMldevWithTimeoutSettings () throws Exception {
1018+ ClientOptions clientOptions =
1019+ ClientOptions .builder ()
1020+ .readTimeout (5000 )
1021+ .writeTimeout (10000 )
1022+ .callTimeout (15000 )
1023+ .build ();
1024+ HttpApiClient client =
1025+ new HttpApiClient (Optional .of (API_KEY ), Optional .empty (), Optional .of (clientOptions ));
1026+
1027+ OkHttpClient httpClient = client .httpClient ();
1028+
1029+ assertEquals (API_KEY , client .apiKey ());
1030+ assertFalse (client .vertexAI ());
1031+ assertEquals (5000 , httpClient .readTimeoutMillis ());
1032+ assertEquals (10000 , httpClient .writeTimeoutMillis ());
1033+ assertEquals (15000 , httpClient .callTimeoutMillis ());
1034+ }
1035+
1036+ @ Test
1037+ public void testHttpClientVertexWithTimeoutSettings () throws Exception {
1038+ ClientOptions clientOptions =
1039+ ClientOptions .builder ()
1040+ .readTimeout (3000 )
1041+ .writeTimeout (6000 )
1042+ .callTimeout (9000 )
1043+ .build ();
1044+ HttpApiClient client =
1045+ new HttpApiClient (
1046+ Optional .empty (),
1047+ Optional .of (PROJECT ),
1048+ Optional .of (LOCATION ),
1049+ Optional .of (CREDENTIALS ),
1050+ Optional .empty (),
1051+ Optional .of (clientOptions ));
1052+
1053+ OkHttpClient httpClient = client .httpClient ();
1054+
1055+ assertEquals (PROJECT , client .project ());
1056+ assertEquals (LOCATION , client .location ());
1057+ assertTrue (client .vertexAI ());
1058+ assertEquals (3000 , httpClient .readTimeoutMillis ());
1059+ assertEquals (6000 , httpClient .writeTimeoutMillis ());
1060+ assertEquals (9000 , httpClient .callTimeoutMillis ());
1061+ }
1062+
1063+ @ Test
1064+ public void testHttpClientWithPartialTimeoutSettings () throws Exception {
1065+ ClientOptions clientOptions =
1066+ ClientOptions .builder ()
1067+ .readTimeout (5000 )
1068+ .build ();
1069+ HttpApiClient client =
1070+ new HttpApiClient (Optional .of (API_KEY ), Optional .empty (), Optional .of (clientOptions ));
1071+
1072+ OkHttpClient httpClient = client .httpClient ();
1073+
1074+ assertEquals (API_KEY , client .apiKey ());
1075+ assertFalse (client .vertexAI ());
1076+ assertEquals (5000 , httpClient .readTimeoutMillis ());
1077+ // When not set, timeouts should remain at default 0 (no timeout)
1078+ assertEquals (0 , httpClient .writeTimeoutMillis ());
1079+ assertEquals (0 , httpClient .callTimeoutMillis ());
1080+ }
1081+
1082+ @ Test
1083+ public void testHttpClientWithAllClientOptionsIncludingTimeouts () throws Exception {
1084+ ClientOptions clientOptions =
1085+ ClientOptions .builder ()
1086+ .maxConnections (32 )
1087+ .maxConnectionsPerHost (8 )
1088+ .readTimeout (2000 )
1089+ .writeTimeout (4000 )
1090+ .callTimeout (8000 )
1091+ .build ();
1092+ HttpApiClient client =
1093+ new HttpApiClient (Optional .of (API_KEY ), Optional .empty (), Optional .of (clientOptions ));
1094+
1095+ OkHttpClient httpClient = client .httpClient ();
1096+ Dispatcher dispatcher = httpClient .dispatcher ();
1097+
1098+ assertEquals (API_KEY , client .apiKey ());
1099+ assertFalse (client .vertexAI ());
1100+ // Test dispatcher settings
1101+ assertEquals (32 , dispatcher .getMaxRequests ());
1102+ assertEquals (8 , dispatcher .getMaxRequestsPerHost ());
1103+ // Test timeout settings
1104+ assertEquals (2000 , httpClient .readTimeoutMillis ());
1105+ assertEquals (4000 , httpClient .writeTimeoutMillis ());
1106+ assertEquals (8000 , httpClient .callTimeoutMillis ());
1107+ }
1108+
10161109 @ Test
10171110 public void testHttpClientWithCustomCredentials () throws Exception {
10181111 HttpApiClient client =
0 commit comments