@@ -1001,4 +1001,80 @@ public void bothFdv1FallbackAndEnvironmentIdExtractedFromHeaders() throws Except
10011001 synchronizer .close ();
10021002 }
10031003 }
1004+
1005+ @ Test
1006+ public void serializationExceptionWithoutFallbackHeader () throws Exception {
1007+ // Verify that fallback is false when header is not present
1008+ // Use malformed JSON that will cause parsing to fail
1009+ String badEvent = makeEvent ("server-intent" , "{" );
1010+
1011+ try (HttpServer server = HttpServer .start (Handlers .all (
1012+ Handlers .SSE .start (),
1013+ Handlers .SSE .event (badEvent ),
1014+ Handlers .SSE .leaveOpen ()))) {
1015+
1016+ HttpProperties httpProperties = toHttpProperties (clientContext ("sdk-key" , baseConfig ().build ()).getHttp ());
1017+ SelectorSource selectorSource = mockSelectorSource ();
1018+
1019+ StreamingSynchronizerImpl synchronizer = new StreamingSynchronizerImpl (
1020+ httpProperties ,
1021+ server .getUri (),
1022+ "/stream" ,
1023+ testLogger ,
1024+ selectorSource ,
1025+ null ,
1026+ Duration .ofMillis (100 )
1027+ );
1028+
1029+ CompletableFuture <FDv2SourceResult > resultFuture = synchronizer .next ();
1030+ FDv2SourceResult result = resultFuture .get (5 , TimeUnit .SECONDS );
1031+
1032+ assertNotNull (result );
1033+ assertEquals (FDv2SourceResult .ResultType .STATUS , result .getResultType ());
1034+ assertEquals (FDv2SourceResult .State .INTERRUPTED , result .getStatus ().getState ());
1035+ assertEquals (DataSourceStatusProvider .ErrorKind .INVALID_DATA , result .getStatus ().getErrorInfo ().getKind ());
1036+ assertEquals (false , result .isFdv1Fallback ());
1037+
1038+ synchronizer .close ();
1039+ }
1040+ }
1041+
1042+ @ Test
1043+ public void serializationExceptionPreservesFallbackHeader () throws Exception {
1044+ // Test that when SerializationException occurs, the fallback header from the event is preserved
1045+ // Use definitely malformed JSON that will cause parsing to fail
1046+ String badEvent = makeEvent ("server-intent" , "{" );
1047+
1048+ try (HttpServer server = HttpServer .start (Handlers .all (
1049+ Handlers .header ("x-ld-fd-fallback" , "true" ),
1050+ Handlers .SSE .start (),
1051+ Handlers .SSE .event (badEvent ),
1052+ Handlers .SSE .leaveOpen ()))) {
1053+
1054+ HttpProperties httpProperties = toHttpProperties (clientContext ("sdk-key" , baseConfig ().build ()).getHttp ());
1055+ SelectorSource selectorSource = mockSelectorSource ();
1056+
1057+ StreamingSynchronizerImpl synchronizer = new StreamingSynchronizerImpl (
1058+ httpProperties ,
1059+ server .getUri (),
1060+ "/stream" ,
1061+ testLogger ,
1062+ selectorSource ,
1063+ null ,
1064+ Duration .ofMillis (100 )
1065+ );
1066+
1067+ CompletableFuture <FDv2SourceResult > resultFuture = synchronizer .next ();
1068+ FDv2SourceResult result = resultFuture .get (5 , TimeUnit .SECONDS );
1069+
1070+ assertNotNull (result );
1071+ assertEquals (FDv2SourceResult .ResultType .STATUS , result .getResultType ());
1072+ assertEquals (FDv2SourceResult .State .INTERRUPTED , result .getStatus ().getState ());
1073+ assertEquals (DataSourceStatusProvider .ErrorKind .INVALID_DATA , result .getStatus ().getErrorInfo ().getKind ());
1074+ assertEquals (true , result .isFdv1Fallback ());
1075+
1076+ synchronizer .close ();
1077+ }
1078+ }
1079+
10041080}
0 commit comments