Search in sources :

Example 11 with ConnectionPool

use of com.hotels.styx.client.connectionpool.ConnectionPool 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 12 with ConnectionPool

use of com.hotels.styx.client.connectionpool.ConnectionPool in project styx by ExpediaGroup.

the class StyxHostHttpClientTest method closesTheConnectionPool.

@Test
public void closesTheConnectionPool() {
    ConnectionPool pool = mock(ConnectionPool.class);
    StyxHostHttpClient hostClient = new StyxHostHttpClient(pool);
    hostClient.close();
    verify(pool).close();
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) Test(org.junit.jupiter.api.Test)

Example 13 with ConnectionPool

use of com.hotels.styx.client.connectionpool.ConnectionPool 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)

Example 14 with ConnectionPool

use of com.hotels.styx.client.connectionpool.ConnectionPool in project styx by ExpediaGroup.

the class DashboardDataTest method pool.

private RemoteHost pool(Origin origin) {
    ConnectionPool pool = mock(ConnectionPool.class);
    when(pool.getOrigin()).thenReturn(origin);
    return remoteHost(origin, mock(HttpHandler.class), mock(LoadBalancingMetricSupplier.class));
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) HttpHandler(com.hotels.styx.api.HttpHandler) LoadBalancingMetricSupplier(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancingMetricSupplier)

Aggregations

ConnectionPool (com.hotels.styx.client.connectionpool.ConnectionPool)14 Test (org.junit.jupiter.api.Test)11 Context (com.hotels.styx.api.HttpInterceptor.Context)7 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)7 Support.requestContext (com.hotels.styx.support.Support.requestContext)7 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Origin (com.hotels.styx.api.extension.Origin)3 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)3 DisableOrigin (com.hotels.styx.client.origincommands.DisableOrigin)2 EnableOrigin (com.hotels.styx.client.origincommands.EnableOrigin)2 Buffer (com.hotels.styx.api.Buffer)1 ByteStream (com.hotels.styx.api.ByteStream)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 OriginsSnapshot (com.hotels.styx.api.extension.OriginsSnapshot)1 LoadBalancingMetricSupplier (com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancingMetricSupplier)1 Subscription (org.reactivestreams.Subscription)1