Source:
public void testRegistryEvictionSubscribe() throws Exception { InterestChannelImpl channel1 = mock(InterestChannelImpl.class); InterestChannelImpl channel2 = mock(InterestChannelImpl.class); when(channel1.getSource()).thenReturn(new Source(Source.Origin.INTERESTED)); when(channel2.getSource()).thenReturn(new Source(Source.Origin.INTERESTED)); ReplaySubject<ChangeNotification<InstanceInfo>> channel1BatchSubject = ReplaySubject.create(); ReplaySubject<ChangeNotification<InstanceInfo>> channel2BatchSubject = ReplaySubject.create(); when(channel1.getChangeNotificationStream()).thenReturn(channel1BatchSubject); when(channel2.getChangeNotificationStream()).thenReturn(channel2BatchSubject); final ReplaySubject<Void> channel1Lifecycle = ReplaySubject.create(); ReplaySubject<Void> channel2Lifecycle = ReplaySubject.create(); when(channel1.asLifecycleObservable()).thenReturn(channel1Lifecycle); when(channel2.asLifecycleObservable()).thenReturn(channel2Lifecycle); client.registryEvictionSubscribe(retryableConnection); channelSubject.onNext(channel1); channel1BatchSubject.onNext(newBufferStart()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channel1BatchSubject.onNext(newBufferEnd()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channelSubject.onNext(channel2); channel1Lifecycle.onError(new Exception("test error")); channel2BatchSubject.onNext(newBufferStart()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channel2BatchSubject.onNext(newBufferEnd()); verify(registry, times(1)).evictAll(any(Source.SourceMatcher.class)); Thread.sleep(1000); }

Target:
public void testRegistryEvictionSubscribe() throws Exception { InterestChannelImpl channel1 = mock(InterestChannelImpl.class); InterestChannelImpl channel2 = mock(InterestChannelImpl.class); when(channel1.getSource()).thenReturn(new Source(Source.Origin.INTERESTED)); when(channel2.getSource()).thenReturn(new Source(Source.Origin.INTERESTED)); ReplaySubject<ChangeNotification<InstanceInfo>> channel1BatchSubject = ReplaySubject.create(); ReplaySubject<ChangeNotification<InstanceInfo>> channel2BatchSubject = ReplaySubject.create(); when(channel1.getChangeNotificationStream()).thenReturn(channel1BatchSubject); when(channel2.getChangeNotificationStream()).thenReturn(channel2BatchSubject); final ReplaySubject<Void> channel1Lifecycle = ReplaySubject.create(); ReplaySubject<Void> channel2Lifecycle = ReplaySubject.create(); when(channel1.asLifecycleObservable()).thenReturn(channel1Lifecycle); when(channel2.asLifecycleObservable()).thenReturn(channel2Lifecycle); client.registryEvictionSubscribe(retryableConnection); channelSubject.onNext(channel1); channel1BatchSubject.onNext(newBufferStart()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channel1BatchSubject.onNext(newBufferEnd()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channelSubject.onNext(channel2); channel1Lifecycle.onError(new Exception("test error")); channel2BatchSubject.onNext(newBufferStart()); verify(registry, never()).evictAll(any(Source.SourceMatcher.class)); channel2BatchSubject.onNext(newBufferEnd()); verify(registry, times(1)).evictAll(any(Source.SourceMatcher.class)); }