Search in sources :

Example 1 with Flow

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

the class SendingLinkEndpoint method receiveFlow.

@Override
public void receiveFlow(final Flow flow) {
    UnsignedInteger receiverDeliveryCount = flow.getDeliveryCount();
    UnsignedInteger receiverLinkCredit = flow.getLinkCredit();
    setDrain(flow.getDrain());
    Map<Symbol, Object> properties = flow.getProperties();
    if (properties != null) {
        final Binary transactionId = (Binary) properties.get(Symbol.valueOf("txn-id"));
        if (transactionId != null) {
            try {
                getSession().getTransaction(transactionId);
            } catch (UnknownTransactionException e) {
                close(new Error(TransactionError.UNKNOWN_ID, e.getMessage()));
                return;
            }
        }
        _transactionId = transactionId;
    }
    if (receiverDeliveryCount == null) {
        setLinkCredit(receiverLinkCredit);
    } else {
        // 2.6.7 Flow Control : link_credit_snd := delivery_count_rcv + link_credit_rcv - delivery_count_snd
        SequenceNumber limit = new SequenceNumber(receiverDeliveryCount.intValue()).add(receiverLinkCredit.intValue());
        if (limit.compareTo(getDeliveryCount()) <= 0) {
            setLinkCredit(UnsignedInteger.valueOf(0));
        } else {
            setLinkCredit(limit.subtract(getDeliveryCount().intValue()).unsignedIntegerValue());
        }
    }
    // send flow when echo=true or drain=true but link credit is zero
    boolean sendFlow = Boolean.TRUE.equals(flow.getEcho()) || (Boolean.TRUE.equals(flow.getDrain()) && getLinkCredit().equals(UnsignedInteger.ZERO));
    flowStateChanged();
    if (sendFlow) {
        sendFlow();
    }
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 2 with Flow

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

the class AbstractLinkEndpoint method sendFlow.

private void sendFlow(boolean echo) {
    if (_state == State.ATTACHED || _state == State.ATTACH_SENT) {
        Flow flow = new Flow();
        flow.setDeliveryCount(_deliveryCount.unsignedIntegerValue());
        flow.setEcho(echo);
        if (_stopped) {
            flow.setLinkCredit(UnsignedInteger.ZERO);
            flow.setDrain(true);
            _lastSentCreditLimit = _deliveryCount.unsignedIntegerValue();
        } else {
            flow.setLinkCredit(_linkCredit);
            _lastSentCreditLimit = _linkCredit.add(_deliveryCount.unsignedIntegerValue());
            flow.setDrain(_drain);
        }
        flow.setAvailable(_available);
        flow.setHandle(getLocalHandle());
        getSession().sendFlow(flow);
    }
}
Also used : Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Example 3 with Flow

use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow 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 4 with Flow

use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow 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 5 with Flow

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

the class AttachTest method attachReceiverWithNullTarget.

@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
@BrokerSpecific(kind = BrokerAdmin.KIND_BROKER_J)
public void attachReceiverWithNullTarget() throws Exception {
    String queueName = BrokerAdmin.TEST_QUEUE_NAME;
    getBrokerAdmin().createQueue(queueName);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        Interaction interaction = transport.newInteraction();
        final Attach responseAttach = interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(queueName).attachTarget(null).attach().consumeResponse().getLatestResponse(Attach.class);
        assertThat(responseAttach.getName(), is(notNullValue()));
        assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
        assertThat(responseAttach.getRole(), is(Role.SENDER));
        assertThat(responseAttach.getInitialDeliveryCount(), is((UnsignedInteger.ZERO)));
        assertThat(responseAttach.getSource(), is(nullValue()));
        assertThat(responseAttach.getTarget(), is(nullValue()));
        final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
        assertThat(responseDetach.getClosed(), is(true));
        assertThat(responseDetach.getError(), is(notNullValue()));
        assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
        final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
        assertThat(endResponse.getError(), is(notNullValue()));
    // QPID-7954
    // assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
    }
}
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) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) 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)

Aggregations

Test (org.junit.Test)49 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)47 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)44 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)42 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)37 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)31 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)24 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)22 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)17 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)11 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)11 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)10 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)10 Ignore (org.junit.Ignore)8 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)7 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)5 BrokerAdmin (org.apache.qpid.tests.utils.BrokerAdmin)5