Search in sources :

Example 6 with Context

use of com.hotels.styx.api.HttpInterceptor.Context in project styx by ExpediaGroup.

the class StyxHostHttpClientTest method returnsConnectionBackToPool.

@Test
public void returnsConnectionBackToPool() {
    Connection connection = mockConnection(just(response));
    ConnectionPool pool = mockPool(connection);
    Context context = mockContext();
    StyxHostHttpClient hostClient = new StyxHostHttpClient(pool);
    StepVerifier.create(hostClient.sendRequest(request, context)).consumeNextWith(response -> response.consume()).expectComplete().verify();
    verify(pool).borrowConnection();
    verify(connection).write(any(LiveHttpRequest.class));
    verify(pool).returnConnection(any(Connection.class));
    verify(context).add(ORIGINID_CONTEXT_KEY, Id.id("mockorigin"));
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) Support.requestContext(com.hotels.styx.support.Support.requestContext) Context(com.hotels.styx.api.HttpInterceptor.Context) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 7 with Context

use of com.hotels.styx.api.HttpInterceptor.Context in project styx by ExpediaGroup.

the class StyxHostHttpClientTest method terminatesConnectionWhenResponseObservableCompletesWithoutHeaders.

@Test
public void terminatesConnectionWhenResponseObservableCompletesWithoutHeaders() {
    // A connection that yields no response:
    Connection connection = mockConnection(Flux.empty());
    ConnectionPool pool = mockPool(connection);
    Context context = mockContext();
    StyxHostHttpClient hostClient = new StyxHostHttpClient(pool);
    StepVerifier.create(hostClient.sendRequest(request, context)).expectNextCount(0).expectComplete().log().verify();
    verify(pool).closeConnection(any(Connection.class));
    verify(context).add(ORIGINID_CONTEXT_KEY, Id.id("mockorigin"));
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) Support.requestContext(com.hotels.styx.support.Support.requestContext) Context(com.hotels.styx.api.HttpInterceptor.Context) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.hotels.styx.api.HttpInterceptor.Context)7 ConnectionPool (com.hotels.styx.client.connectionpool.ConnectionPool)7 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)7 Support.requestContext (com.hotels.styx.support.Support.requestContext)7 Test (org.junit.jupiter.api.Test)7 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Buffer (com.hotels.styx.api.Buffer)1 ByteStream (com.hotels.styx.api.ByteStream)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 Subscription (org.reactivestreams.Subscription)1