Search in sources :

Example 46 with Disposition

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

the class ResumeDeliveriesTest method incompleteUnsettledReceiving.

@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 incompleteUnsettledReceiving() throws Exception {
    for (int i = 0; i < MIN_MAX_FRAME_SIZE; i++) {
        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT + "-" + i);
    }
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        // 1. open with small max-frame=512, begin, attach receiver with
        // with rcv-settle-mode=second, snd-settle-mode=unsettled,
        // flow with incoming-window=MAX_INTEGER and link-credit=MAX_INTEGER
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSndSettleMode(SenderSettleMode.UNSETTLED).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class);
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.valueOf(Integer.MAX_VALUE)).flowLinkCredit(UnsignedInteger.valueOf(Integer.MAX_VALUE)).flowHandleFromLinkHandle().flow();
        // 2. Receive transfers
        final Map<Binary, DeliveryState> localUnsettled = new HashMap<>();
        for (int i = 0; i < MIN_MAX_FRAME_SIZE; ) {
            Response<?> response = interaction.consumeResponse().getLatestResponse();
            if (response.getBody() instanceof Transfer) {
                assertThat(response.getBody(), Matchers.is(instanceOf(Transfer.class)));
                Transfer responseTransfer = (Transfer) response.getBody();
                assertThat(responseTransfer.getMore(), is(not(equalTo(true))));
                assertThat(responseTransfer.getSettled(), is(not(equalTo(true))));
                localUnsettled.putIfAbsent(responseTransfer.getDeliveryTag(), responseTransfer.getState());
                i++;
            } else if (response.getBody() instanceof Flow || response.getBody() instanceof Disposition) {
            // ignore
            } else {
                fail("Unexpected frame " + response.getBody());
            }
        }
        // 3. detach the link
        interaction.detach().consumeResponse(Detach.class);
        // 4. resume the link
        final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
        Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
        final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
        assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
        final Attach resumingAttach = (Attach) latestResponse.getBody();
        final Map<Binary, DeliveryState> remoteUnsettled = resumingAttach.getUnsettled();
        assertThat(remoteUnsettled, is(notNullValue()));
        assertThat(remoteUnsettled.keySet(), is(not(empty())));
        for (Binary deliveryTag : remoteUnsettled.keySet()) {
            assertThat(deliveryTag, isIn(localUnsettled.keySet()));
        }
        assertThat(resumingAttach.getIncompleteUnsettled(), is(equalTo(true)));
        interaction.flowHandle(linkHandle2).flow();
        boolean received = false;
        while (!received) {
            Response<?> nextResponse = interaction.consumeResponse().getLatestResponse();
            assertThat(nextResponse, is(notNullValue()));
            if (nextResponse.getBody() instanceof Transfer) {
                assertThat(nextResponse.getBody(), is(instanceOf(Transfer.class)));
                Transfer responseTransfer = (Transfer) nextResponse.getBody();
                assertThat(responseTransfer.getMore(), is(not(equalTo(true))));
                assertThat(responseTransfer.getSettled(), is(not(equalTo(true))));
                assertThat(responseTransfer.getDeliveryTag(), is(equalTo(sampleLocalUnsettled)));
                received = true;
            } else if (nextResponse.getBody() instanceof Flow || nextResponse.getBody() instanceof Disposition) {
            // ignore
            } else {
                fail("Unexpected frame " + nextResponse.getBody());
            }
        }
        interaction.doCloseConnection();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) 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) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 47 with Disposition

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

the class Interaction method txnDischarge.

public Interaction txnDischarge(final InteractionTransactionalState txnState, boolean failed) throws Exception {
    final Discharge discharge = new Discharge();
    discharge.setTxnId(txnState.getCurrentTransactionId());
    discharge.setFail(failed);
    Transfer transfer = createTransactionTransfer(txnState.getHandle());
    transferPayload(transfer, discharge);
    sendPerformativeAndChainFuture(transfer, _sessionChannel);
    Disposition declareTransactionDisposition = null;
    Flow coordinatorFlow = null;
    do {
        consumeResponse(Disposition.class, Flow.class);
        Response<?> response = getLatestResponse();
        if (response.getBody() instanceof Disposition) {
            declareTransactionDisposition = (Disposition) response.getBody();
        }
        if (response.getBody() instanceof Flow) {
            final Flow flowResponse = (Flow) response.getBody();
            if (flowResponse.getHandle().equals(txnState.getHandle())) {
                coordinatorFlow = flowResponse;
            }
        }
    } while (declareTransactionDisposition == null || coordinatorFlow == null);
    assertThat(declareTransactionDisposition.getSettled(), is(equalTo(true)));
    assertThat(declareTransactionDisposition.getState(), is(instanceOf(Accepted.class)));
    txnState.setLastTransactionId(null);
    return this;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Example 48 with Disposition

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

the class Interaction method txnDeclare.

public Interaction txnDeclare(final InteractionTransactionalState txnState) throws Exception {
    Transfer transfer = createTransactionTransfer(txnState.getHandle());
    transferPayload(transfer, new Declare());
    sendPerformativeAndChainFuture(transfer, _sessionChannel);
    consumeResponse(Disposition.class);
    Disposition declareTransactionDisposition = getLatestResponse(Disposition.class);
    assertThat(declareTransactionDisposition.getSettled(), is(equalTo(true)));
    assertThat(declareTransactionDisposition.getState(), is(instanceOf(Declared.class)));
    Binary transactionId = ((Declared) declareTransactionDisposition.getState()).getTxnId();
    assertThat(transactionId, is(notNullValue()));
    consumeResponse(Flow.class);
    txnState.setLastTransactionId(transactionId);
    return this;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Declared(org.apache.qpid.server.protocol.v1_0.type.transaction.Declared)

Example 49 with Disposition

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

the class Interaction method copyDisposition.

private Disposition copyDisposition(final Disposition disposition) {
    final Disposition dispositionCopy = new Disposition();
    dispositionCopy.setRole(disposition.getRole());
    dispositionCopy.setFirst(disposition.getFirst());
    dispositionCopy.setLast(disposition.getLast());
    dispositionCopy.setSettled(disposition.getSettled());
    dispositionCopy.setState(disposition.getState());
    dispositionCopy.setBatchable(disposition.getBatchable());
    return dispositionCopy;
}
Also used : Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)

Example 50 with Disposition

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

the class ResumeDeliveriesTest method resumeReceivingLinkEmptyUnsettled.

@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 resumeReceivingLinkEmptyUnsettled() 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).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).disposition();
        Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
        interaction.attachUnsettled(new HashMap<>()).attach().consumeResponse(Attach.class);
        Attach attach = interaction.getLatestResponse(Attach.class);
        Map<Binary, DeliveryState> unsettled = attach.getUnsettled();
        assertThat(unsettled.entrySet(), empty());
    }
}
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) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)44 Test (org.junit.Test)44 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)42 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)40 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)37 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)29 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)23 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)20 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)20 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)18 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)17 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)17 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)9 Ignore (org.junit.Ignore)9 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8