use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_InternalTest method configureMessageContent.
private void configureMessageContent(byte[] section) {
if (section == null) {
section = new byte[0];
}
final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
when(_handle.getContentSize()).thenReturn(section.length);
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_0_8Test method doTest.
private void doTest(final Serializable messageBytes, final String mimeType, final byte[] expectedContent, final String expectedContentType) throws Exception {
final InternalMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent();
assertArrayEquals("Unexpected content", expectedContent != null ? expectedContent : new byte[0], getBytes(content));
assertEquals("Unexpected content type", expectedContentType, convertedMessage.getMessageHeader().getMimeType());
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageMetaDataFactoryTest method testUnmarshalFromSingleBuffer.
public void testUnmarshalFromSingleBuffer() throws Exception {
try (QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocateDirect(_mmd.getStorableSize())) {
_mmd.writeToBuffer(qpidByteBuffer);
qpidByteBuffer.flip();
MessageMetaData recreated = MessageMetaData.FACTORY.createMetaData(qpidByteBuffer);
assertEquals("Unexpected arrival time", _arrivalTime, recreated.getArrivalTime());
assertEquals("Unexpected routing key", _routingKey, recreated.getMessagePublishInfo().getRoutingKey());
assertEquals("Unexpected content type", CONTENT_TYPE, recreated.getContentHeaderBody().getProperties().getContentTypeAsString());
recreated.dispose();
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AMQTypeTest method doTest.
private <T> void doTest(final AMQType type, final T value) {
final QpidByteBuffer buf = QpidByteBuffer.allocate(false, SIZE);
AMQTypedValue.createAMQTypedValue(type, value).writeToBuffer(buf);
buf.flip();
T read = (T) AMQTypedValue.readFromBuffer(buf).getValue();
assertEquals("Unexpected round trip value", value, read);
buf.dispose();
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpSequenceWithSimpleTypes.
public void testAmqpSequenceWithSimpleTypes() throws Exception {
final List<Integer> expected = new ArrayList<>();
expected.add(37);
expected.add(42);
final AmqpSequence amqpSequence = new AmqpSequence(expected);
Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected content", expected, new JmsStreamMessageToList().toObject(getBytes(content)));
}
Aggregations