CachingServiceSelector implements ServiceSelector, ServiceDescriptorsListener { @Override public List<ServiceDescriptor> selectAllServices() { return this.serviceDescriptors.get(); } CachingServiceSelector(String type, ServiceSelectorConfig selectorConfig, NodeInfo nodeInfo); @Override String getType(); @Override String getPool(); @Override List<ServiceDescriptor> selectAllServices(); @Override void updateServiceDescriptors(Iterable<ServiceDescriptor> newDescriptors);  }
@Test public void testNotStartedEmpty() { assertEquals(serviceSelector.selectAllServices(), ImmutableList.of()); }
@Test public void testStartedEmpty() { updater.start(); assertEquals(serviceSelector.selectAllServices(), ImmutableList.of()); }
@Test public void testNotStartedWithServices() { discoveryClient.addDiscoveredService(APPLE_1_SERVICE); discoveryClient.addDiscoveredService(APPLE_2_SERVICE); discoveryClient.addDiscoveredService(DIFFERENT_TYPE); discoveryClient.addDiscoveredService(DIFFERENT_POOL); assertEquals(serviceSelector.selectAllServices(), ImmutableList.of()); }
@Test public void testStartedWithServices() throws Exception { discoveryClient.addDiscoveredService(APPLE_1_SERVICE); discoveryClient.addDiscoveredService(APPLE_2_SERVICE); discoveryClient.addDiscoveredService(DIFFERENT_TYPE); discoveryClient.addDiscoveredService(DIFFERENT_POOL); updater.start(); Thread.sleep(100); assertEqualsIgnoreOrder(serviceSelector.selectAllServices(), ImmutableList.of(APPLE_1_SERVICE, APPLE_2_SERVICE)); }
@Test public void testServiceUpdaterDefaultToNodePool() throws Exception { discoveryClient.addDiscoveredService(APPLE_1_SERVICE); discoveryClient.addDiscoveredService(APPLE_2_SERVICE); discoveryClient.addDiscoveredService(DIFFERENT_TYPE); discoveryClient.addDiscoveredService(DIFFERENT_POOL); updater = new ServiceDescriptorsUpdater(serviceSelector, "apple", new ServiceSelectorConfig(), new NodeInfo("test-application", new NodeConfig().setEnvironment("environment").setPool("pool")), discoveryClient, executor); updater.start(); Thread.sleep(100); assertEqualsIgnoreOrder(serviceSelector.selectAllServices(), ImmutableList.of(APPLE_1_SERVICE, APPLE_2_SERVICE)); }