Search in sources :

Example 6 with DeliveryState

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

the class Session_1_0 method updateDisposition.

void updateDisposition(final LinkEndpoint<?, ?> linkEndpoint, final Binary deliveryTag, final DeliveryState state, final boolean settled) {
    final UnsignedInteger deliveryId = getDeliveryId(deliveryTag, linkEndpoint);
    updateDisposition(linkEndpoint.getRole(), deliveryId, deliveryId, state, settled);
}
Also used : UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 7 with DeliveryState

use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState 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 {
    Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateOpen().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(getTestName())));
        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();
        final String content = getTestName() + "_2";
        Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, content);
        assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(content)));
    }
}
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 8 with DeliveryState

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

the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If set to true [incomplete-unsettled] indicates that the unsettled map provided is not complete. " + "When the map is incomplete the recipient of the map cannot take the absence of a delivery tag from " + "the map as evidence of settlement. On receipt of an incomplete unsettled map a sending endpoint MUST " + "NOT send any new deliveries (i.e. deliveries where resume is not set to true) to its partner (and " + "a receiving endpoint which sent an incomplete unsettled map MUST detach with an error on " + "receiving a transfer which does not have the resume flag set to true).")
public void rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
    final String destination = BrokerAdmin.TEST_QUEUE_NAME;
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        // 0. Open connection with small max-frame-size
        final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).negotiateOpen().getLatestResponse(Open.class);
        interaction.begin().consumeResponse(Begin.class);
        // 1. attach with ReceiverSettleMode.SECOND
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond).consumeResponse(Flow.class);
        // 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
        // assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
        interaction.transferHandle(linkHandle1).transferPayloadData(getTestName());
        Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
        for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
            final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
            final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
            assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
            localUnsettled.put(deliveryTag, null);
        }
        // 3. detach the link
        interaction.detach().consumeResponse(Detach.class);
        // 4. resume the link
        final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
        Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
        final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
        assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
        // 5. ensure attach has incomplete-unsettled
        final Attach responseAttach = (Attach) latestResponse.getBody();
        assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
        // 6. send new transfer
        final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
        final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detachWithError.getError(), is(notNullValue()));
        final Error detachError = detachWithError.getError();
        assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 9 with DeliveryState

use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState 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 {
    Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateOpen().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(getTestName())));
        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();
        final String content = getTestName() + "_2";
        Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, content);
        assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(content)));
    }
}
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 10 with DeliveryState

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

the class AnonymousTerminusTest method transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource.

@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(getNonExistingDestinationName())).transferDeliveryTag(_deliveryTag).transferTransactionalStateFromCurrentTransaction().transferSettled(Boolean.FALSE).transfer();
        final Disposition disposition = interaction.consume(Disposition.class, Flow.class);
        assertThat(disposition.getSettled(), is(true));
        DeliveryState dispositionState = disposition.getState();
        assertThat(dispositionState, is(instanceOf(TransactionalState.class)));
        final TransactionalState receivedTxnState = (TransactionalState) dispositionState;
        assertThat(receivedTxnState.getOutcome(), is(instanceOf(Rejected.class)));
        final Error rejectedError = ((Rejected) receivedTxnState.getOutcome()).getError();
        assertThat(rejectedError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(rejectedError.getInfo(), is(notNullValue()));
        assertThat(rejectedError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
        interaction.txnDischarge(false);
        assertThat(interaction.getCoordinatorLatestDeliveryState(), is(instanceOf(Accepted.class)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)15 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)13 Test (org.junit.Test)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 HashMap (java.util.HashMap)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)8 Ignore (org.junit.Ignore)7 Map (java.util.Map)6 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)6 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)6 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)5 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5