CacheDistributionAdvisor extends DistributionAdvisor { Set adviseUpdate(final EntryEventImpl event) throws IllegalStateException { if (event.hasNewValue() || event.getOperation().isPutAll()) { return adviseAllEventsOrCached(); } else { long tempProfilesVersion = profilesVersion; if (adviseUpdateVersion != tempProfilesVersion) { synchronized (adviseSetforUpdate) { if (adviseUpdateVersion != tempProfilesVersion) { adviseSetforUpdate = Collections.unmodifiableSet(adviseFilter(profile -> { CacheProfile cp = (CacheProfile) profile; DataPolicy dp = cp.getDataPolicy(); return dp.withReplication() || (cp.allEvents() && (dp.withStorage() || cp.hasCacheListener)); })); adviseUpdateVersion = tempProfilesVersion; } } } return adviseSetforUpdate; } } 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 testAdviseUpdate() { CacheProfile profile = mock(CacheProfile.class); InternalDistributedMember member = mock(InternalDistributedMember.class); EntryEventImpl event = mock(EntryEventImpl.class); when(event.hasNewValue()).thenReturn(false); when(event.getOperation()).thenReturn(Operation.CREATE); when(profile.getId()).thenReturn(member); when(profile.cachedOrAllEventsWithListener()).thenReturn(true); when(profile.getDistributedMember()).thenReturn(member); when(profile.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); advisor.putProfile(profile, true); Set<InternalDistributedMember> targets1 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); Set<InternalDistributedMember> targets2 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); Set<InternalDistributedMember> targets3 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); verify(profile, times(1)).getDataPolicy(); }
@Test public void testAdviseUpdate2() { CacheProfile profile = mock(CacheProfile.class); InternalDistributedMember member = mock(InternalDistributedMember.class); EntryEventImpl event = mock(EntryEventImpl.class); when(event.hasNewValue()).thenReturn(false); when(event.getOperation()).thenReturn(Operation.CREATE); when(profile.getId()).thenReturn(member); when(profile.cachedOrAllEventsWithListener()).thenReturn(true); when(profile.getDistributedMember()).thenReturn(member); when(profile.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); CacheProfile profile2 = mock(CacheProfile.class); InternalDistributedMember member2 = mock(InternalDistributedMember.class); when(profile2.getId()).thenReturn(member2); when(profile2.cachedOrAllEventsWithListener()).thenReturn(true); when(profile2.getDistributedMember()).thenReturn(member2); when(profile2.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); when(event.hasNewValue()).thenReturn(false); when(event.getOperation()).thenReturn(Operation.CREATE); advisor.putProfile(profile, true); Set<InternalDistributedMember> targets1 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); advisor.putProfile(profile2, true); Set<InternalDistributedMember> targets2 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); Set<InternalDistributedMember> targets3 = ((CacheDistributionAdvisor) advisor).adviseUpdate(event); verify(profile, times(2)).getDataPolicy(); verify(profile2, times(1)).getDataPolicy(); }