Search in sources :

Example 71 with Begin

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

the class FlowTest method flowWithUnknownHandle.

@Test
@SpecificationTest(section = "2.7.4", description = "If set to a handle that is not currently associated with an attached link, the recipient" + " MUST respond by ending the session with an unattached-handle session error.")
public void flowWithUnknownHandle() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        End responseEnd = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).flowEcho(true).flowHandle(UnsignedInteger.ONE).flow().consumeResponse().getLatestResponse(End.class);
        assertThat(responseEnd.getError(), is(notNullValue()));
        assertThat(responseEnd.getError().getCondition(), is(equalTo(SessionError.UNATTACHED_HANDLE)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 72 with Begin

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

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

the class FlowTest method linkEchoFlow.

@Test
@SpecificationTest(section = "2.7.4", description = "If set to true then the receiver SHOULD send its state at the earliest convenient opportunity.")
public void linkEchoFlow() throws Exception {
    getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Flow responseFlow = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).flowEcho(true).flowHandleFromLinkHandle().flowAvailable(UnsignedInteger.valueOf(10)).flowDeliveryCount(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ZERO).flow().consumeResponse().getLatestResponse(Flow.class);
        assertThat(responseFlow.getEcho(), not(equalTo(Boolean.TRUE)));
        assertThat(responseFlow.getHandle(), is(notNullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) 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 74 with Begin

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

use of org.apache.qpid.server.protocol.v1_0.type.transport.Begin 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)

Aggregations

Test (org.junit.Test)76 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)74 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)74 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)57 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)51 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)35 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)30 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)24 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)23 InetSocketAddress (java.net.InetSocketAddress)19 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)18 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)15 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)11 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 Ignore (org.junit.Ignore)8 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)7