Search in sources :

Example 1 with ConnectionClose

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose 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 ConnectionClose

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose in project qpid-broker-j by apache.

the class TransactionTimeoutTest method publishTransactionTimeout.

@Test
public void publishTransactionTimeout() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "test".getBytes(UTF_8);
        interaction.openAnonymousConnection().channelId(1).attachSession(sessionName).tx().selectId(0).select().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferId(1).transfer().session().flushCompleted().flush();
        SessionCompleted completed;
        do {
            completed = interaction.consumeResponse().getLatestResponse(SessionCompleted.class);
        } while (!completed.getCommands().includes(1));
        int queueDepthMessages = getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
        assertThat(queueDepthMessages, is(equalTo(0)));
        ConnectionClose close = receiveResponse(interaction, ConnectionClose.class);
        assertThat(close.getReplyCode(), is(equalTo(ConnectionCloseCode.CONNECTION_FORCED)));
        assertThat(close.getReplyText(), containsString("transaction timed out"));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
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) ConnectionClose(org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose) Test(org.junit.Test)

Aggregations

ConnectionClose (org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose)2 SessionCompleted (org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted)2 FrameTransport (org.apache.qpid.tests.protocol.v0_10.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v0_10.Interaction)2 Test (org.junit.Test)2 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)1 RangeSet (org.apache.qpid.server.protocol.v0_10.transport.RangeSet)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1