Search in sources :

Example 81 with ConnectionFactory

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);
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Test(org.junit.Test)

Example 82 with ConnectionFactory

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;
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory)

Example 83 with 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) {
        }
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) MalformedFrameException(com.rabbitmq.client.MalformedFrameException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) SocketFrameHandler(com.rabbitmq.client.impl.SocketFrameHandler) Socket(java.net.Socket) Test(org.junit.Test)

Example 84 with ConnectionFactory

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");
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 85 with 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)).isTrue();
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) Channel(com.rabbitmq.client.Channel) StrictExceptionHandler(com.rabbitmq.client.impl.StrictExceptionHandler) Connection(com.rabbitmq.client.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ConnectionFactory (com.rabbitmq.client.ConnectionFactory)188 Connection (com.rabbitmq.client.Connection)87 Test (org.junit.Test)73 Channel (com.rabbitmq.client.Channel)63 IOException (java.io.IOException)53 TimeoutException (java.util.concurrent.TimeoutException)23 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)11 Envelope (com.rabbitmq.client.Envelope)11 SSLContext (javax.net.ssl.SSLContext)11 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)9 HashMap (java.util.HashMap)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 AMQP (com.rabbitmq.client.AMQP)6 Consumer (com.rabbitmq.client.Consumer)6 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)6 AMQConnection (com.rabbitmq.client.impl.AMQConnection)6 Address (com.rabbitmq.client.Address)5 NioParams (com.rabbitmq.client.impl.nio.NioParams)4 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)4 Path (javax.ws.rs.Path)3