Search in sources :

Example 11 with InMemoryDiscoveryClient

use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.

the class TestHttpServiceSelectorBinder method testHttpSelectorString.

@Test
public void testHttpSelectorString() {
    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()));
    HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
    assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http"));
}
Also used : TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) Injector(com.google.inject.Injector) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Test(org.testng.annotations.Test)

Example 12 with InMemoryDiscoveryClient

use of io.airlift.discovery.client.testing.InMemoryDiscoveryClient in project airlift by airlift.

the class TestHttpServiceSelectorBinder method testNoHttpServices.

@Test
public void testNoHttpServices() {
    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("foo", "fake://server-https").build()));
    HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
    assertEquals(selector.selectHttpService(), ImmutableList.of());
}
Also used : TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) Injector(com.google.inject.Injector) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Test(org.testng.annotations.Test)

Aggregations

InMemoryDiscoveryClient (io.airlift.discovery.client.testing.InMemoryDiscoveryClient)12 Test (org.testng.annotations.Test)11 Injector (com.google.inject.Injector)6 ConfigurationFactory (io.airlift.configuration.ConfigurationFactory)6 ConfigurationModule (io.airlift.configuration.ConfigurationModule)6 TestingDiscoveryModule (io.airlift.discovery.client.testing.TestingDiscoveryModule)6 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)6 NodeConfig (io.airlift.node.NodeConfig)1 NodeInfo (io.airlift.node.NodeInfo)1 BeforeMethod (org.testng.annotations.BeforeMethod)1