Search in sources :

Example 1 with BrokerAdmin

use of org.apache.qpid.tests.utils.BrokerAdmin in project qpid-broker-j by apache.

the class FlowTest method synchronousGetWithTimeoutNonEmptyQueue.

@Test
@SpecificationTest(section = "2.6.8", description = "Synchronous get with a timeout is accomplished by incrementing the link-credit," + " sending the updated flow state and waiting for the link-credit to be consumed." + " When the desired time has elapsed the receiver then sets the drain flag and sends" + " the newly updated flow state again, while continuing to wait for the link-credit" + " to be consumed.")
public void synchronousGetWithTimeoutNonEmptyQueue() throws Exception {
    BrokerAdmin brokerAdmin = getBrokerAdmin();
    brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    String messageContent = "Test";
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
    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()));
        Object receivedMessageContent = interaction.flowIncomingWindow(UnsignedInteger.valueOf(1)).flowNextIncomingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowDrain(Boolean.FALSE).flowEcho(Boolean.FALSE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent, is(equalTo(messageContent)));
        assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ZERO)));
        Flow responseFlow = interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowDrain(Boolean.TRUE).flowEcho(Boolean.FALSE).flowHandleFromLinkHandle().flow().consumeResponse().getLatestResponse(Flow.class);
        assertThat(responseFlow.getHandle(), is(equalTo(remoteHandle)));
        assertThat(responseFlow.getLinkCredit(), is(equalTo(UnsignedInteger.ZERO)));
    }
}
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 2 with BrokerAdmin

use of org.apache.qpid.tests.utils.BrokerAdmin in project qpid-broker-j by apache.

the class FlowTest method stoppingALink.

@Test
@SpecificationTest(section = "2.6.10", description = "Stopping the transfers on a given link is accomplished by updating the link-credit" + " to be zero and sending the updated flow state. [...]" + " The echo field of the flow frame MAY be used to request the sender’s flow state" + " be echoed back. This MAY be used to determine when the link has finally quiesced.")
public void stoppingALink() throws Exception {
    BrokerAdmin brokerAdmin = getBrokerAdmin();
    brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    String messageContent1 = "Test1";
    String messageContent2 = "Test2";
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent1);
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent2);
    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()));
        Object receivedMessageContent1 = interaction.flowIncomingWindow(UnsignedInteger.valueOf(2)).flowNextIncomingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(receivedMessageContent1, is(equalTo(messageContent1)));
        assertThat(interaction.getLatestDeliveryId(), is(equalTo(UnsignedInteger.ZERO)));
        Flow responseFlow = interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ZERO).flowHandleFromLinkHandle().flowEcho(Boolean.TRUE).flow().consumeResponse().getLatestResponse(Flow.class);
        assertThat(responseFlow.getHandle(), is(equalTo(remoteHandle)));
        assertThat(responseFlow.getLinkCredit(), is(equalTo(UnsignedInteger.ZERO)));
    }
}
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 3 with BrokerAdmin

use of org.apache.qpid.tests.utils.BrokerAdmin in project qpid-broker-j by apache.

the class AnonymousTerminusTest method setUp.

@Before
public void setUp() {
    final BrokerAdmin brokerAdmin = getBrokerAdmin();
    brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    _brokerAddress = brokerAdmin.getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    _deliveryTag = new Binary("testTag".getBytes(StandardCharsets.UTF_8));
}
Also used : BrokerAdmin(org.apache.qpid.tests.utils.BrokerAdmin) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Before(org.junit.Before)

Example 4 with BrokerAdmin

use of org.apache.qpid.tests.utils.BrokerAdmin in project qpid-broker-j by apache.

the class FlowTest method drainWithZeroCredits.

@Test
@SpecificationTest(section = "2.6.7", description = "The drain flag indicates how the sender SHOULD behave when insufficient messages are" + " available to consume the current link-credit. If set, the sender will" + " (after sending all available messages) advance the delivery-count as much as possible," + " consuming all link-credit, and send the flow state to the receiver.")
public void drainWithZeroCredits() throws Exception {
    BrokerAdmin brokerAdmin = getBrokerAdmin();
    brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    brokerAdmin.putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "Test1");
    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()));
        Flow responseFlow = interaction.flowIncomingWindow(UnsignedInteger.valueOf(2)).flowNextIncomingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ZERO).flowDrain(Boolean.TRUE).flowHandleFromLinkHandle().flow().consumeResponse().getLatestResponse(Flow.class);
        assertThat(responseFlow.getHandle(), is(equalTo(remoteHandle)));
        assertThat(responseFlow.getLinkCredit(), is(equalTo(UnsignedInteger.ZERO)));
    }
}
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 5 with BrokerAdmin

use of org.apache.qpid.tests.utils.BrokerAdmin 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)

Aggregations

BrokerAdmin (org.apache.qpid.tests.utils.BrokerAdmin)5 InetSocketAddress (java.net.InetSocketAddress)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)4 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)4 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)4 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)4 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)4 Test (org.junit.Test)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)1 Before (org.junit.Before)1