use of com.rabbitmq.client.MetricsCollector in project rabbitmq-java-client by rabbitmq.
the class ConnectionFactoryTest method tryNextAddressIfTimeoutExceptionNoAutoRecovery.
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/262
@Test
public void tryNextAddressIfTimeoutExceptionNoAutoRecovery() throws IOException, TimeoutException {
final AMQConnection connectionThatThrowsTimeout = mock(AMQConnection.class);
final AMQConnection connectionThatSucceeds = mock(AMQConnection.class);
final Queue<AMQConnection> connections = new ArrayBlockingQueue<AMQConnection>(10);
connections.add(connectionThatThrowsTimeout);
connections.add(connectionThatSucceeds);
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector) {
return connections.poll();
}
@Override
protected synchronized FrameHandlerFactory createFrameHandlerFactory() throws IOException {
return mock(FrameHandlerFactory.class);
}
};
connectionFactory.setAutomaticRecoveryEnabled(false);
doThrow(TimeoutException.class).when(connectionThatThrowsTimeout).start();
doNothing().when(connectionThatSucceeds).start();
Connection returnedConnection = connectionFactory.newConnection(new Address[] { new Address("host1"), new Address("host2") });
assertSame(connectionThatSucceeds, returnedConnection);
}
use of com.rabbitmq.client.MetricsCollector in project rabbitmq-java-client by rabbitmq.
the class ConnectionFactoryTest method customizeCredentialsProvider.
// see https://github.com/rabbitmq/rabbitmq-java-client/pull/350
@Test
public void customizeCredentialsProvider() throws Exception {
final CredentialsProvider provider = mock(CredentialsProvider.class);
final AMQConnection connection = mock(AMQConnection.class);
final AtomicBoolean createCalled = new AtomicBoolean(false);
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector) {
assertSame(provider, params.getCredentialsProvider());
createCalled.set(true);
return connection;
}
};
connectionFactory.setCredentialsProvider(provider);
connectionFactory.setAutomaticRecoveryEnabled(false);
doNothing().when(connection).start();
Connection returnedConnection = connectionFactory.newConnection();
assertSame(returnedConnection, connection);
assertTrue(createCalled.get());
}
use of com.rabbitmq.client.MetricsCollector 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