use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class CloseInMainLoop method specialConnectionFactory.
private ConnectionFactory specialConnectionFactory() {
ConnectionFactory f = TestUtils.connectionFactory();
f.setExceptionHandler(new DefaultExceptionHandler() {
@Override
public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
try {
// TODO: change this to call 4-parameter close and make 6-parm one private
((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR, "Internal error in Consumer " + consumerTag, false, exception, -1, false);
} catch (Throwable e) {
// Man, this clearly isn't our day.
// TODO: Log the nested failure
} finally {
closeLatch.countDown();
}
}
});
return f;
}
use of com.rabbitmq.client.ConnectionFactory 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.ConnectionFactory 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.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class DnsRecordIpAddressResolverTests method loopbackInterfaceResolution.
@Test
public void loopbackInterfaceResolution() throws IOException, TimeoutException {
DnsRecordIpAddressResolver addressResolver = new DnsRecordIpAddressResolver("127.0.0.1");
ConnectionFactory connectionFactory = newConnectionFactory();
Connection connection = connectionFactory.newConnection(addressResolver);
try {
connection.createChannel();
} finally {
connection.abort();
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class NoAutoRecoveryWhenTcpWindowIsFullTest method setUp.
@Before
public void setUp() throws Exception {
// we need several threads to publish, dispatch deliveries, handle RPC responses, etc.
executorService = Executors.newFixedThreadPool(10);
final ConnectionFactory factory = TestUtils.connectionFactory();
factory.setSocketConfigurator(new DefaultSocketConfigurator() {
/* default value on Linux */
int DEFAULT_RECEIVE_BUFFER_SIZE = 43690;
@Override
public void configure(Socket socket) throws IOException {
super.configure(socket);
socket.setReceiveBufferSize(DEFAULT_RECEIVE_BUFFER_SIZE);
}
});
factory.setAutomaticRecoveryEnabled(true);
factory.setTopologyRecoveryEnabled(true);
// we try to set the lower values for closing timeouts, etc.
// this makes the test execute faster.
factory.setRequestedHeartbeat(5);
factory.setSharedExecutor(executorService);
// we need the shutdown executor: channel shutting down depends on the work pool,
// which is full. Channel shutting down will time out with the shutdown executor.
factory.setShutdownExecutor(executorService);
factory.setNetworkRecoveryInterval(2000);
if (TestUtils.USE_NIO) {
factory.setWorkPoolTimeout(10 * 1000);
factory.setNioParams(new NioParams().setWriteQueueCapacity(10 * 1000 * 1000).setNbIoThreads(4));
}
producingConnection = (AutorecoveringConnection) factory.newConnection("Producer Connection");
producingChannel = (AutorecoveringChannel) producingConnection.createChannel();
consumingConnection = (AutorecoveringConnection) factory.newConnection("Consuming Connection");
consumingChannel = (AutorecoveringChannel) consumingConnection.createChannel();
consumerOkLatch = new CountDownLatch(2);
}
Aggregations