use of com.hotels.styx.client.Connection in project styx by ExpediaGroup.
the class NettyConnectionTest method notifiesListenersWhenConnectionIsClosed.
@Test
public void notifiesListenersWhenConnectionIsClosed() throws Exception {
Connection connection = createConnection();
EventCapturingListener listener = new EventCapturingListener();
connection.addConnectionListener(listener);
channel.close();
assertThat(connection.isConnected(), is(false));
assertThat(listener.closedConnection(), isValue(connection));
}
use of com.hotels.styx.client.Connection in project styx by ExpediaGroup.
the class SimpleConnectionPoolTest method emitsExceptionWhenPendingConnectionTimesOut.
@Test
public void emitsExceptionWhenPendingConnectionTimesOut() {
EmitterProcessor<Connection> processor = EmitterProcessor.create();
when(connectionFactory.createConnection(any(Origin.class), any(ConnectionSettings.class))).thenReturn(Mono.from(processor));
ConnectionPoolSettings poolSettings = new ConnectionPoolSettings.Builder().pendingConnectionTimeout(500, MILLISECONDS).build();
SimpleConnectionPool pool = new SimpleConnectionPool(origin, poolSettings, connectionFactory);
StepVerifier.create(pool.borrowConnection()).expectError(MaxPendingConnectionTimeoutException.class).verifyThenAssertThat().tookMoreThan(Duration.ofMillis(500));
// And then ensure connection is placed in the active queue:
processor.onNext(mock(Connection.class));
assertEquals(pool.stats().availableConnectionCount(), 1);
assertEquals(pool.stats().pendingConnectionCount(), 0);
assertEquals(pool.stats().busyConnectionCount(), 0);
assertEquals(pool.stats().connectionAttempts(), 1);
}
use of com.hotels.styx.client.Connection in project styx by ExpediaGroup.
the class ExpiringConnectionTest method shouldExpireConnection.
@Test
public void shouldExpireConnection() {
Connection trackedConnection = new StubConnectionFactory.StubConnection(null);
ExpiringConnection connectionTracker = new ExpiringConnection(trackedConnection, 2, new OneSecondPerTickClock());
assertThat(connectionTracker.isConnected(), is(true));
assertThat(connectionTracker.isConnected(), is(false));
}
use of com.hotels.styx.client.Connection in project styx by ExpediaGroup.
the class SimpleConnectionPoolStressTest method canRoundTripBorrowedConnectionsFromMultipleThreads.
@Test
public void canRoundTripBorrowedConnectionsFromMultipleThreads() throws InterruptedException {
MultithreadedStressTester stressTester = new MultithreadedStressTester(10, 250);
Random returnOrClose = new Random();
stressTester.stress(() -> {
Connection connection = borrowConnectionSynchronously();
if (returnOrClose.nextBoolean()) {
releaseConnection(connection);
} else {
closeConnection(connection);
}
});
stressTester.shutdown();
assertThat("final busy connection count", pool.stats().busyConnectionCount(), is(0));
assertThat("final available connection count", pool.stats().availableConnectionCount(), is(greaterThanOrEqualTo(0)));
}
use of com.hotels.styx.client.Connection in project styx by ExpediaGroup.
the class SimpleConnectionPool method close.
@Override
public void close() {
active = false;
Connection con;
while ((con = availableConnections.poll()) != null) {
if (con.isConnected()) {
doCloseConnection(con);
}
}
}
Aggregations