use of com.rabbitmq.client.AddressResolver in project rabbitmq-java-client by rabbitmq.
the class RecoveryAwareAMQConnectionFactoryTest method tryNextAddressIfTimeoutException.
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/262
@Test
public void tryNextAddressIfTimeoutException() throws IOException, TimeoutException {
final RecoveryAwareAMQConnection connectionThatThrowsTimeout = mock(RecoveryAwareAMQConnection.class);
final RecoveryAwareAMQConnection connectionThatSucceeds = mock(RecoveryAwareAMQConnection.class);
final Queue<RecoveryAwareAMQConnection> connections = new ArrayBlockingQueue<RecoveryAwareAMQConnection>(10);
connections.add(connectionThatThrowsTimeout);
connections.add(connectionThatSucceeds);
AddressResolver addressResolver = () -> Arrays.asList(new Address("host1"), new Address("host2"));
RecoveryAwareAMQConnectionFactory connectionFactory = new RecoveryAwareAMQConnectionFactory(new ConnectionParams(), mock(FrameHandlerFactory.class), addressResolver) {
@Override
protected RecoveryAwareAMQConnection createConnection(ConnectionParams params, FrameHandler handler, MetricsCollector metricsCollector) {
return connections.poll();
}
};
doThrow(TimeoutException.class).when(connectionThatThrowsTimeout).start();
doNothing().when(connectionThatSucceeds).start();
Connection returnedConnection = connectionFactory.newConnection();
assertSame(connectionThatSucceeds, returnedConnection);
}
Aggregations