Search in sources :

Example 1 with InMemoryDiscoveryClient

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());
}
Also used : InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) Test(org.testng.annotations.Test)

Example 2 with InMemoryDiscoveryClient

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");
}
Also used : InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) Test(org.testng.annotations.Test)

Example 3 with InMemoryDiscoveryClient

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();
}
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 4 with InMemoryDiscoveryClient

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());
}
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 5 with InMemoryDiscoveryClient

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")));
}
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