Search in sources :

Example 36 with Transfer

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

the class Session_1_0 method sendTransfer.

void sendTransfer(final Transfer xfr, final SendingLinkEndpoint endpoint) {
    _nextOutgoingId.incr();
    final boolean settled = Boolean.TRUE.equals(xfr.getSettled());
    UnsignedInteger deliveryId = UnsignedInteger.valueOf(_nextOutgoingDeliveryId++);
    xfr.setDeliveryId(deliveryId);
    if (!settled) {
        final UnsettledDelivery delivery = new UnsettledDelivery(xfr.getDeliveryTag(), endpoint);
        _outgoingDeliveryRegistry.addDelivery(deliveryId, delivery);
    }
    _remoteIncomingWindow--;
    try (QpidByteBuffer payload = xfr.getPayload()) {
        long remaining = payload == null ? 0 : (long) payload.remaining();
        int payloadSent = _connection.sendFrame(_sendingChannel, xfr, payload);
        if (payload != null) {
            while (payloadSent < remaining && payloadSent >= 0) {
                Transfer continuationTransfer = new Transfer();
                continuationTransfer.setHandle(xfr.getHandle());
                continuationTransfer.setRcvSettleMode(xfr.getRcvSettleMode());
                continuationTransfer.setState(xfr.getState());
                continuationTransfer.setPayload(payload);
                _nextOutgoingId.incr();
                _remoteIncomingWindow--;
                remaining = (long) payload.remaining();
                payloadSent = _connection.sendFrame(_sendingChannel, continuationTransfer, payload);
                continuationTransfer.dispose();
            }
        }
    } catch (OversizeFrameException e) {
        throw new ConnectionScopedRuntimeException(e);
    }
}
Also used : OversizeFrameException(org.apache.qpid.server.protocol.v1_0.framing.OversizeFrameException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) UnsettledDelivery(org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 37 with Transfer

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

the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error. If the source for the link to" + " the coordinator supports the rejected outcome, then the message MUST be rejected" + " with this outcome carrying the transaction-error.")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transferDeliveryId(UnsignedInteger.valueOf(1)).transfer();
        final Discharge discharge = new Discharge();
        discharge.setTxnId(txnState.getCurrentTransactionId());
        discharge.setFail(false);
        interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(2)).transferSettled(Boolean.FALSE).transferDeliveryTag(new Binary(("transaction-" + 2).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
        Disposition dischargeTransactionDisposition = getDispositionForDeliveryId(interaction, UnsignedInteger.valueOf(2));
        assertThat(dischargeTransactionDisposition.getSettled(), is(equalTo(true)));
        assertThat(dischargeTransactionDisposition.getState(), is(instanceOf(Rejected.class)));
        Rejected rejected = (Rejected) dischargeTransactionDisposition.getState();
        Error error = rejected.getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) 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) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 38 with Transfer

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

the class AnonymousTerminusTest method transferUnsettledToUnknownDestinationWhenRejectedOutcomeSupportedBySource.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " If the source of the link supports the rejected outcome," + " and the message has not already been settled by the sender, then the routing node" + " MUST reject the message." + " [...] the info field of error MUST contain an entry with symbolic key delivery-tag" + " and binary value of the delivery-tag of the message which caused the failure.")
@Test
public void transferUnsettledToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transfer().consumeResponse();
        Disposition disposition = interaction.getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(true));
        DeliveryState dispositionState = disposition.getState();
        assertThat(dispositionState, is(instanceOf(Rejected.class)));
        Rejected rejected = (Rejected) dispositionState;
        Error error = rejected.getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(error.getInfo(), is(notNullValue()));
        assertThat(error.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
    }
}
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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) 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) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 39 with Transfer

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

the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error." + " [...]" + " If the source does not support the rejected outcome, the transactional resource MUST" + " detach the link to the coordinator, with the detach performative carrying" + " the transaction-error")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachName("testTransactionCoordinator-" + txnState.getHandle()).attachHandle(txnState.getHandle()).attachInitialDeliveryCount(UnsignedInteger.ZERO).attachTarget(new Coordinator()).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachTarget(new Target()).attachName("link-" + linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transfer();
        final Discharge discharge = new Discharge();
        discharge.setTxnId(txnState.getCurrentTransactionId());
        discharge.setFail(false);
        interaction.transferHandle(txnState.getHandle()).transferSettled(Boolean.FALSE).transferDeliveryId(UnsignedInteger.valueOf(4)).transferDeliveryTag(new Binary(("transaction-" + 4).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
        Detach transactionCoordinatorDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
        Error transactionCoordinatorDetachError = transactionCoordinatorDetach.getError();
        assertThat(transactionCoordinatorDetachError, is(notNullValue()));
        assertThat(transactionCoordinatorDetachError.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) 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) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Coordinator(org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 40 with Transfer

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

the class AnonymousTerminusTest method transferPreSettledInTransactionToKnownDestination.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2. Sending A Message", description = "Messages sent over links into a routing node will be" + " forwarded to the node referenced in the to field of properties of the message" + " just as if a direct link has been established to that node.")
@Test
public void transferPreSettledInTransactionToKnownDestination() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(BrokerAdmin.TEST_QUEUE_NAME)).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transfer().txnDischarge(txnState, false);
        Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
        assertThat(receivedMessage, is(equalTo(TEST_MESSAGE_CONTENT)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Test (org.junit.Test)54 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)53 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)53 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)46 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)29 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)29 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)26 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)26 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)24 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)21 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)20 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)19 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)19 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)18 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)14 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)11 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11