Search in sources :

Example 1 with HttpRequestMetadata

use of com.spotify.apollo.http.server.HttpRequestMetadata in project apollo by spotify.

the class HttpServiceTest method shouldPopulateRequestMetadata.

@Test
public void shouldPopulateRequestMetadata() throws Exception {
    AtomicReference<RequestMetadata> metadataReference = new AtomicReference<>();
    final InstanceWaiter waiter = new InstanceWaiter();
    Future<?> future = executorService.submit(() -> {
        try {
            HttpService.boot(environment -> environment.routingEngine().registerRoute(Route.async("GET", "/meta", trackMeta(metadataReference))), "metadatatest", waiter);
        } catch (LoadingException e) {
            throw new RuntimeException(e);
        }
    });
    final Service.Instance instance = waiter.waitForInstance();
    Request httpRequest = new Request.Builder().url("http://localhost:29432/meta").build();
    new OkHttpClient().newCall(httpRequest).execute();
    assertThat(((HttpRequestMetadata) metadataReference.get()).httpVersion(), is("HTTP/1.1"));
    instance.getSignaller().signalShutdown();
    instance.waitForShutdown();
    future.get();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Service(com.spotify.apollo.core.Service) ExecutorService(java.util.concurrent.ExecutorService) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpRequestMetadata(com.spotify.apollo.http.server.HttpRequestMetadata) RequestMetadata(com.spotify.apollo.RequestMetadata) Test(org.junit.Test)

Aggregations

RequestMetadata (com.spotify.apollo.RequestMetadata)1 Service (com.spotify.apollo.core.Service)1 HttpRequestMetadata (com.spotify.apollo.http.server.HttpRequestMetadata)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Test (org.junit.Test)1