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());
}
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);
}
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());
}
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));
}
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());
}
Aggregations