CacheDistributionAdvisor extends DistributionAdvisor { Set<InternalDistributedMember> adviseAllEventsOrCached() throws IllegalStateException { getAdvisee().getCancelCriterion().checkCancelInProgress(null); long tempProfilesVersion = profilesVersion; long tempInRecoveryVersion = inRecoveryVersion; if (adviseAllEventsVersion != tempProfilesVersion || adviseInRecoveryVersion != tempInRecoveryVersion) { synchronized (adviseSetforAllEvents) { if (adviseAllEventsVersion != tempProfilesVersion || adviseInRecoveryVersion != tempInRecoveryVersion) { adviseSetforAllEvents = Collections.unmodifiableSet(adviseFilter(profile -> { CacheProfile cp = (CacheProfile) profile; if (cp.getInRecovery()) { return false; } return cp.cachedOrAllEventsWithListener(); })); adviseAllEventsVersion = tempProfilesVersion; adviseInRecoveryVersion = tempInRecoveryVersion; } } } return adviseSetforAllEvents; } protected  CacheDistributionAdvisor(CacheDistributionAdvisee region); synchronized void incInRecoveryVersion(); @Override String toString(); Set adviseNetLoad(); FilterRoutingInfo adviseFilterRouting(CacheEvent event, Set cacheOpRecipients); Set<InternalDistributedMember> adviseCacheOp(); Set adviseDestroyRegion(); Set adviseNetWrite(); Set<InternalDistributedMember> adviseInitializedReplicates(); InitialImageAdvice adviseInitialImage(InitialImageAdvice previousAdvice); @SuppressWarnings("synthetic-access") InitialImageAdvice adviseInitialImage(InitialImageAdvice previousAdvice,
      boolean persistent); Set<InternalDistributedMember> adviseReplicates(); Set advisePreloadeds(); Map<InternalDistributedMember, PersistentMemberID> advisePersistentMembers(); Map<InternalDistributedMember, PersistentMemberID> adviseInitializedPersistentMembers(); void addMembershipAndProxyListener(MembershipListener listener); void removeMembershipAndProxyListener(MembershipListener listener); @Override boolean removeId(ProfileId memberId, boolean crashed, boolean destroyed,
      boolean fromMembershipListener);  }
@Test public void testAdviseAllEventsOrCached() { CacheProfile profile = mock(CacheProfile.class); InternalDistributedMember member = mock(InternalDistributedMember.class); when(profile.getId()).thenReturn(member); when(profile.getInRecovery()).thenReturn(false); when(profile.cachedOrAllEventsWithListener()).thenReturn(true); when(profile.getDistributedMember()).thenReturn(member); advisor.putProfile(profile, true); Set<InternalDistributedMember> targets1 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); Set<InternalDistributedMember> targets2 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); Set<InternalDistributedMember> targets3 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); verify(profile, times(1)).getInRecovery(); verify(profile, times(1)).cachedOrAllEventsWithListener(); }
@Test public void testAdviseAllEventsOrCached2() { CacheProfile profile = mock(CacheProfile.class); InternalDistributedMember member = mock(InternalDistributedMember.class); when(profile.getId()).thenReturn(member); when(profile.getInRecovery()).thenReturn(false); when(profile.cachedOrAllEventsWithListener()).thenReturn(true); when(profile.getDistributedMember()).thenReturn(member); CacheProfile profile2 = mock(CacheProfile.class); InternalDistributedMember member2 = mock(InternalDistributedMember.class); when(profile2.getId()).thenReturn(member2); when(profile2.getInRecovery()).thenReturn(false); when(profile2.cachedOrAllEventsWithListener()).thenReturn(true); when(profile2.getDistributedMember()).thenReturn(member2); advisor.putProfile(profile, true); Set<InternalDistributedMember> targets1 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); advisor.putProfile(profile2, true); Set<InternalDistributedMember> targets2 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); Set<InternalDistributedMember> targets3 = ((CacheDistributionAdvisor) advisor).adviseAllEventsOrCached(); verify(profile, times(2)).getInRecovery(); verify(profile, times(2)).cachedOrAllEventsWithListener(); verify(profile2, times(1)).getInRecovery(); verify(profile2, times(1)).cachedOrAllEventsWithListener(); }