Search in sources :

Example 31 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target 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);
    String messageContent1 = "Test1";
    String messageContent2 = "Test2";
    String messageContent3 = "Test2";
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent1);
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent2);
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent3);
    final InetSocketAddress addr = brokerAdmin.getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class);
        Attach remoteAttach = interaction.getLatestResponse(Attach.class);
        UnsignedInteger remoteHandle = remoteAttach.getHandle();
        assertThat(remoteHandle, is(notNullValue()));
        UnsignedInteger delta = UnsignedInteger.ONE;
        UnsignedInteger incomingWindow = UnsignedInteger.valueOf(3);
        Object receivedMessageContent1 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingId(UnsignedInteger.ZERO).flowLinkCredit(delta).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent1, is(equalTo(messageContent1)));
        assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ZERO)));
        Object receivedMessageContent2 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(delta).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent2, is(equalTo(messageContent2)));
        assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ONE)));
        // send session flow with echo=true to verify that no message is delivered without issuing a credit
        Flow responseFlow = interaction.flowNextIncomingId(UnsignedInteger.valueOf(2)).flowLinkCredit(null).flowHandle(null).flowEcho(Boolean.TRUE).flow().consumeResponse().getLatestResponse(Flow.class);
        assertThat(responseFlow.getHandle(), is(nullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) BrokerAdmin(org.apache.qpid.tests.utils.BrokerAdmin) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) 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)

Example 32 with Target

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

the class Interaction method attachTargetAddress.

public Interaction attachTargetAddress(final String address) {
    final Target target = ((Target) _attach.getTarget());
    target.setAddress(address);
    _attach.setTarget(target);
    return this;
}
Also used : BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target)

Aggregations

Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)11 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)11 Test (org.junit.Test)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)10 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)9 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 StoreException (org.apache.qpid.server.store.StoreException)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)6 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)6 PreparedStatement (java.sql.PreparedStatement)5 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)5 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)4 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)4