use of io.airlift.node.NodeConfig in project airlift by airlift.
the class TestServiceDescriptor method testBuilderNodeInfo.
@Test
public void testBuilderNodeInfo() {
NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool"));
ServiceDescriptor expected = new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), nodeInfo.getNodeId(), "type", nodeInfo.getPool(), "location", ServiceState.STOPPED, ImmutableMap.of("a", "apple", "b", "banana"));
ServiceDescriptor actual = serviceDescriptor(expected.getType()).setId(expected.getId()).setLocation(expected.getLocation()).setNodeInfo(nodeInfo).setState(expected.getState()).addProperties(expected.getProperties()).build();
assertDescriptorEquals(expected, actual);
}
use of io.airlift.node.NodeConfig in project airlift by airlift.
the class TestAnnouncer method setUp.
@BeforeMethod
protected void setUp() throws Exception {
nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool"));
discoveryClient = new InMemoryDiscoveryClient(nodeInfo, MAX_AGE);
serviceAnnouncement = ServiceAnnouncement.serviceAnnouncement(serviceType.value()).addProperty("a", "apple").build();
announcer = new Announcer(discoveryClient, ImmutableSet.of(serviceAnnouncement));
}
use of io.airlift.node.NodeConfig in project airlift by airlift.
the class TestingNodeModule method configure.
@Override
public void configure(Binder binder) {
binder.bind(NodeInfo.class).in(Scopes.SINGLETON);
NodeConfig nodeConfig = new NodeConfig().setEnvironment(environment).setNodeInternalAddress(InetAddresses.toAddrString(getV4Localhost())).setNodeBindIp(getV4Localhost());
if (pool.isPresent()) {
nodeConfig.setPool(pool.get());
}
binder.bind(NodeConfig.class).toInstance(nodeConfig);
newExporter(binder).export(NodeInfo.class).withGeneratedName();
}
use of io.airlift.node.NodeConfig in project airlift by airlift.
the class TestHttpServerProvider method setup.
@BeforeMethod
public void setup() throws IOException {
tempDir = createTempDirectory(getClass().getSimpleName()).toFile();
config = new HttpServerConfig().setHttpPort(0).setLogPath(new File(tempDir, "http-request.log").getAbsolutePath());
httpsConfig = new HttpsConfig().setHttpsPort(0);
clientCertificate = ClientCertificate.NONE;
nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setNodeInternalAddress("localhost"));
httpServerInfo = createHttpServerInfo();
}
use of io.airlift.node.NodeConfig in project airlift by airlift.
the class TestJettyMultipleCerts method test.
@Test
public void test() throws Exception {
HttpServlet servlet = new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setStatus(200);
response.getOutputStream().write((request.getServerName() + " OK").getBytes(UTF_8));
}
};
HttpServerConfig config = new HttpServerConfig().setLogEnabled(false).setHttpEnabled(false).setHttpPort(0).setHttpsEnabled(true);
HttpsConfig httpsConfig = new HttpsConfig().setHttpsPort(0).setKeystorePath(getResource("multiple-certs/server.p12").getPath()).setKeystorePassword("airlift");
HashLoginServiceProvider loginServiceProvider = new HashLoginServiceProvider(config);
NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setNodeInternalAddress("localhost"));
HttpServerInfo httpServerInfo = new HttpServerInfo(config, Optional.of(httpsConfig), nodeInfo);
HttpServerProvider serverProvider = new HttpServerProvider(httpServerInfo, nodeInfo, config, Optional.of(httpsConfig), servlet, ImmutableSet.of(new DummyFilter()), ImmutableSet.of(), ImmutableSet.of(), ClientCertificate.NONE, new RequestStats(), new NullEventClient(), Optional.empty());
serverProvider.setTheAdminServlet(new DummyServlet());
serverProvider.setLoginService(loginServiceProvider.get());
serverProvider.setTokenManager(new TraceTokenManager());
try (Closer closer = Closer.create()) {
HttpServer server = serverProvider.get();
closer.register(() -> {
try {
server.stop();
} catch (Exception ignore) {
}
});
server.start();
JettyHttpClient client = new JettyHttpClient(new HttpClientConfig().setTrustStorePath(getResource("multiple-certs/server.p12").getPath()).setTrustStorePassword("airlift"));
closer.register(client);
int httpsPort = httpServerInfo.getHttpsUri().getPort();
tryHost(client, HostAndPort.fromParts("localhost", httpsPort));
for (String name : List.of("127.0.0.1", "::1")) {
assertThatThrownBy(() -> tryHost(client, HostAndPort.fromParts(name, httpsPort))).hasMessageStartingWith(name + " Failed communicating with server").hasRootCauseMessage("No subject alternative names present");
}
//
for (String name : List.of("single1", "single2", "single3", "single4")) {
if (doesDomainResolveToLocalhost(name)) {
tryHost(client, HostAndPort.fromParts(name, httpsPort));
}
}
}
}
Aggregations