use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.
the class TestCachingServiceSelector method testNotStartedEmpty.
@Test
public void testNotStartedEmpty() {
CachingServiceSelector serviceSelector = new CachingServiceSelector("type", new ServiceSelectorConfig().setPool("pool"), new InMemoryDiscoveryClient(nodeInfo), executor);
assertEquals(serviceSelector.selectAllServices(), ImmutableList.of());
}
use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.
the class TestCachingServiceSelector method testBasics.
@Test
public void testBasics() {
CachingServiceSelector serviceSelector = new CachingServiceSelector("type", new ServiceSelectorConfig().setPool("pool"), new InMemoryDiscoveryClient(nodeInfo), executor);
assertEquals(serviceSelector.getType(), "type");
assertEquals(serviceSelector.getPool(), "pool");
}
use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.
the class TestHttpServiceSelectorBinder method testHttpSelectorAnnotation.
@Test
public void testHttpSelectorAnnotation() {
Injector injector = Guice.createInjector(new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector(serviceType("apple")));
InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class);
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build()));
HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http"));
ServiceSelectorManager manager = injector.getInstance(ServiceSelectorManager.class);
assertEquals(manager.getServiceSelectors().size(), 1);
manager.attemptRefresh();
manager.forceRefresh();
}
use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.
the class TestHttpServiceSelectorBinder method testInvalidUris.
@Test
public void testInvalidUris() {
Injector injector = Guice.createInjector(new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple"));
InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class);
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", ":::INVALID:::").build()));
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", ":::INVALID:::").build()));
HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(selector.selectHttpService(), ImmutableList.of());
}
use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.
the class TestHttpServiceSelectorBinder method testFavorHttpsOverHttpSelector.
@Test
public void testFavorHttpsOverHttpSelector() {
Injector injector = Guice.createInjector(new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple"));
InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class);
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build(), serviceAnnouncement("apple").addProperty("https", "fake://server-https").build()));
HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(selector.selectHttpService(), ImmutableList.of(URI.create("fake://server-https"), URI.create("fake://server-http")));
}
Aggregations