use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class OriginTest method rejectsIfThereAreDuplicateHosts.
@Test
public void rejectsIfThereAreDuplicateHosts() {
Origin origin1 = newOriginBuilder("localhost", 8080).applicationId("webapp").id("origin-01").build();
Origin origin2 = newOriginBuilder("localhost", 8081).applicationId("webapp").id("origin-02").build();
Origin origin3 = newOriginBuilder("localhost", 8081).applicationId("webapp").id("origin-03").build();
assertThrows(IllegalArgumentException.class, () -> checkThatOriginsAreDistinct(List.of(origin1, origin2, origin3)));
}
use of com.hotels.styx.api.extension.Origin 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;
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class SimpleConnectionPoolTest method shouldNotHandoutConnectionToCancelledSubscriberWhenConnectionIsReturned.
@Test
public void shouldNotHandoutConnectionToCancelledSubscriberWhenConnectionIsReturned() throws Exception {
EmitterProcessor<Connection> processor = EmitterProcessor.create();
when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.from(processor));
ConnectionPoolSettings poolSettings = new ConnectionPoolSettings.Builder().pendingConnectionTimeout(100, MILLISECONDS).build();
SimpleConnectionPool simpleConnectionPool = new SimpleConnectionPool(origin, poolSettings, connectionFactory);
SimpleConnectionPool pool = spy(simpleConnectionPool);
when(pool.dequeue()).thenAnswer(new AnswersWithDelay(200, new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.callRealMethod();
}
}));
StepVerifier.create(pool.borrowConnection()).expectError(MaxPendingConnectionTimeoutException.class).verify();
pool.returnConnection(connection1);
assertEquals(pool.stats().availableConnectionCount(), 1);
// Waiting subscribers
assertEquals(pool.stats().pendingConnectionCount(), 0);
// Borrowed count
assertEquals(pool.stats().busyConnectionCount(), -1);
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class SimpleConnectionPoolTest method limitsPendingConnectionsDueToConnectionEstablishment.
@Test
public void limitsPendingConnectionsDueToConnectionEstablishment() {
when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.from(EmitterProcessor.create())).thenReturn(Mono.from(EmitterProcessor.create())).thenReturn(Mono.from(EmitterProcessor.create()));
ConnectionPoolSettings poolSettings = new ConnectionPoolSettings.Builder().maxPendingConnectionsPerHost(2).build();
SimpleConnectionPool pool = new SimpleConnectionPool(origin, poolSettings, connectionFactory);
Mono.from(pool.borrowConnection()).toFuture();
Mono.from(pool.borrowConnection()).toFuture();
StepVerifier.create(pool.borrowConnection()).expectError(MaxPendingConnectionsExceededException.class).verify();
assertEquals(pool.stats().connectionAttempts(), 2);
assertEquals(pool.stats().pendingConnectionCount(), 2);
}
use of com.hotels.styx.api.extension.Origin in project styx by ExpediaGroup.
the class SimpleConnectionPoolTest method borrowGivesUpConnectionEstablishmentAttemptAfterThreeTries.
@Test
public void borrowGivesUpConnectionEstablishmentAttemptAfterThreeTries() {
when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.error(new OriginUnreachableException(origin, new RuntimeException()))).thenReturn(Mono.error(new OriginUnreachableException(origin, new RuntimeException()))).thenReturn(Mono.error(new OriginUnreachableException(origin, new RuntimeException())));
SimpleConnectionPool pool = new SimpleConnectionPool(origin, defaultConnectionPoolSettings(), connectionFactory);
Mono.from(pool.borrowConnection()).subscribe();
assertEquals(pool.stats().pendingConnectionCount(), 1);
assertEquals(pool.stats().connectionFailures(), 1);
assertEquals(pool.stats().availableConnectionCount(), 0);
assertEquals(pool.stats().closedConnections(), 0);
assertEquals(pool.stats().terminatedConnections(), 0);
}
Aggregations