Search in sources :

Example 1 with UnexpectedFrameError

use of com.rabbitmq.client.UnexpectedFrameError in project rabbitmq-java-client by rabbitmq.

the class BrokenFramesTest method methodThenBody.

@Test
public void methodThenBody() throws Exception {
    List<Frame> frames = new ArrayList<Frame>();
    byte[] contentBody = new byte[10];
    int channelNumber = 0;
    Publish method = new Publish(1, "test", "test", false, false);
    frames.add(method.toFrame(0));
    frames.add(Frame.fromBodyFragment(channelNumber, contentBody, 0, contentBody.length));
    myFrameHandler.setFrames(frames.iterator());
    try {
        new AMQConnection(factory.params(Executors.newFixedThreadPool(1)), myFrameHandler).start();
    } catch (IOException e) {
        UnexpectedFrameError unexpectedFrameError = findUnexpectedFrameError(e);
        assertNotNull(unexpectedFrameError);
        assertEquals(AMQP.FRAME_BODY, unexpectedFrameError.getReceivedFrame().type);
        assertEquals(AMQP.FRAME_HEADER, unexpectedFrameError.getExpectedFrameType());
        return;
    }
    fail("No UnexpectedFrameError thrown");
}
Also used : Frame(com.rabbitmq.client.impl.Frame) AMQConnection(com.rabbitmq.client.impl.AMQConnection) ArrayList(java.util.ArrayList) UnexpectedFrameError(com.rabbitmq.client.UnexpectedFrameError) IOException(java.io.IOException) Publish(com.rabbitmq.client.impl.AMQImpl.Basic.Publish) Test(org.junit.Test)

Example 2 with UnexpectedFrameError

use of com.rabbitmq.client.UnexpectedFrameError in project rabbitmq-java-client by rabbitmq.

the class BrokenFramesTest method noMethod.

@Test
public void noMethod() throws Exception {
    List<Frame> frames = new ArrayList<Frame>();
    frames.add(new Frame(AMQP.FRAME_HEADER, 0));
    myFrameHandler.setFrames(frames.iterator());
    try {
        new AMQConnection(factory.params(Executors.newFixedThreadPool(1)), myFrameHandler).start();
    } catch (IOException e) {
        UnexpectedFrameError unexpectedFrameError = findUnexpectedFrameError(e);
        assertNotNull(unexpectedFrameError);
        assertEquals(AMQP.FRAME_HEADER, unexpectedFrameError.getReceivedFrame().type);
        assertEquals(AMQP.FRAME_METHOD, unexpectedFrameError.getExpectedFrameType());
        return;
    }
    fail("No UnexpectedFrameError thrown");
}
Also used : Frame(com.rabbitmq.client.impl.Frame) AMQConnection(com.rabbitmq.client.impl.AMQConnection) ArrayList(java.util.ArrayList) UnexpectedFrameError(com.rabbitmq.client.UnexpectedFrameError) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

UnexpectedFrameError (com.rabbitmq.client.UnexpectedFrameError)2 AMQConnection (com.rabbitmq.client.impl.AMQConnection)2 Frame (com.rabbitmq.client.impl.Frame)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Publish (com.rabbitmq.client.impl.AMQImpl.Basic.Publish)1