Search in sources :

Example 21 with Received

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

the class TransferTest method transferMultipleDeliveries.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void transferMultipleDeliveries() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(2)));
        interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(new Binary("A".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("B".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.valueOf(2)).transferDeliveryTag(new Binary("C".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer();
        TreeSet<UnsignedInteger> expectedDeliveryIds = Sets.newTreeSet(Arrays.asList(UnsignedInteger.ZERO, UnsignedInteger.ONE, UnsignedInteger.valueOf(2)));
        assertDeliveries(interaction, expectedDeliveryIds);
        // verify that no unexpected performative is received by closing
        interaction.doCloseConnection();
    }
}
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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 22 with Received

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

the class OpenTest method idleTimeout.

@Test
@SpecificationTest(section = "2.4.5", description = "Connections are subject to an idle timeout threshold.")
public void idleTimeout() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction();
        final int idleTimeOut = 1000;
        Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openIdleTimeOut(idleTimeOut).open().consumeResponse().getLatestResponse(Open.class);
        final int peerIdleTimeOut = responseOpen.getIdleTimeOut().intValue();
        assertThat(peerIdleTimeOut, is(either(equalTo(0)).or(greaterThanOrEqualTo(idleTimeOut))));
        final long startTime = System.currentTimeMillis();
        interaction.consumeResponse(EmptyResponse.class);
        final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
        assertThat("Empty frame not received within expected time frame", ((int) actualHeartbeatDelay / 1000), is(both(greaterThanOrEqualTo(peerIdleTimeOut)).and(lessThanOrEqualTo(peerIdleTimeOut * 2))));
        if (peerIdleTimeOut > 0) {
            interaction.emptyFrame();
        }
        interaction.doCloseConnection();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) 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 23 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received 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

AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)7 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)6 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)6 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)6 Test (org.junit.Test)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)5 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)5 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)5 ConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 ConnectionError (org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)4 InetSocketAddress (java.net.InetSocketAddress)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)3 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)3 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)3 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)3