Search in sources :

Example 1 with NodeConfig

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);
}
Also used : NodeInfo(io.airlift.node.NodeInfo) NodeConfig(io.airlift.node.NodeConfig) Test(org.testng.annotations.Test)

Example 2 with NodeConfig

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));
}
Also used : NodeInfo(io.airlift.node.NodeInfo) InMemoryDiscoveryClient(io.airlift.discovery.client.testing.InMemoryDiscoveryClient) NodeConfig(io.airlift.node.NodeConfig) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with NodeConfig

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();
}
Also used : NodeInfo(io.airlift.node.NodeInfo) NodeConfig(io.airlift.node.NodeConfig)

Example 4 with NodeConfig

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();
}
Also used : NodeInfo(io.airlift.node.NodeInfo) TempFile(io.airlift.testing.TempFile) File(java.io.File) NodeConfig(io.airlift.node.NodeConfig) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with NodeConfig

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));
            }
        }
    }
}
Also used : Closer(com.google.common.io.Closer) HttpClientConfig(io.airlift.http.client.HttpClientConfig) NullEventClient(io.airlift.event.client.NullEventClient) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TraceTokenManager(io.airlift.tracetoken.TraceTokenManager) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeInfo(io.airlift.node.NodeInfo) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) NodeConfig(io.airlift.node.NodeConfig) Test(org.testng.annotations.Test)

Aggregations

NodeConfig (io.airlift.node.NodeConfig)6 NodeInfo (io.airlift.node.NodeInfo)6 Test (org.testng.annotations.Test)3 BeforeMethod (org.testng.annotations.BeforeMethod)2 Closer (com.google.common.io.Closer)1 InMemoryDiscoveryClient (io.airlift.discovery.client.testing.InMemoryDiscoveryClient)1 NullEventClient (io.airlift.event.client.NullEventClient)1 HttpClientConfig (io.airlift.http.client.HttpClientConfig)1 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)1 TempFile (io.airlift.testing.TempFile)1 TraceTokenManager (io.airlift.tracetoken.TraceTokenManager)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1