@@ -97,10 +97,16 @@ public class OfrepProviderTest {
9797 private static final ObjectMapper deserializer =
9898 new ObjectMapper ().configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
9999
100+ private static final OfrepProvider ofrepProviderWithRequestTimeout =
101+ OfrepProvider .constructProvider (OfrepProviderOptions .builder ()
102+ .baseUrl ("http://10.255.255.1" )
103+ .requestTimeout (Duration .ofSeconds (2 ))
104+ .build ());
105+
100106 private static final OfrepProvider ofrepProviderWithConnectTimeout =
101107 OfrepProvider .constructProvider (OfrepProviderOptions .builder ()
102108 .baseUrl ("http://10.255.255.1" )
103- .timeout (Duration .ofSeconds (2 ))
109+ .connectTimeout (Duration .ofSeconds (2 ))
104110 .build ());
105111
106112 private static MockWebServer mockWebServer ;
@@ -452,7 +458,32 @@ void testRateLimit() throws JsonProcessingException, InterruptedException {
452458 }
453459
454460 @ Test
455- void testTimeoutConnection () throws JsonProcessingException {
461+ void testRequestTimeoutConnection () throws JsonProcessingException {
462+ OfrepResponse successfulStringResponse = new OfrepResponse ();
463+ successfulStringResponse .setKey (FLAG_KEY );
464+ successfulStringResponse .setValue (SUCCESSFUL_STRING_VALUE );
465+ successfulStringResponse .setReason (SUCCESSFUL_REASON );
466+ successfulStringResponse .setVariant (SUCCESSFUL_VARIANT );
467+ successfulStringResponse .setMetadata (FLAG_METADATA );
468+
469+ mockWebServer .enqueue (new MockResponse ()
470+ .setBody (serializer .writeValueAsString (successfulStringResponse ))
471+ .setBodyDelay (4 , TimeUnit .SECONDS )
472+ .setResponseCode (200 ));
473+
474+ ProviderEvaluation <String > evaluation = ofrepProviderWithRequestTimeout .getStringEvaluation (
475+ FLAG_KEY , DEFAULT_STRING_VALUE , new ImmutableContext ());
476+
477+ assertTrue (DEFAULT_STRING_VALUE .equals (evaluation .getValue ()));
478+ assertNull (evaluation .getVariant ());
479+ assertNull (evaluation .getReason ());
480+ assertTrue (ImmutableMetadata .builder ().build ().equals (evaluation .getFlagMetadata ()));
481+ assertTrue (ERROR_CODE_GENERAL .equals (evaluation .getErrorCode ().toString ()));
482+ assertTrue (ERROR_DETAIL_GENERAL_HTTP_TIMEOUT .equals (evaluation .getErrorMessage ()));
483+ }
484+
485+ @ Test
486+ void testConnectTimeoutConnection () throws JsonProcessingException {
456487 OfrepResponse successfulStringResponse = new OfrepResponse ();
457488 successfulStringResponse .setKey (FLAG_KEY );
458489 successfulStringResponse .setValue (SUCCESSFUL_STRING_VALUE );
@@ -542,23 +573,43 @@ void testConfigurationValidation() {
542573 OfrepProvider .constructProvider (options );
543574 });
544575
545- Exception exceptionNegativeTimeout = assertThrows (IllegalArgumentException .class , () -> {
576+ Exception exceptionNegativeConnectTimeout = assertThrows (IllegalArgumentException .class , () -> {
546577 OfrepProviderOptions options = OfrepProviderOptions .builder ()
547- .timeout (Duration .ofSeconds (-10 ))
578+ .connectTimeout (Duration .ofSeconds (-10 ))
548579 .build ();
549580 OfrepProvider .constructProvider (options );
550581 });
551582
552- Exception exceptionZeroedTimeout = assertThrows (IllegalArgumentException .class , () -> {
583+ Exception exceptionZeroedConnectTimeout = assertThrows (IllegalArgumentException .class , () -> {
553584 OfrepProviderOptions options = OfrepProviderOptions .builder ()
554- .timeout (Duration .ofSeconds (0 ))
585+ .connectTimeout (Duration .ofSeconds (0 ))
555586 .build ();
556587 OfrepProvider .constructProvider (options );
557588 });
558589
559- Exception exceptionNullTimeout = assertThrows (IllegalArgumentException .class , () -> {
590+ Exception exceptionNullConnectTimeout = assertThrows (IllegalArgumentException .class , () -> {
560591 OfrepProviderOptions options =
561- OfrepProviderOptions .builder ().timeout (null ).build ();
592+ OfrepProviderOptions .builder ().connectTimeout (null ).build ();
593+ OfrepProvider .constructProvider (options );
594+ });
595+
596+ Exception exceptionNegativeRequestTimeout = assertThrows (IllegalArgumentException .class , () -> {
597+ OfrepProviderOptions options = OfrepProviderOptions .builder ()
598+ .requestTimeout (Duration .ofSeconds (-10 ))
599+ .build ();
600+ OfrepProvider .constructProvider (options );
601+ });
602+
603+ Exception exceptionZeroedRequestTimeout = assertThrows (IllegalArgumentException .class , () -> {
604+ OfrepProviderOptions options = OfrepProviderOptions .builder ()
605+ .requestTimeout (Duration .ofSeconds (0 ))
606+ .build ();
607+ OfrepProvider .constructProvider (options );
608+ });
609+
610+ Exception exceptionNullRequestTimeout = assertThrows (IllegalArgumentException .class , () -> {
611+ OfrepProviderOptions options =
612+ OfrepProviderOptions .builder ().requestTimeout (null ).build ();
562613 OfrepProvider .constructProvider (options );
563614 });
564615
@@ -577,9 +628,14 @@ void testConfigurationValidation() {
577628 assertTrue (exceptionInvalidBaseUrl .getMessage ().contains ("Invalid base URL" ));
578629 assertTrue (exceptionNullBaseUrl .getMessage ().contains ("Invalid base URL" ));
579630 assertTrue (exceptionNullHeaders .getMessage ().contains ("Headers cannot be null" ));
580- assertTrue (exceptionNegativeTimeout .getMessage ().contains ("Timeout must be a positive duration" ));
581- assertTrue (exceptionZeroedTimeout .getMessage ().contains ("Timeout must be a positive duration" ));
582- assertTrue (exceptionNullTimeout .getMessage ().contains ("Timeout must be a positive duration" ));
631+ assertTrue (
632+ exceptionNegativeRequestTimeout .getMessage ().contains ("Request timeout must be a positive duration" ));
633+ assertTrue (exceptionZeroedRequestTimeout .getMessage ().contains ("Request timeout must be a positive duration" ));
634+ assertTrue (exceptionNullRequestTimeout .getMessage ().contains ("Request timeout must be a positive duration" ));
635+ assertTrue (
636+ exceptionNegativeConnectTimeout .getMessage ().contains ("Connect timeout must be a positive duration" ));
637+ assertTrue (exceptionZeroedConnectTimeout .getMessage ().contains ("Connect timeout must be a positive duration" ));
638+ assertTrue (exceptionNullConnectTimeout .getMessage ().contains ("Connect timeout must be a positive duration" ));
583639 assertTrue (exceptionNullProxySelector .getMessage ().contains ("ProxySelector cannot be null" ));
584640 assertTrue (exceptionNullExecutor .getMessage ().contains ("Executor cannot be null" ));
585641 }
0 commit comments