use of io.airlift.configuration.ConfigurationFactory 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.ConfigurationFactory 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(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.ConfigurationFactory 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();
}
use of io.airlift.configuration.ConfigurationFactory 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());
}
use of io.airlift.configuration.ConfigurationFactory 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")));
}
Aggregations