Search in sources :

Example 41 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 transferUnsettledInTransactionToKnownDestination.

@Test
public void transferUnsettledInTransactionToKnownDestination() 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.FALSE).transfer();
        Disposition disposition = interaction.consumeResponse().getLatestResponse(Disposition.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(Accepted.class)));
        interaction.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) 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) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 42 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 transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.

@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() 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).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryId(UnsignedInteger.valueOf(1)).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.FALSE).transfer();
        Detach senderLinkDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
        Error senderLinkDetachError = senderLinkDetach.getError();
        assertThat(senderLinkDetachError, is(notNullValue()));
        assertThat(senderLinkDetachError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(senderLinkDetachError.getInfo(), is(notNullValue()));
        assertThat(senderLinkDetachError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
        final Discharge discharge = new Discharge();
        discharge.setTxnId(txnState.getCurrentTransactionId());
        discharge.setFail(false);
        interaction.transferHandle(txnState.getHandle()).transferSettled(Boolean.FALSE).transferDeliveryId(UnsignedInteger.valueOf(2)).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) 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)

Example 43 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 transferPreSettledToUnknownDestination.

@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." + " [...] the message has already been settled by the sender," + " then the routing node MUST detach the link with an error." + " [...] 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 transferPreSettledToUnknownDestination() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination("Unknown")).transferSettled(Boolean.TRUE).transferDeliveryTag(_deliveryTag).transfer();
        Detach detach = interaction.consumeResponse().getLatestResponse(Detach.class);
        Error error = detach.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) 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) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 44 with Transfer

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

the class FilterTest method selectorFilter.

@Test
@BrokerSpecific(kind = KIND_BROKER_J)
@SpecificationTest(section = "3.5.1", description = "A source can restrict the messages transferred from a source by specifying a filter.")
public void selectorFilter() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(1)));
        for (int i = 0; i < 2; i++) {
            QpidByteBuffer payload = generateMessagePayloadWithApplicationProperties(Collections.singletonMap("index", i), TEST_MESSAGE_CONTENT);
            interaction.transferPayload(payload).transferSettled(true).transfer();
        }
        interaction.detachClose(true).detach().close().sync();
    }
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSourceFilter(Collections.singletonMap(Symbol.valueOf("selector-filter"), new JMSSelectorFilter("index=1"))).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
        Object data = interaction.receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Map<String, Object> applicationProperties = interaction.getLatestDeliveryApplicationProperties();
        assertThat(applicationProperties, is(notNullValue()));
        assertThat(applicationProperties.get("index"), is(equalTo(1)));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition();
        interaction.close().sync();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) JMSSelectorFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) 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) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) BrokerSpecific(org.apache.qpid.tests.utils.BrokerSpecific) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 45 with Transfer

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

the class MessageFormat method differentMessageFormatOnSameDeliveryFails.

@Test
@SpecificationTest(section = "2.7.5", description = "message-format: " + "This field MUST be specified for the first transfer of a multi-transfer message and can " + "only be omitted for continuation transfers. It is an error if the message-format on a " + "continuation transfer differs from the message-format on the first transfer of a delivery.")
public void differentMessageFormatOnSameDeliveryFails() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final Response<?> latestResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferMore(true).transferMessageFormat(UnsignedInteger.ZERO).transferPayload(payloads[0]).transfer().consumeResponse(null, Flow.class, Disposition.class).transferDeliveryTag(null).transferDeliveryId(null).transferMore(false).transferMessageFormat(UnsignedInteger.ONE).transferPayload(payloads[1]).transfer().consumeResponse(Detach.class, End.class, Close.class).getLatestResponse();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        assertThat(latestResponse, is(notNullValue()));
        final Object responseBody = latestResponse.getBody();
        final Error error;
        if (responseBody instanceof Detach) {
            error = ((Detach) responseBody).getError();
        } else if (responseBody instanceof End) {
            error = ((End) responseBody).getError();
        } else if (responseBody instanceof Close) {
            error = ((Close) responseBody).getError();
        } else {
            fail(String.format("Expected response of either Detach, End, or Close. Got '%s'", responseBody));
            error = null;
        }
        assertThat(error, is(notNullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) 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