Search in sources :

Example 51 with FrameTransport

use of org.apache.qpid.tests.protocol.v1_0.FrameTransport in project qpid-broker-j by apache.

the class TransactionalTransferTest method receiveTransactionalRetirementDispositionFailsDueToUnknownTransactionId.

@Test
@SpecificationTest(section = "4.4.2", description = "Transactional Retirement[...]" + " To associate an outcome with a transaction the controller" + " sends a disposition performative which sets the state" + " of the delivery to a transactional-state with the desired" + " transaction identifier and the outcome to be applied" + " upon a successful discharge.")
public void receiveTransactionalRetirementDispositionFailsDueToUnknownTransactionId() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        List<Transfer> transfers = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.RECEIVER).attachHandle(UnsignedInteger.ONE).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().getLatestDelivery();
        UnsignedInteger deliveryId = transfers.get(0).getDeliveryId();
        assertThat(deliveryId, is(notNullValue()));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Response<?> response = interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionTransactionalState(integerToBinary(Integer.MAX_VALUE), new Accepted()).dispositionFirst(deliveryId).disposition().consumeResponse().getLatestResponse();
        assertUnknownTransactionIdError(response);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) 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 52 with FrameTransport

use of org.apache.qpid.tests.protocol.v1_0.FrameTransport in project qpid-broker-j by apache.

the class ProtocolHeaderTest method successfulHeaderExchange.

@Test
@SpecificationTest(section = "2.2", description = "Prior to sending any frames on a connection, each peer MUST start by sending a protocol header that indicates " + "the protocol version used on the connection. The protocol header consists of the upper case ASCII letters “AMQP” " + "followed by a protocol id of zero, followed by three unsigned bytes representing the major, minor, and revision of " + "the protocol version (currently 1 (MAJOR), 0 (MINOR), 0 (REVISION)).")
public void successfulHeaderExchange() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        byte[] protocolHeader = "AMQP\0\1\0\0".getBytes(StandardCharsets.UTF_8);
        final byte[] response = transport.newInteraction().protocolHeader(protocolHeader).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
        assertArrayEquals("Unexpected protocol header response", protocolHeader, response);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 53 with FrameTransport

use of org.apache.qpid.tests.protocol.v1_0.FrameTransport in project qpid-broker-j by apache.

the class IdleTimeoutTest method brokerClosesIdleConnection.

@Test
@SpecificationTest(section = "2.4.5", description = "If the [idle timeout threshold] threshold is exceeded, then a peer SHOULD try to" + "gracefully close the connection using a close frame with an error explaining why.")
public void brokerClosesIdleConnection() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction();
        Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse().getLatestResponse(Open.class);
        assertThat(responseOpen.getIdleTimeOut().intValue(), is(equalTo(IDLE_TIMEOUT_MS)));
        // TODO: defect - broker ought to be sending a close performative but it just closes the socket.
        interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
    }
}
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 54 with FrameTransport

use of org.apache.qpid.tests.protocol.v1_0.FrameTransport in project qpid-broker-j by apache.

the class IdleTimeoutTest method idleLine.

@Test
@SpecificationTest(section = "2.4.5", description = "If a peer needs to satisfy the need to send traffic to prevent idle timeout, and has " + "nothing to send, it MAY send an empty frame.")
public void idleLine() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction();
        Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openIdleTimeOut(IDLE_TIMEOUT_MS).open().consumeResponse().getLatestResponse(Open.class);
        assertThat(responseOpen.getIdleTimeOut().intValue(), is(equalTo(IDLE_TIMEOUT_MS)));
        // Reflect the broker's empty frames
        interaction.consumeResponse(EmptyResponse.class).emptyFrame();
        interaction.consumeResponse(EmptyResponse.class).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) EmptyResponse(org.apache.qpid.tests.protocol.v1_0.EmptyResponse) 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 55 with FrameTransport

use of org.apache.qpid.tests.protocol.v1_0.FrameTransport in project qpid-broker-j by apache.

the class OpenTest method failOpenOnNonExistingHostname.

@Test
@SpecificationTest(section = "2.7.1", description = "The name of the host (either fully qualified or relative) to which the sending peer is connecting")
public void failOpenOnNonExistingHostname() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        final Interaction interaction = transport.newInteraction();
        Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openHostname("non-existing-virtual-host-" + System.currentTimeMillis()).open().consumeResponse().getLatestResponse(Open.class);
        assertThat(responseOpen.getContainerId(), is(notNullValue()));
        Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
        assertThat(responseClose.getError(), is(notNullValue()));
        assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.NOT_FOUND));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) 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)

Aggregations

Test (org.junit.Test)136 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)125 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)116 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)101 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)57 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)57 InetSocketAddress (java.net.InetSocketAddress)45 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)37 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)35 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)32 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)29 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)16 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)14 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)11 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10