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);
}
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);
}
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);
}
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]);
}
}
}
Aggregations