@@ -476,6 +476,64 @@ public void watchIsLeftOpenIfNotRespondedImmediately() {
476476 assertThatWatchIsOpenWithNoResponses (new WatchAndTracker (watch , responseTracker ));
477477 }
478478
479+ @ Test
480+ public void watchIsLeftOpenIfNotRespondedImmediatelyAndThroughSubsequentSetEmptySnapshots () {
481+ SimpleCache <String > cache = new SimpleCache <>(new SingleNodeGroup ());
482+ cache .setSnapshot (SingleNodeGroup .GROUP , Snapshot .create (
483+ ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), VERSION1 ));
484+
485+ ResponseTracker responseTracker = new ResponseTracker ();
486+ Watch watch = cache .createWatch (
487+ true ,
488+ XdsRequest .create (DiscoveryRequest .newBuilder ()
489+ .setNode (Node .getDefaultInstance ())
490+ .setTypeUrl (ROUTE_TYPE_URL )
491+ .addAllResourceNames (Collections .singleton (ROUTE_NAME ))
492+ .build ()),
493+ Collections .singleton (ROUTE_NAME ),
494+ responseTracker );
495+
496+ assertThatWatchIsOpenWithNoResponses (new WatchAndTracker (watch , responseTracker ));
497+ assertThat (cache .statusInfo (SingleNodeGroup .GROUP ).numWatches ()).isEqualTo (1 );
498+
499+ cache .setSnapshot (SingleNodeGroup .GROUP , Snapshot .create (
500+ ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), VERSION2 ));
501+
502+ assertThatWatchIsOpenWithNoResponses (new WatchAndTracker (watch , responseTracker ));
503+ assertThat (cache .statusInfo (SingleNodeGroup .GROUP ).numWatches ()).isEqualTo (1 );
504+ }
505+
506+ @ Test
507+ public void watchIsLeftOpenIfNotRespondedImmediatelyAndLaterSetSnapshotSendsUpdate () {
508+ SimpleCache <String > cache = new SimpleCache <>(new SingleNodeGroup ());
509+ cache .setSnapshot (SingleNodeGroup .GROUP , Snapshot .create (
510+ ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), VERSION1 ));
511+
512+ ResponseTracker responseTracker = new ResponseTracker ();
513+ Watch watch = cache .createWatch (
514+ true ,
515+ XdsRequest .create (DiscoveryRequest .newBuilder ()
516+ .setNode (Node .getDefaultInstance ())
517+ .setTypeUrl (ROUTE_TYPE_URL )
518+ .addAllResourceNames (SNAPSHOT1 .resources (ROUTE_TYPE_URL ).keySet ())
519+ .build ()),
520+ Collections .emptySet (),
521+ responseTracker );
522+
523+ assertThatWatchIsOpenWithNoResponses (new WatchAndTracker (watch , responseTracker ));
524+ assertThat (cache .statusInfo (SingleNodeGroup .GROUP ).numWatches ()).isEqualTo (1 );
525+
526+ cache .setSnapshot (SingleNodeGroup .GROUP , Snapshot .create (
527+ ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), ImmutableList .of (), VERSION2 ));
528+
529+ assertThatWatchIsOpenWithNoResponses (new WatchAndTracker (watch , responseTracker ));
530+ assertThat (cache .statusInfo (SingleNodeGroup .GROUP ).numWatches ()).isEqualTo (1 );
531+
532+ cache .setSnapshot (SingleNodeGroup .GROUP , SNAPSHOT1 );
533+
534+ assertThatWatchReceivesSnapshot (new WatchAndTracker (watch , responseTracker ), SNAPSHOT1 );
535+ }
536+
479537 @ Test
480538 public void getSnapshot () {
481539 SimpleCache <String > cache = new SimpleCache <>(new SingleNodeGroup ());
0 commit comments