Search in sources :

Example 21 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeReceivingLinkWithSingleUnsettledAccepted.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkWithSingleUnsettledAccepted() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        List<Transfer> transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer transfer = transfers.get(0);
        Binary deliveryTag = transfer.getDeliveryTag();
        assertThat(deliveryTag, is(notNullValue()));
        assertThat(transfer.getSettled(), is(not(equalTo(true))));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
        interaction.attachUnsettled(Collections.singletonMap(deliveryTag, new Accepted())).attach().consumeResponse(Attach.class);
        Attach resumeAttach = interaction.getLatestResponse(Attach.class);
        Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
        assertThat(unsettled, is(notNullValue()));
        assertThat(unsettled.entrySet(), hasSize(1));
        Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
        assertThat(entry.getKey(), is(equalTo(deliveryTag)));
        interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer resumeTransfer = transfers.get(0);
        assertThat(resumeTransfer.getResume(), is(equalTo(true)));
        assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
        assertThat(resumeTransfer.getPayload(), is(nullValue()));
        if (!Boolean.TRUE.equals(resumeTransfer.getSettled())) {
            interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
        }
        interaction.doCloseConnection();
        if (getBrokerAdmin().isQueueDepthSupported()) {
            assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Map(java.util.Map) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 22 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeReceivingLinkOneUnsettledWithNoOutcome.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkOneUnsettledWithNoOutcome() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        List<Transfer> transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer transfer = transfers.get(0);
        Binary deliveryTag = transfer.getDeliveryTag();
        assertThat(deliveryTag, is(notNullValue()));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Detach detach = interaction.detach().consumeResponse(Detach.class).getLatestResponse(Detach.class);
        assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
        interaction.attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse(Attach.class);
        Attach resumeAttach = interaction.getLatestResponse(Attach.class);
        Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
        assertThat(unsettled, is(notNullValue()));
        assertThat(unsettled.entrySet(), hasSize(1));
        Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
        assertThat(entry.getKey(), is(equalTo(deliveryTag)));
        interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer resumeTransfer = transfers.get(0);
        assertThat(resumeTransfer.getResume(), is(equalTo(true)));
        assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
        assertThat(resumeTransfer.getPayload(), is(notNullValue()));
        interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
        interaction.doCloseConnection();
        if (getBrokerAdmin().isQueueDepthSupported()) {
            assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(0)));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Map(java.util.Map) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 23 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class FrameEncoder method encode.

@Override
public ByteBuffer encode(final Object msg) {
    if (msg instanceof AMQFrame) {
        List<ByteBuffer> buffers = new ArrayList<>();
        FrameWriter _frameWriter = new FrameWriter(TYPE_REGISTRY, new ByteBufferSender() {

            @Override
            public boolean isDirectBufferPreferred() {
                return false;
            }

            @Override
            public void send(final QpidByteBuffer msg) {
                byte[] data = new byte[msg.remaining()];
                msg.get(data);
                buffers.add(ByteBuffer.wrap(data));
            }

            @Override
            public void flush() {
            }

            @Override
            public void close() {
            }
        });
        _frameWriter.send(((AMQFrame) msg));
        int remaining = 0;
        for (ByteBuffer byteBuffer : buffers) {
            remaining += byteBuffer.remaining();
        }
        ByteBuffer result = ByteBuffer.allocate(remaining);
        for (ByteBuffer byteBuffer : buffers) {
            result.put(byteBuffer);
        }
        result.flip();
        return result;
    }
    return null;
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter)

Example 24 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class MessageEncoder method getPayload.

public QpidByteBuffer getPayload() {
    List<QpidByteBuffer> payload = new ArrayList<>();
    if (_header != null) {
        payload.add(_header.createEncodingRetainingSection().getEncodedForm());
    }
    if (_properties != null) {
        payload.add(_properties.createEncodingRetainingSection().getEncodedForm());
    }
    if (_applicationProperties != null) {
        payload.add(new ApplicationProperties(_applicationProperties).createEncodingRetainingSection().getEncodedForm());
    }
    if (_data.isEmpty()) {
        throw new IllegalStateException("Message should have at least one data section");
    }
    List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
    if (_data.size() == 1) {
        AmqpValue amqpValue = new AmqpValue(_data.get(0));
        dataSections.add(amqpValue.createEncodingRetainingSection());
    } else {
        throw new UnsupportedOperationException("Unsupported yet");
    }
    for (EncodingRetainingSection<?> section : dataSections) {
        payload.add(section.getEncodedForm());
        section.dispose();
    }
    QpidByteBuffer combined = QpidByteBuffer.concatenate(payload);
    payload.forEach(QpidByteBuffer::dispose);
    return combined;
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)

Example 25 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class MultiTransferTest method abortMultiTransferMessage.

// 
@Test
@SpecificationTest(section = "2.6.14", description = "The sender MAY indicate an aborted attempt to deliver a message by setting the abort flag on the last transfer." + "In this case the receiver MUST discard the message data that was transferred prior to the abort.")
public void abortMultiTransferMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final UnsignedInteger deliveryId = UnsignedInteger.ZERO;
        final Binary deliveryTag = new Binary("testTransfer".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(payloads[0]).transferDeliveryId(deliveryId).transferDeliveryTag(deliveryTag).transferMore(true).transfer().sync().transferPayload(null).transferMore(null).transferAborted(true).transfer();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        Response<?> latestResponse = interaction.consumeResponse(new Class<?>[] { null }).getLatestResponse();
        assertThat(latestResponse, is(nullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)39 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)30 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)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 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)19 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)19 Test (org.junit.Test)19 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)18 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)14 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)14 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 ArrayList (java.util.ArrayList)9 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)9 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)8 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)8