@@ -468,6 +468,50 @@ public void server_errors_should_incrementally_increase_interval()
468468 assertThat (featureRepository .getFailures ()).isEqualTo (0 );
469469 }
470470
471+ @ Test
472+ public void should_write_backup_file_when_streaming_update_received () throws Exception {
473+ UnleashConfig streamingConfig =
474+ UnleashConfig .builder ()
475+ .appName ("streaming-test" )
476+ .unleashAPI ("http://localhost:4242/api/" )
477+ .scheduledExecutor (mock (UnleashScheduledExecutor .class ))
478+ .disableMetrics ()
479+ .disablePolling ()
480+ .experimentalStreamingMode ()
481+ .build ();
482+
483+ when (backupHandler .read ()).thenReturn (Optional .empty ());
484+
485+ FeatureRepositoryImpl repository =
486+ new FeatureRepositoryImpl (
487+ streamingConfig ,
488+ backupHandler ,
489+ new UnleashEngine (),
490+ fetcher ,
491+ streamingFetcher ,
492+ bootstrapHandler );
493+
494+ String streamingData =
495+ "{\" events\" :[{\" type\" :\" hydration\" ,\" eventId\" :1,\" features\" :[{\" name\" :\" testFeature\" ,\" enabled\" :true,\" strategies\" :[],\" variants\" :[]}],\" segments\" :[]}]}" ;
496+
497+ repository .handleStreamingUpdate (streamingData );
498+
499+ ArgumentCaptor <String > backupContentCaptor = ArgumentCaptor .forClass (String .class );
500+ verify (backupHandler , times (1 )).write (backupContentCaptor .capture ());
501+
502+ String savedBackupContent = backupContentCaptor .getValue ();
503+
504+ assertThat (savedBackupContent ).contains ("\" features\" " );
505+ assertThat (savedBackupContent ).contains ("\" segments\" " );
506+
507+ assertThat (savedBackupContent ).contains ("\" testFeature\" " );
508+
509+ assertThat (savedBackupContent ).contains ("\" version\" :2" );
510+ assertThat (savedBackupContent ).contains ("\" query\" :" );
511+
512+ assertThat (savedBackupContent ).doesNotContain ("\" events\" " ); // store state not events
513+ }
514+
471515 private class TestRunner {
472516
473517 private final UnleashScheduledExecutor executor ;
0 commit comments