@Test public void testAddRemoveInstances() { InstanceInfo i1 = createInstance(1); InstanceInfo i2 = createInstance(2); InstanceInfo i3 = createInstance(3); InstanceInfo i4 = createInstance(4); Mockito.when(client.getApplication("foo")).thenReturn(application); AtomicReference<List<InstanceInfo>> result = new AtomicReference<List<InstanceInfo>>(); TestScheduler scheduler = new TestScheduler(); EurekaInterestManager eureka = new EurekaInterestManager(client); eureka.newInterest() .forApplication("foo") .withRefreshInterval(1, TimeUnit.SECONDS) .withScheduler(scheduler) .asObservable() .compose(InstanceCollector.<InstanceInfo>create()) .subscribe(RxUtil.set(result)); Mockito.when(application.getInstances()).thenReturn(Arrays.asList(i1, i2)); scheduler.advanceTimeBy(10, TimeUnit.SECONDS); Assert.assertEquals(Sets.newHashSet(i2, i1), Sets.newHashSet(result.get())); Mockito.when(application.getInstances()).thenReturn(Arrays.asList(i1, i2, i3)); scheduler.advanceTimeBy(10, TimeUnit.SECONDS); Assert.assertEquals(Sets.newHashSet(i3, i2, i1), Sets.newHashSet(result.get())); Mockito.when(application.getInstances()).thenReturn(Arrays.asList(i3, i4)); scheduler.advanceTimeBy(10, TimeUnit.SECONDS); Assert.assertEquals(Sets.newHashSet(i3, i4), Sets.newHashSet(result.get())); Mockito.when(application.getInstances()).thenReturn(Arrays.<InstanceInfo>asList()); scheduler.advanceTimeBy(10, TimeUnit.SECONDS); Assert.assertEquals(Sets.newHashSet(), Sets.newHashSet(result.get())); }
public InterestDsl newInterest() { return new InterestDsl(client); }
EurekaInterestManager { public InterestDsl newInterest() { return new InterestDsl(client); } }
EurekaInterestManager { public InterestDsl newInterest() { return new InterestDsl(client); } @Inject  EurekaInterestManager(DiscoveryClient client); }
EurekaInterestManager { public InterestDsl newInterest() { return new InterestDsl(client); } @Inject  EurekaInterestManager(DiscoveryClient client); InterestDsl newInterest(); }
EurekaInterestManager { public InterestDsl newInterest() { return new InterestDsl(client); } @Inject  EurekaInterestManager(DiscoveryClient client); InterestDsl newInterest();  }