use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class FrameMax method rejectExceedingFrameMax.
/* server should reject frames larger than the negotiated frame
* size */
@Test
public void rejectExceedingFrameMax() throws IOException, TimeoutException {
closeChannel();
closeConnection();
ConnectionFactory cf = new GenerousConnectionFactory();
cf.setRequestedFrameMax(8192);
connection = cf.newConnection();
openChannel();
basicPublishVolatile(new byte[connection.getFrameMax() * 2], "void");
expectError(AMQP.FRAME_ERROR);
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class TopologyRecoveryFiltering method newConnectionFactory.
@Override
protected ConnectionFactory newConnectionFactory() {
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
connectionFactory.setTopologyRecoveryFilter(new SimpleTopologyRecoveryFilter());
connectionFactory.setNetworkRecoveryInterval(1000);
return connectionFactory;
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ConnectionOpen method crazyProtocolHeader.
@Test
public void crazyProtocolHeader() throws IOException {
ConnectionFactory factory = TestUtils.connectionFactory();
// keep the frame handler's socket
Socket fhSocket = SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT);
SocketFrameHandler fh = new SocketFrameHandler(fhSocket);
// major, minor
fh.sendHeader(100, 3);
DataInputStream in = fh.getInputStream();
// we should get a valid protocol header back
byte[] header = new byte[4];
in.read(header);
// The protocol header is "AMQP" plus a version that the server
// supports. We can really only test for the first bit.
assertEquals("AMQP", new String(header));
in.read(header);
assertEquals(in.available(), 0);
// gives an error.
if (!fhSocket.isClosed()) {
fh.setTimeout(500);
// NB the frame handler will return null if the socket times out
try {
fh.readFrame();
fail("Expected socket read to fail due to socket being closed");
} catch (MalformedFrameException mfe) {
fail("Expected nothing, rather than a badly-formed something");
} catch (IOException ioe) {
}
}
}
use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.
the class ConnectionOpen method frameMaxLessThanFrameMinSize.
@Test
public void frameMaxLessThanFrameMinSize() throws IOException, TimeoutException {
ConnectionFactory factory = TestUtils.connectionFactory();
factory.setRequestedFrameMax(100);
try {
factory.newConnection();
} catch (IOException ioe) {
return;
}
fail("Broker should have closed the connection since our frame max < frame_min_size");
}
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)).isTrue();
}
}
Aggregations