use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class ConsumerTarget_1_0Test method testTTLAdjustedOnSend.
public void testTTLAdjustedOnSend() throws Exception {
final MessageInstanceConsumer comsumer = mock(MessageInstanceConsumer.class);
long ttl = 2000L;
long arrivalTime = System.currentTimeMillis() - 1000L;
final Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
final Message_1_0 message = createTestMessage(header, arrivalTime);
final MessageInstance messageInstance = mock(MessageInstance.class);
when(messageInstance.getMessage()).thenReturn(message);
AtomicReference<QpidByteBuffer> payloadRef = new AtomicReference<>();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
Transfer transfer = (Transfer) args[0];
QpidByteBuffer transferPayload = transfer.getPayload();
QpidByteBuffer payloadCopy = transferPayload.duplicate();
payloadRef.set(payloadCopy);
return null;
}).when(_sendingLinkEndpoint).transfer(any(Transfer.class), anyBoolean());
_consumerTarget.doSend(comsumer, messageInstance, false);
verify(_sendingLinkEndpoint, times(1)).transfer(any(Transfer.class), anyBoolean());
final List<EncodingRetainingSection<?>> sections;
try (QpidByteBuffer payload = payloadRef.get()) {
sections = new SectionDecoderImpl(_describedTypeRegistry.getSectionDecoderRegistry()).parseAll(payload);
}
Header sentHeader = null;
for (EncodingRetainingSection<?> section : sections) {
if (section instanceof HeaderSection) {
sentHeader = ((HeaderSection) section).getValue();
}
}
assertNotNull("Header is not found", sentHeader);
assertNotNull("Ttl is not set", sentHeader.getTtl());
assertTrue("Unexpected ttl", sentHeader.getTtl().longValue() <= 1000);
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_1_0Test method doTest.
private void doTest(final Serializable messageBytes, final String mimeType, final Class<? extends EncodingRetainingSection<?>> expectedBodySection, final Object expectedContent, final Symbol expectedContentType, final Byte expectedJmsTypeAnnotation) throws Exception {
final InternalMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent();
List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
EncodingRetainingSection<?> encodingRetainingSection = sections.get(0);
assertEquals("Unexpected section type", expectedBodySection, encodingRetainingSection.getClass());
if (expectedContent instanceof byte[]) {
assertArrayEquals("Unexpected content", ((byte[]) expectedContent), ((Binary) encodingRetainingSection.getValue()).getArray());
} else {
assertEquals("Unexpected content", expectedContent, encodingRetainingSection.getValue());
}
Symbol contentType = getContentType(convertedMessage);
if (expectedContentType == null) {
assertNull("Content type should be null", contentType);
} else {
assertEquals("Unexpected content type", expectedContentType, contentType);
}
Byte jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(convertedMessage);
if (expectedJmsTypeAnnotation == null) {
assertEquals("Unexpected annotation 'x-opt-jms-msg-type'", null, jmsMessageTypeAnnotation);
} else {
assertEquals("Unexpected annotation 'x-opt-jms-msg-type'", expectedJmsTypeAnnotation, jmsMessageTypeAnnotation);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_1_0Test 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 MessageFormat_0_10 method convertToMessageFormat.
// format: <int header count> <headers> <body>
@Override
public QpidByteBuffer convertToMessageFormat(final MessageTransferMessage message) {
ServerEncoder encoder = new ServerEncoder(4096, true);
Struct[] structs = message.getHeader().getStructs();
encoder.writeInt32(structs.length);
for (Struct struct : structs) {
encoder.writeStruct32(struct);
}
try (QpidByteBuffer headerBuf = encoder.getBuffer();
QpidByteBuffer content = message.getContent()) {
return QpidByteBuffer.concatenate(headerBuf, content);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageMetaData_0_10 method encodeAsBuffer.
private QpidByteBuffer encodeAsBuffer() {
ServerEncoder encoder = new ServerEncoder(ENCODER_SIZE, false);
encoder.writeInt64(_messageHeader.getArrivalTime());
encoder.writeInt32(_bodySize);
int headersLength = 0;
if (_header != null) {
if (_header.getDeliveryProperties() != null) {
headersLength++;
}
if (_header.getMessageProperties() != null) {
headersLength++;
}
if (_header.getNonStandardProperties() != null) {
headersLength += _header.getNonStandardProperties().size();
}
}
encoder.writeInt32(headersLength);
if (_header != null) {
if (_header.getDeliveryProperties() != null) {
encoder.writeStruct32(_header.getDeliveryProperties());
}
if (_header.getMessageProperties() != null) {
encoder.writeStruct32(_header.getMessageProperties());
}
if (_header.getNonStandardProperties() != null) {
for (Struct header : _header.getNonStandardProperties()) {
encoder.writeStruct32(header);
}
}
}
QpidByteBuffer buf = encoder.getBuffer();
encoder.close();
return buf;
}
Aggregations