Search in sources :

Example 1 with AddressResolver

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);
}
Also used : RecoveryAwareAMQConnectionFactory(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory) FrameHandlerFactory(com.rabbitmq.client.impl.FrameHandlerFactory) MetricsCollector(com.rabbitmq.client.MetricsCollector) AddressResolver(com.rabbitmq.client.AddressResolver) FrameHandler(com.rabbitmq.client.impl.FrameHandler) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Address(com.rabbitmq.client.Address) RecoveryAwareAMQConnection(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection) RecoveryAwareAMQConnection(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection) Connection(com.rabbitmq.client.Connection) ConnectionParams(com.rabbitmq.client.impl.ConnectionParams) Test(org.junit.Test)

Aggregations

Address (com.rabbitmq.client.Address)1 AddressResolver (com.rabbitmq.client.AddressResolver)1 Connection (com.rabbitmq.client.Connection)1 MetricsCollector (com.rabbitmq.client.MetricsCollector)1 ConnectionParams (com.rabbitmq.client.impl.ConnectionParams)1 FrameHandler (com.rabbitmq.client.impl.FrameHandler)1 FrameHandlerFactory (com.rabbitmq.client.impl.FrameHandlerFactory)1 RecoveryAwareAMQConnection (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection)1 RecoveryAwareAMQConnectionFactory (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 Test (org.junit.Test)1