Search in sources :

Example 11 with ConfigurationModule

use of io.airlift.configuration.ConfigurationModule 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)

Example 12 with ConfigurationModule

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

the class TestNodeModule method testFullConfig.

@Test
public void testFullConfig() {
    long testStartTime = System.currentTimeMillis();
    String environment = "environment";
    String pool = "pool";
    String nodeId = "nodeId";
    String location = "location";
    String binarySpec = "binary";
    String configSpec = "config";
    String publicAddress = "public";
    ConfigurationFactory configFactory = new ConfigurationFactory(ImmutableMap.<String, String>builder().put("node.environment", environment).put("node.pool", pool).put("node.id", nodeId).put("node.internal-address", publicAddress).put("node.location", location).put("node.binary-spec", binarySpec).put("node.config-spec", configSpec).build());
    Injector injector = Guice.createInjector(new NodeModule(), new ConfigurationModule(configFactory));
    NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
    assertNotNull(nodeInfo);
    assertEquals(nodeInfo.getEnvironment(), environment);
    assertEquals(nodeInfo.getPool(), pool);
    assertEquals(nodeInfo.getNodeId(), nodeId);
    assertEquals(nodeInfo.getLocation(), location);
    assertEquals(nodeInfo.getBinarySpec(), binarySpec);
    assertEquals(nodeInfo.getConfigSpec(), configSpec);
    assertNotNull(nodeInfo.getInstanceId());
    assertNotEquals(nodeInfo.getNodeId(), nodeInfo.getInstanceId());
    assertEquals(nodeInfo.getInternalAddress(), publicAddress);
    assertEquals(nodeInfo.getBindIp(), InetAddresses.forString("0.0.0.0"));
    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)

Aggregations

Injector (com.google.inject.Injector)12 ConfigurationFactory (io.airlift.configuration.ConfigurationFactory)12 ConfigurationModule (io.airlift.configuration.ConfigurationModule)12 Test (org.testng.annotations.Test)11 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)8 InMemoryDiscoveryClient (io.airlift.discovery.client.testing.InMemoryDiscoveryClient)6 TestingDiscoveryModule (io.airlift.discovery.client.testing.TestingDiscoveryModule)6 ImmutableList (com.google.common.collect.ImmutableList)2 Guice (com.google.inject.Guice)2 Module (com.google.inject.Module)2 JsonModule (io.airlift.json.JsonModule)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Builder (com.google.common.collect.ImmutableList.Builder)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Binder (com.google.inject.Binder)1 BindingAnnotation (com.google.inject.BindingAnnotation)1