Search in sources :

Example 1 with Interaction

use of org.apache.qpid.tests.protocol.v0_10.Interaction in project qpid-broker-j by apache.

the class TransactionTimeoutTest method consumeTransactionTimeout.

@Test
public void consumeTransactionTimeout() throws Exception {
    String testMessageBody = "testMessage";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageBody);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.openAnonymousConnection().channelId(1).attachSession(sessionName).tx().selectId(0).select().message().subscribeAcceptMode(MessageAcceptMode.EXPLICIT).subscribeAcquireMode(MessageAcquireMode.PRE_ACQUIRED).subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = receiveResponse(interaction, MessageTransfer.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        RangeSet transfers = Range.newInstance(transfer.getId());
        interaction.message().acceptId(3).acceptTransfers(transfers).accept().session().flushCompleted().flush();
        SessionCompleted completed = receiveResponse(interaction, SessionCompleted.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(3), is(equalTo(true)));
        ConnectionClose close = receiveResponse(interaction, ConnectionClose.class);
        assertThat(close.getReplyCode(), is(equalTo(ConnectionCloseCode.CONNECTION_FORCED)));
        assertThat(close.getReplyText(), containsString("transaction timed out"));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_10.FrameTransport) SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Interaction(org.apache.qpid.tests.protocol.v0_10.Interaction) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) ConnectionClose(org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 2 with Interaction

use of org.apache.qpid.tests.protocol.v0_10.Interaction in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeReceivingLinkWithSingleUnsettledAccepted.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkWithSingleUnsettledAccepted() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        List<Transfer> transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer transfer = transfers.get(0);
        Binary deliveryTag = transfer.getDeliveryTag();
        assertThat(deliveryTag, is(notNullValue()));
        assertThat(transfer.getSettled(), is(not(equalTo(true))));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
        interaction.attachUnsettled(Collections.singletonMap(deliveryTag, new Accepted())).attach().consumeResponse(Attach.class);
        Attach resumeAttach = interaction.getLatestResponse(Attach.class);
        Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
        assertThat(unsettled, is(notNullValue()));
        assertThat(unsettled.entrySet(), hasSize(1));
        Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
        assertThat(entry.getKey(), is(equalTo(deliveryTag)));
        interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer resumeTransfer = transfers.get(0);
        assertThat(resumeTransfer.getResume(), is(equalTo(true)));
        assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
        assertThat(resumeTransfer.getPayload(), is(nullValue()));
        if (!Boolean.TRUE.equals(resumeTransfer.getSettled())) {
            interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
        }
        interaction.doCloseConnection();
        if (getBrokerAdmin().isQueueDepthSupported()) {
            assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        }
    }
}
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) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Map(java.util.Map) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with Interaction

use of org.apache.qpid.tests.protocol.v0_10.Interaction in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeReceivingLinkOneUnsettledWithNoOutcome.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkOneUnsettledWithNoOutcome() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        List<Transfer> transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer transfer = transfers.get(0);
        Binary deliveryTag = transfer.getDeliveryTag();
        assertThat(deliveryTag, is(notNullValue()));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Detach detach = interaction.detach().consumeResponse(Detach.class).getLatestResponse(Detach.class);
        assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
        interaction.attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse(Attach.class);
        Attach resumeAttach = interaction.getLatestResponse(Attach.class);
        Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
        assertThat(unsettled, is(notNullValue()));
        assertThat(unsettled.entrySet(), hasSize(1));
        Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
        assertThat(entry.getKey(), is(equalTo(deliveryTag)));
        interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
        transfers = interaction.getLatestDelivery();
        assertThat(transfers, hasSize(1));
        Transfer resumeTransfer = transfers.get(0);
        assertThat(resumeTransfer.getResume(), is(equalTo(true)));
        assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
        assertThat(resumeTransfer.getPayload(), is(notNullValue()));
        interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
        interaction.doCloseConnection();
        if (getBrokerAdmin().isQueueDepthSupported()) {
            assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(0)));
        }
    }
}
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) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Map(java.util.Map) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with Interaction

use of org.apache.qpid.tests.protocol.v0_10.Interaction in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.

@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 rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
    final String destination = BrokerAdmin.TEST_QUEUE_NAME;
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse();
        // 0. Open connection with small max-frame-size
        final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().getLatestResponse(Open.class);
        interaction.begin().consumeResponse(Begin.class);
        // 1. attach with ReceiverSettleMode.SECOND
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        // 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
        // assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
        interaction.transferHandle(linkHandle1).transferPayloadData(TEST_MESSAGE_CONTENT);
        Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
        for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
            final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
            final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
            assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
            localUnsettled.put(deliveryTag, null);
        }
        // 3. detach the link
        interaction.detach().consumeResponse(Detach.class);
        // 4. resume the link
        final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
        Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
        final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
        assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
        // 5. ensure attach has incomplete-unsettled
        final Attach responseAttach = (Attach) latestResponse.getBody();
        assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
        // 6. send new transfer
        final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
        final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
        assertThat(detachWithError.getError(), is(notNullValue()));
        final Error detachError = detachWithError.getError();
        assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) 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) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with Interaction

use of org.apache.qpid.tests.protocol.v0_10.Interaction in project qpid-broker-j by apache.

the class SaslTest method saslUnsuccessfulAuthentication.

@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation")
public void saslUnsuccessfulAuthentication() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
    try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
        final Interaction interaction = transport.newInteraction();
        final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
        assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
        SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
        assertThat(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
        final Binary initialResponse = new Binary(String.format("\0%s\0badpassword", _username).getBytes(StandardCharsets.US_ASCII));
        SaslOutcome saslOutcome = interaction.saslMechanism(PLAIN).saslInitialResponse(initialResponse).saslInit().consumeResponse().getLatestResponse(SaslOutcome.class);
        assertThat(saslOutcome.getCode(), equalTo(SaslCode.AUTH));
        transport.assertNoMoreResponsesAndChannelClosed();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) SaslOutcome(org.apache.qpid.server.protocol.v1_0.type.security.SaslOutcome) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Test (org.junit.Test)112 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)101 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)100 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)91 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)53 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)48 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)33 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)31 InetSocketAddress (java.net.InetSocketAddress)28 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)28 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)28 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)28 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10