Search in sources :

Example 1 with ConnectionPool

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

the class DashboardDataSupplierTest method pool.

private ConnectionPool pool(Origin origin) {
    ConnectionPool pool = mock(ConnectionPool.class);
    when(pool.getOrigin()).thenReturn(origin);
    return pool;
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool)

Example 2 with ConnectionPool

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

the class OriginsInventoryTest method stopsMonitoringAndUnregistersWhenClosed.

@Test
public void stopsMonitoringAndUnregistersWhenClosed() {
    ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
    ConnectionPool pool1 = mock(ConnectionPool.class);
    when(pool1.getOrigin()).thenReturn(ORIGIN_1);
    ConnectionPool pool2 = mock(ConnectionPool.class);
    when(pool2.getOrigin()).thenReturn(ORIGIN_2);
    when(connectionFactory.create(eq(ORIGIN_1))).thenReturn(pool1);
    when(connectionFactory.create(eq(ORIGIN_2))).thenReturn(pool2);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
    inventory.setOrigins(ORIGIN_1, ORIGIN_2);
    inventory.close();
    verify(monitor).stopMonitoring(eq(Set.of(ORIGIN_1)));
    verify(monitor).stopMonitoring(eq(Set.of(ORIGIN_2)));
    assertThat(gaugeValue("generic-app", "app-01"), isAbsent());
    assertThat(gaugeValue("generic-app", "app-02"), isAbsent());
    verify(pool1).close();
    verify(pool2).close();
    verify(eventBus, times(2)).post(any(OriginsSnapshot.class));
    verify(eventBus).unregister(eq(inventory));
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) OriginsSnapshot(com.hotels.styx.api.extension.OriginsSnapshot) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionPool

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

the class OriginsInventoryTest method shutsConnectionPoolForModifiedOrigin.

@Test
public void shutsConnectionPoolForModifiedOrigin() {
    Origin originV1 = newOriginBuilder("acme01.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    Origin originV2 = newOriginBuilder("acme02.com", 80).applicationId(GENERIC_APP).id("acme-01").build();
    ConnectionPool.Factory connectionFactory = mock(ConnectionPool.Factory.class);
    ConnectionPool pool1 = mock(ConnectionPool.class);
    ConnectionPool pool2 = mock(ConnectionPool.class);
    when(connectionFactory.create(eq(originV1))).thenReturn(pool1);
    when(connectionFactory.create(eq(originV2))).thenReturn(pool2);
    inventory = new OriginsInventory(eventBus, GENERIC_APP, monitor, connectionFactory, hostClientFactory, new CentralisedMetrics(meterRegistry));
    inventory.setOrigins(originV1);
    verify(connectionFactory).create(eq(originV1));
    inventory.setOrigins(originV2);
    verify(connectionFactory).create(eq(originV2));
    verify(pool1).close();
}
Also used : DisableOrigin(com.hotels.styx.client.origincommands.DisableOrigin) EnableOrigin(com.hotels.styx.client.origincommands.EnableOrigin) Origin(com.hotels.styx.api.extension.Origin) ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Test(org.junit.jupiter.api.Test)

Example 4 with ConnectionPool

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

the class StyxHostHttpClientTest method terminatesConnectionDueToUnsubscribedBody.

@Test
public void terminatesConnectionDueToUnsubscribedBody() {
    TestPublisher<Buffer> testPublisher = TestPublisher.create();
    Connection connection = mockConnection(just(LiveHttpResponse.response(OK).body(new ByteStream(testPublisher)).build()));
    ConnectionPool pool = mockPool(connection);
    Context context = mockContext();
    AtomicReference<LiveHttpResponse> receivedResponse = new AtomicReference<>();
    StyxHostHttpClient hostClient = new StyxHostHttpClient(pool);
    StepVerifier.create(hostClient.sendRequest(request, context)).consumeNextWith(receivedResponse::set).expectComplete().verify();
    StepVerifier.create(receivedResponse.get().body()).thenCancel().verify();
    verify(pool).closeConnection(any(Connection.class));
    verify(context).add(ORIGINID_CONTEXT_KEY, Id.id("mockorigin"));
}
Also used : Buffer(com.hotels.styx.api.Buffer) 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) ByteStream(com.hotels.styx.api.ByteStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 5 with ConnectionPool

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

the class StyxHostHttpClientTest method mockPool.

ConnectionPool mockPool(Connection connection) {
    ConnectionPool pool = mock(ConnectionPool.class);
    when(pool.borrowConnection()).thenReturn(Flux.just(connection));
    Origin origin = mockOrigin("mockorigin");
    when(pool.getOrigin()).thenReturn(origin);
    return pool;
}
Also used : ConnectionPool(com.hotels.styx.client.connectionpool.ConnectionPool) Origin(com.hotels.styx.api.extension.Origin)

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