Search in sources :

Example 26 with Accepted

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

the class TransactionalTransferTest method sendTransactionalPostingReceiverSettlesSecond.

@Test
@SpecificationTest(section = "4.4.4", description = "Transactional Posting[...]the transaction controller wishes to associate an outgoing" + " transfer with a transaction, it MUST set the state of the transfer with a" + "transactional-state carrying the appropriate transaction identifier.")
public void sendTransactionalPostingReceiverSettlesSecond() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final Interaction interaction = transport.newInteraction();
        Disposition responseDisposition = interaction.negotiateOpen().begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachHandle(linkHandle).attach().consumeResponse(Attach.class).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond).consumeResponse(Flow.class).transferDeliveryId().transferHandle(linkHandle).transferPayloadData(getTestName()).transferTransactionalStateFromCurrentTransaction().transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
        assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
        assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
        assertThat(responseDisposition.getState(), is(instanceOf(TransactionalState.class)));
        assertThat(((TransactionalState) responseDisposition.getState()).getOutcome(), is(instanceOf(Accepted.class)));
        interaction.dispositionRole(Role.SENDER).dispositionSettled(true).dispositionTransactionalStateFromCurrentTransaction(new Accepted()).disposition();
        interaction.txnDischarge(false);
        assertThat(interaction.getCoordinatorLatestDeliveryState(), is(instanceOf(Accepted.class)));
    }
    assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(getTestName())));
}
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) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) 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 27 with Accepted

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

the class FilterTest method selectorFilter.

@Test
@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(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().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), getTestName());
            interaction.transferPayload(payload).transferSettled(true).transfer();
        }
        interaction.detachClose(true).detach().close().sync();
    }
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().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(getTestName())));
        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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) 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 28 with Accepted

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

the class TransactionTimeoutTest method transactionalRetirementTimeout.

@Test
public void transactionalRetirementTimeout() throws Exception {
    Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO).txnDeclare().attachRole(Role.RECEIVER).attachHandle(UnsignedInteger.ONE).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.MAX_VALUE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.MAX_VALUE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, is(equalTo(getTestName())));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionTransactionalStateFromCurrentTransaction(new Accepted()).disposition().sync();
        Response<?> response = interaction.consumeResponse(Close.class, Flow.class).getLatestResponse();
        Close responseClose;
        if (response.getBody() instanceof Close) {
            responseClose = (Close) response.getBody();
        } else {
            responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
        }
        assertThat(responseClose.getError(), is(notNullValue()));
        assertThat(responseClose.getError().getCondition(), equalTo(TransactionError.TRANSACTION_TIMEOUT));
    }
    assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(getTestName())));
}
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) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test)

Example 29 with Accepted

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

the class FlowTest method asynchronousNotification.

@Test
@SpecificationTest(section = "2.6.9", description = "Asynchronous notification can be accomplished as follows." + " The receiver maintains a target amount of link-credit for that link." + " As transfer arrive on the link, the sender’s link-credit decreases" + " as the delivery-count increases. When the sender’s link-credit falls below a threshold," + " the flow state MAY be sent to increase the sender’s link-credit back" + " to the desired target amount.")
public void asynchronousNotification() throws Exception {
    BrokerAdmin brokerAdmin = getBrokerAdmin();
    brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    final String[] contents = Utils.createTestMessageContents(3, getTestName());
    Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, contents);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        Interaction interaction = transport.newInteraction().negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class);
        UnsignedInteger delta = UnsignedInteger.ONE;
        UnsignedInteger incomingWindow = UnsignedInteger.valueOf(3);
        Object receivedMessageContent1 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flowLinkCredit(delta).flowHandleFromLinkHandle().flowDeliveryCount().flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent1, is(equalTo(contents[0])));
        UnsignedInteger firstDeliveryId = interaction.getLatestDeliveryId();
        Object receivedMessageContent2 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flowLinkCredit(delta).flowHandleFromLinkHandle().flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowDeliveryCount().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent2, is(equalTo(contents[1])));
        UnsignedInteger secondDeliveryId = interaction.getLatestDeliveryId();
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(firstDeliveryId).dispositionLast(secondDeliveryId).dispositionState(new Accepted()).disposition();
        // detach link and consume detach to verify that no transfer was delivered
        interaction.detachClose(true).detach().consume(Detach.class, Flow.class);
    }
    assertThat(Utils.receiveMessage(brokerAdmin, BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(contents[2])));
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) BrokerAdmin(org.apache.qpid.tests.utils.BrokerAdmin) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 30 with Accepted

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

the class TransactionalTransferTest method receiveTransactionalRetirementReceiverSettleSecond.

@Ignore("TODO disposition is currently not being sent by Broker")
@Test
@SpecificationTest(section = "4.4.2", description = "Transactional Retirement[...] The transaction controller might" + "wish to associate the outcome of a delivery with a transaction.")
public void receiveTransactionalRetirementReceiverSettleSecond() throws Exception {
    Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.RECEIVER).attachHandle(UnsignedInteger.ONE).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, is(equalTo(getTestName())));
        Disposition settledDisposition = interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionTransactionalStateFromCurrentTransaction(new Accepted()).disposition().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
        assertThat(settledDisposition.getSettled(), is(true));
        assertThat(settledDisposition.getState(), is(instanceOf(TransactionalState.class)));
        assertThat(((TransactionalState) settledDisposition.getState()).getOutcome(), is(instanceOf(Accepted.class)));
        interaction.txnDischarge(false);
        assertThat(interaction.getCoordinatorLatestDeliveryState(), is(instanceOf(Accepted.class)));
    }
}
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) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Ignore(org.junit.Ignore) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)30 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)25 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)25 Test (org.junit.Test)25 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)23 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)18 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)12 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)11 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)7 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)4 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)4 BrokerAdmin (org.apache.qpid.tests.utils.BrokerAdmin)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3