Search in sources :

Example 76 with QpidByteBuffer

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);
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) HeaderSection(org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection) MessageInstance(org.apache.qpid.server.message.MessageInstance) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) SectionDecoderImpl(org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 77 with QpidByteBuffer

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);
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 78 with QpidByteBuffer

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()));
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 79 with QpidByteBuffer

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);
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Example 80 with QpidByteBuffer

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;
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)185 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)61 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)61 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)30 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)29 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 ArrayList (java.util.ArrayList)22 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)20 Test (org.junit.Test)13 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)12 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ByteBuffer (java.nio.ByteBuffer)8 LinkedHashMap (java.util.LinkedHashMap)8 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)8