Search in sources :

Example 1 with FrameBuilder

use of com.rabbitmq.client.impl.nio.FrameBuilder in project rabbitmq-java-client by rabbitmq.

the class FrameBuilderTest method buildFramesInOneGo.

@Test
public void buildFramesInOneGo() throws IOException {
    byte[] frameContent = new byte[] { 1, 0, 0, 0, 0, 0, 3, 1, 2, 3, end() };
    int nbFrames = 13;
    byte[] frames = new byte[frameContent.length * nbFrames];
    for (int i = 0; i < nbFrames; i++) {
        for (int j = 0; j < frameContent.length; j++) {
            frames[i * frameContent.length + j] = frameContent[j];
        }
    }
    buffer = ByteBuffer.wrap(frames);
    builder = new FrameBuilder(channel, buffer);
    int frameCount = 0;
    Frame frame;
    while ((frame = builder.readFrame()) != null) {
        assertThat(frame).isNotNull();
        assertThat(frame.getType()).isEqualTo(1);
        assertThat(frame.getChannel()).isEqualTo(0);
        assertThat(frame.getPayload()).hasSize(3);
        frameCount++;
    }
    assertThat(frameCount).isEqualTo(nbFrames);
}
Also used : Frame(com.rabbitmq.client.impl.Frame) FrameBuilder(com.rabbitmq.client.impl.nio.FrameBuilder) Test(org.junit.Test)

Example 2 with FrameBuilder

use of com.rabbitmq.client.impl.nio.FrameBuilder in project rabbitmq-java-client by rabbitmq.

the class FrameBuilderTest method buildFrameInOneGo.

@Test
public void buildFrameInOneGo() throws IOException {
    buffer = ByteBuffer.wrap(new byte[] { 1, 0, 0, 0, 0, 0, 3, 1, 2, 3, end() });
    builder = new FrameBuilder(channel, buffer);
    Frame frame = builder.readFrame();
    assertThat(frame).isNotNull();
    assertThat(frame.getType()).isEqualTo(1);
    assertThat(frame.getChannel()).isEqualTo(0);
    assertThat(frame.getPayload()).hasSize(3);
}
Also used : Frame(com.rabbitmq.client.impl.Frame) FrameBuilder(com.rabbitmq.client.impl.nio.FrameBuilder) Test(org.junit.Test)

Example 3 with FrameBuilder

use of com.rabbitmq.client.impl.nio.FrameBuilder in project rabbitmq-java-client by rabbitmq.

the class FrameBuilderTest method buildFrameInSeveralCalls.

@Test
public void buildFrameInSeveralCalls() throws IOException {
    buffer = ByteBuffer.wrap(new byte[] { 1, 0, 0, 0, 0, 0, 3, 1, 2 });
    builder = new FrameBuilder(channel, buffer);
    Frame frame = builder.readFrame();
    assertThat(frame).isNull();
    buffer.clear();
    buffer.put(b(3)).put(end());
    buffer.flip();
    frame = builder.readFrame();
    assertThat(frame).isNotNull();
    assertThat(frame.getType()).isEqualTo(1);
    assertThat(frame.getChannel()).isEqualTo(0);
    assertThat(frame.getPayload()).hasSize(3);
}
Also used : Frame(com.rabbitmq.client.impl.Frame) FrameBuilder(com.rabbitmq.client.impl.nio.FrameBuilder) Test(org.junit.Test)

Example 4 with FrameBuilder

use of com.rabbitmq.client.impl.nio.FrameBuilder in project rabbitmq-java-client by rabbitmq.

the class FrameBuilderTest method protocolMismatchHeader.

@Test
public void protocolMismatchHeader() throws IOException {
    ByteBuffer[] buffers = new ByteBuffer[] { ByteBuffer.wrap(new byte[] { 'A' }), ByteBuffer.wrap(new byte[] { 'A', 'M', 'Q' }), ByteBuffer.wrap(new byte[] { 'A', 'N', 'Q', 'P' }), ByteBuffer.wrap(new byte[] { 'A', 'M', 'Q', 'P' }), ByteBuffer.wrap(new byte[] { 'A', 'M', 'Q', 'P', 1, 1, 8 }), ByteBuffer.wrap(new byte[] { 'A', 'M', 'Q', 'P', 1, 1, 8, 0 }), ByteBuffer.wrap(new byte[] { 'A', 'M', 'Q', 'P', 1, 1, 9, 1 }) };
    String[] messages = new String[] { "Invalid AMQP protocol header from server: read only 1 byte(s) instead of 4", "Invalid AMQP protocol header from server: read only 3 byte(s) instead of 4", "Invalid AMQP protocol header from server: expected character 77, got 78", "Invalid AMQP protocol header from server", "Invalid AMQP protocol header from server", "AMQP protocol version mismatch; we are version 0-9-1, server is 0-8", "AMQP protocol version mismatch; we are version 0-9-1, server sent signature 1,1,9,1" };
    for (int i = 0; i < buffers.length; i++) {
        builder = new FrameBuilder(channel, buffers[i]);
        try {
            builder.readFrame();
            fail("protocol header not correct, exception should have been thrown");
        } catch (MalformedFrameException e) {
            assertThat(e.getMessage()).isEqualTo(messages[i]);
        }
    }
}
Also used : MalformedFrameException(com.rabbitmq.client.MalformedFrameException) FrameBuilder(com.rabbitmq.client.impl.nio.FrameBuilder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

FrameBuilder (com.rabbitmq.client.impl.nio.FrameBuilder)4 Test (org.junit.Test)4 Frame (com.rabbitmq.client.impl.Frame)3 MalformedFrameException (com.rabbitmq.client.MalformedFrameException)1 ByteBuffer (java.nio.ByteBuffer)1