use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class SharedThreadPoolTest method willShutDownExecutor.
@Test
public void willShutDownExecutor() throws IOException, TimeoutException {
ExecutorService executor1 = null;
ExecutorService executor2 = null;
AMQConnection conn1 = null;
AMQConnection conn2 = null;
AMQConnection conn3 = null;
AMQConnection conn4 = null;
try {
ConnectionFactory cf = TestUtils.connectionFactory();
cf.setAutomaticRecoveryEnabled(false);
executor1 = Executors.newFixedThreadPool(8);
cf.setSharedExecutor(executor1);
conn1 = (AMQConnection) cf.newConnection();
assertFalse(conn1.willShutDownConsumerExecutor());
executor2 = Executors.newSingleThreadExecutor();
conn2 = (AMQConnection) cf.newConnection(executor2);
assertFalse(conn2.willShutDownConsumerExecutor());
conn3 = (AMQConnection) cf.newConnection((ExecutorService) null);
assertTrue(conn3.willShutDownConsumerExecutor());
cf.setSharedExecutor(null);
conn4 = (AMQConnection) cf.newConnection();
assertTrue(conn4.willShutDownConsumerExecutor());
} finally {
close(conn1);
close(conn2);
close(conn3);
close(conn4);
close(executor1);
close(executor2);
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo.
private void doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo(Supplier<ConnectionFactory> supplier) throws Exception {
ConnectionFactory connectionFactory = supplier.get();
connectionFactory.useBlockingIo();
SslContextFactory sslContextFactory = sslContextFactory();
connectionFactory.setSslContextFactory(sslContextFactory);
SSLContext contextAcceptAll = sslContextFactory.create("connection01");
connectionFactory.setSocketFactory(contextAcceptAll.getSocketFactory());
Connection connection = connectionFactory.newConnection("connection01");
TestUtils.close(connection);
connection = connectionFactory.newConnection("connection02");
TestUtils.close(connection);
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method doTestSetSslContextFactory.
private void doTestSetSslContextFactory(Supplier<ConnectionFactory> supplier) throws Exception {
ConnectionFactory connectionFactory = supplier.get();
SslContextFactory sslContextFactory = sslContextFactory();
connectionFactory.setSslContextFactory(sslContextFactory);
Connection connection = connectionFactory.newConnection("connection01");
TestUtils.close(connection);
try {
connectionFactory.newConnection("connection02");
fail("The SSL context of this client should not trust the server");
} catch (SSLHandshakeException e) {
// OK
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method setSslContextFactory.
@Test
public void setSslContextFactory() throws Exception {
doTestSetSslContextFactory(() -> {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.useBlockingIo();
connectionFactory.setAutomaticRecoveryEnabled(true);
return connectionFactory;
});
doTestSetSslContextFactory(() -> {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.useNio();
connectionFactory.setAutomaticRecoveryEnabled(true);
return connectionFactory;
});
doTestSetSslContextFactory(() -> {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.useBlockingIo();
connectionFactory.setAutomaticRecoveryEnabled(false);
return connectionFactory;
});
doTestSetSslContextFactory(() -> {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.useNio();
connectionFactory.setAutomaticRecoveryEnabled(false);
return connectionFactory;
});
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class StrictExceptionHandlerTest method tooLongClosingMessage.
@Test
public void tooLongClosingMessage() throws Exception {
ConnectionFactory cf = TestUtils.connectionFactory();
final CountDownLatch latch = new CountDownLatch(1);
cf.setExceptionHandler(new StrictExceptionHandler() {
@Override
public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
try {
super.handleConsumerException(channel, exception, consumer, consumerTag, methodName);
} catch (IllegalArgumentException e) {
fail("No exception should caught");
}
latch.countDown();
}
});
try (Connection c = cf.newConnection()) {
Channel channel = c.createChannel();
String queue = channel.queueDeclare().getQueue();
channel.basicConsume(queue, new VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(channel));
channel.basicPublish("", queue, null, new byte[0]);
assertThat(latch.await(5, TimeUnit.SECONDS), is(true));
}
}
Aggregations