Search in sources :

Example 1 with TraceTokenManager

use of io.airlift.tracetoken.TraceTokenManager in project airlift by airlift.

the class TestHttpServerCipher method createServer.

private static HttpServer createServer(HttpServlet servlet, NodeInfo nodeInfo, HttpServerInfo httpServerInfo, HttpServerConfig config) {
    HashLoginServiceProvider loginServiceProvider = new HashLoginServiceProvider(config);
    HttpServerProvider serverProvider = new HttpServerProvider(httpServerInfo, nodeInfo, config, servlet, ImmutableSet.of(new DummyFilter()), ImmutableSet.of(), ImmutableSet.of(), new RequestStats(), new NullEventClient());
    serverProvider.setTheAdminServlet(new DummyServlet());
    serverProvider.setLoginService(loginServiceProvider.get());
    serverProvider.setTokenManager(new TraceTokenManager());
    return serverProvider.get();
}
Also used : NullEventClient(io.airlift.event.client.NullEventClient) TraceTokenManager(io.airlift.tracetoken.TraceTokenManager)

Example 2 with TraceTokenManager

use of io.airlift.tracetoken.TraceTokenManager in project airlift by airlift.

the class TestHttpServerProvider method createServer.

private void createServer(HttpServlet servlet) {
    HashLoginServiceProvider loginServiceProvider = new HashLoginServiceProvider(config);
    HttpServerProvider serverProvider = new HttpServerProvider(httpServerInfo, nodeInfo, config, optionalHttpsConfig(), servlet, ImmutableSet.of(new DummyFilter()), ImmutableSet.of(), ImmutableSet.of(), clientCertificate, new RequestStats(), new NullEventClient(), Optional.empty());
    serverProvider.setTheAdminServlet(new DummyServlet());
    serverProvider.setLoginService(loginServiceProvider.get());
    serverProvider.setTokenManager(new TraceTokenManager());
    server = serverProvider.get();
}
Also used : NullEventClient(io.airlift.event.client.NullEventClient) TraceTokenManager(io.airlift.tracetoken.TraceTokenManager)

Example 3 with TraceTokenManager

use of io.airlift.tracetoken.TraceTokenManager in project airlift by airlift.

the class TestDelimitedRequestLog method testTraceTokenHeader.

@Test
public void testTraceTokenHeader() throws Exception {
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    TraceTokenManager tokenManager = new TraceTokenManager();
    InMemoryEventClient eventClient = new InMemoryEventClient();
    DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, tokenManager, eventClient, new SystemCurrentTimeMillisProvider(), false);
    String token = "test-trace-token";
    when(request.getHttpVersion()).thenReturn(HTTP_2);
    when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(token);
    // log a request without a token set by tokenManager
    logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
    // create and set a new token with tokenManager
    tokenManager.createAndRegisterNewRequestToken();
    logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
    // clear the token HTTP header
    when(request.getHeader(TRACETOKEN_HEADER)).thenReturn(null);
    logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
    logger.stop();
    List<Object> events = eventClient.getEvents();
    assertEquals(events.size(), 3);
    // first two events should have the token set from the header
    for (int i = 0; i < 2; i++) {
        assertEquals(((HttpRequestEvent) events.get(i)).getTraceToken(), token);
    }
    // last event should have the token set by the tokenManager
    assertEquals(((HttpRequestEvent) events.get(2)).getTraceToken(), tokenManager.getCurrentRequestToken());
}
Also used : Response(org.eclipse.jetty.server.Response) InMemoryEventClient(io.airlift.event.client.InMemoryEventClient) Request(org.eclipse.jetty.server.Request) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) TraceTokenManager(io.airlift.tracetoken.TraceTokenManager) Test(org.testng.annotations.Test)

Example 4 with TraceTokenManager

use of io.airlift.tracetoken.TraceTokenManager in project airlift by airlift.

the class TestHttpServerCipher method createServer.

private static HttpServer createServer(HttpServlet servlet, NodeInfo nodeInfo, HttpServerInfo httpServerInfo, HttpServerConfig config, HttpsConfig httpsConfig) {
    HashLoginServiceProvider loginServiceProvider = new HashLoginServiceProvider(config);
    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());
    return serverProvider.get();
}
Also used : NullEventClient(io.airlift.event.client.NullEventClient) TraceTokenManager(io.airlift.tracetoken.TraceTokenManager)

Example 5 with TraceTokenManager

use of io.airlift.tracetoken.TraceTokenManager in project airlift by airlift.

the class TestTraceTokenRequestFilter method testSameRequestReturnedWhenTraceTokenNotSet.

@Test
public void testSameRequestReturnedWhenTraceTokenNotSet() {
    TraceTokenManager manager = new TraceTokenManager();
    TraceTokenRequestFilter filter = new TraceTokenRequestFilter(manager);
    Request original = prepareGet().setUri(URI.create("http://example.com")).build();
    Request request = filter.filterRequest(original);
    assertSame(request, original);
}
Also used : TraceTokenManager(io.airlift.tracetoken.TraceTokenManager) Test(org.testng.annotations.Test)

Aggregations

TraceTokenManager (io.airlift.tracetoken.TraceTokenManager)8 Test (org.testng.annotations.Test)5 NullEventClient (io.airlift.event.client.NullEventClient)4 InMemoryEventClient (io.airlift.event.client.InMemoryEventClient)2 DoubleSummaryStatistics (java.util.DoubleSummaryStatistics)2 Request (org.eclipse.jetty.server.Request)2 Response (org.eclipse.jetty.server.Response)2 Closer (com.google.common.io.Closer)1 HttpClientConfig (io.airlift.http.client.HttpClientConfig)1 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)1 NodeConfig (io.airlift.node.NodeConfig)1 NodeInfo (io.airlift.node.NodeInfo)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Principal (java.security.Principal)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpURI (org.eclipse.jetty.http.HttpURI)1