Search in sources :

Example 1 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule in project airlift by airlift.

the class TestNodeModule method testDefaultConfig.

@Test
public void testDefaultConfig() throws UnknownHostException {
    long testStartTime = System.currentTimeMillis();
    ConfigurationFactory configFactory = new ConfigurationFactory(ImmutableMap.<String, String>of("node.environment", "environment"));
    Injector injector = Guice.createInjector(new NodeModule(), new ConfigurationModule(configFactory));
    NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
    assertNotNull(nodeInfo);
    assertEquals(nodeInfo.getEnvironment(), "environment");
    assertEquals(nodeInfo.getPool(), "general");
    assertNotNull(nodeInfo.getNodeId());
    assertNotNull(nodeInfo.getLocation());
    assertNull(nodeInfo.getBinarySpec());
    assertNull(nodeInfo.getConfigSpec());
    assertNotNull(nodeInfo.getInstanceId());
    assertNotEquals(nodeInfo.getNodeId(), nodeInfo.getInstanceId());
    assertNotNull(nodeInfo.getInternalAddress());
    assertFalse(InetAddress.getByName(nodeInfo.getInternalAddress()).isAnyLocalAddress());
    assertNotNull(nodeInfo.getBindIp());
    assertTrue(nodeInfo.getBindIp().isAnyLocalAddress());
    assertGreaterThanOrEqual(nodeInfo.getStartTime(), testStartTime);
    // make sure toString doesn't throw an exception
    assertNotNull(nodeInfo.toString());
}
Also used : Injector(com.google.inject.Injector) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Test(org.testng.annotations.Test)

Example 2 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule in project airlift by airlift.

the class TestH2EmbeddedDataSourceModule method createInjector.

private static Injector createInjector(Map<String, String> properties, Module... modules) {
    ConfigurationFactory configurationFactory = new ConfigurationFactory(properties);
    // Required to bind a configuration module and an MBean server when binding an H2EmbeddedDataSourceModule
    List<Module> moduleList = ImmutableList.<Module>builder().add(modules).add(new ConfigurationModule(configurationFactory)).add(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(MBeanServer.class).to(TestingMBeanServer.class).in(Scopes.SINGLETON);
            binder.bind(ObjectHolder.class);
        }
    }).build();
    return Guice.createInjector(moduleList);
}
Also used : Binder(com.google.inject.Binder) TestingMBeanServer(org.weakref.jmx.testing.TestingMBeanServer) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) Module(com.google.inject.Module) ConfigurationModule(io.airlift.configuration.ConfigurationModule) ConfigurationModule(io.airlift.configuration.ConfigurationModule)

Example 3 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule in project airlift by airlift.

the class AbstractTestDiscoveryModule method testMerging.

@Test
public void testMerging() throws Exception {
    final StaticAnnouncementHttpServerInfoImpl httpServerInfo = new StaticAnnouncementHttpServerInfoImpl(URI.create("http://127.0.0.1:4444"), URI.create("http://example.com:4444"), null, null);
    Map<String, String> config = ImmutableMap.<String, String>builder().put("discovery.uri", "fake://server").put("discovery.carrot.pool", "test").build();
    Injector injector = Guice.createInjector(new ConfigurationModule(new ConfigurationFactory(config)), new JsonModule(), new TestingNodeModule(), new DiscoveryModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(AnnouncementHttpServerInfo.class).toInstance(httpServerInfo);
            discoveryBinder(binder).bindHttpAnnouncement("apple");
            discoveryBinder(binder).bindHttpAnnouncement("banana");
            discoveryBinder(binder).bindHttpAnnouncement("carrot");
            discoveryBinder(binder).bindHttpSelector("apple");
            discoveryBinder(binder).bindHttpSelector("banana");
            discoveryBinder(binder).bindHttpSelector("carrot");
            discoveryBinder(binder).bindHttpSelector("grape");
        }
    });
    HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
    assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
    selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("banana")));
    assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
    selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("carrot")));
    assertTrue(selector.selectHttpService().isEmpty());
    selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("grape")));
    assertTrue(selector.selectHttpService().isEmpty());
}
Also used : TestingNodeModule(io.airlift.node.testing.TestingNodeModule) JsonModule(io.airlift.json.JsonModule) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Binder(com.google.inject.Binder) DiscoveryBinder.discoveryBinder(io.airlift.discovery.client.DiscoveryBinder.discoveryBinder) Injector(com.google.inject.Injector) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) Module(com.google.inject.Module) ConfigurationModule(io.airlift.configuration.ConfigurationModule) JsonModule(io.airlift.json.JsonModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) Test(org.testng.annotations.Test)

Example 4 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule in project airlift by airlift.

the class AbstractTestDiscoveryModule method testBinding.

@Test
public void testBinding() throws Exception {
    Injector injector = Guice.createInjector(new ConfigurationModule(new ConfigurationFactory(ImmutableMap.of("discovery.uri", "fake://server"))), new JsonModule(), new TestingNodeModule(), discoveryModule);
    // should produce a discovery announcement client and a lookup client
    assertNotNull(injector.getInstance(DiscoveryAnnouncementClient.class));
    assertNotNull(injector.getInstance(DiscoveryLookupClient.class));
    // should produce an Announcer
    assertNotNull(injector.getInstance(Announcer.class));
    // should produce a ServiceSelectorManager
    assertNotNull(injector.getInstance(ServiceSelectorManager.class));
}
Also used : Injector(com.google.inject.Injector) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) JsonModule(io.airlift.json.JsonModule) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Test(org.testng.annotations.Test)

Example 5 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule 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(), new Module() {

        @Override
        public void configure(Binder 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 : Binder(com.google.inject.Binder) DiscoveryBinder.discoveryBinder(io.airlift.discovery.client.DiscoveryBinder.discoveryBinder) TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) Injector(com.google.inject.Injector) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) ConfigurationFactory(io.airlift.configuration.ConfigurationFactory) Module(com.google.inject.Module) ConfigurationModule(io.airlift.configuration.ConfigurationModule) TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) ConfigurationModule(io.airlift.configuration.ConfigurationModule) Test(org.testng.annotations.Test)

Aggregations

ConfigurationFactory (io.airlift.configuration.ConfigurationFactory)16 ConfigurationModule (io.airlift.configuration.ConfigurationModule)16 Injector (com.google.inject.Injector)15 Test (org.testng.annotations.Test)14 Binder (com.google.inject.Binder)13 Module (com.google.inject.Module)13 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)12 DiscoveryBinder.discoveryBinder (io.airlift.discovery.client.DiscoveryBinder.discoveryBinder)7 InMemoryDiscoveryClient (io.airlift.discovery.client.testing.InMemoryDiscoveryClient)6 TestingDiscoveryModule (io.airlift.discovery.client.testing.TestingDiscoveryModule)6 EventModule (io.airlift.event.client.EventModule)4 InMemoryEventModule (io.airlift.event.client.InMemoryEventModule)4 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)4 HttpServerBinder.httpServerBinder (io.airlift.http.server.HttpServerBinder.httpServerBinder)4 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)4 File (java.io.File)4 Servlet (javax.servlet.Servlet)3 HttpServlet (javax.servlet.http.HttpServlet)3 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)2 JsonModule (io.airlift.json.JsonModule)2