Search in sources :

Example 1 with SessionCompleted

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

the class MessageTest method subscribe.

@Test
@SpecificationTest(section = "10.message.subscribe", description = "This command asks the server to start a \"subscription\"," + " which is a request for messages from a specific queue.")
public void subscribe() throws Exception {
    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).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().session().flushCompleted().flush();
        SessionCompleted completed = consumeResponse(interaction, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(0), is(equalTo(true)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 2 with SessionCompleted

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

the class MessageTest method acquireTransfer.

@Test
@SpecificationTest(section = "10.message.acquire", description = "Acquires previously transferred messages for consumption. The acquired ids (if any) are " + "sent via message.acquired.")
public void acquireTransfer() 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).message().subscribeAcceptMode(MessageAcceptMode.EXPLICIT).subscribeAcquireMode(MessageAcquireMode.NOT_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 = consumeResponse(interaction, MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        RangeSet transfers = Range.newInstance(transfer.getId());
        final ExecutionResult result = interaction.message().acquireId(3).acquireTransfers(transfers).acquire().consumeResponse(SessionFlush.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        final Acquired acquired = (Acquired) result.getValue();
        assertThat(acquired.getTransfers().includes(transfer.getId()), is(equalTo(true)));
        interaction.message().acceptId(4).acceptTransfers(transfers).accept().session().flushCompleted().flush();
        SessionCompleted completed = consumeResponse(interaction, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(4), is(equalTo(true)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Acquired(org.apache.qpid.server.protocol.v0_10.transport.Acquired) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with SessionCompleted

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

the class MessageTest method sendTransfer.

@Test
@SpecificationTest(section = "10.message.transfer", description = "This command transfers a message between two peers.")
public void sendTransfer() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "test".getBytes(UTF_8);
        SessionCompleted completed = interaction.openAnonymousConnection().channelId(1).attachSession(sessionName).message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferId(0).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        assertThat(completed.getCommands().includes(0), is(equalTo(true)));
        int queueDepthMessages = getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
        assertThat(queueDepthMessages, is(equalTo(1)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) SessionCommandPoint(org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with SessionCompleted

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

the class MessageTest method acceptTransfer.

@Test
@SpecificationTest(section = "10.message.accept", description = "Accepts the message.")
public void acceptTransfer() 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).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 = consumeResponse(interaction, MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.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 = consumeResponse(interaction, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(3), is(equalTo(true)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with SessionCompleted

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

Aggregations

SessionCompleted (org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted)9 Test (org.junit.Test)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)7 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)3 RangeSet (org.apache.qpid.server.protocol.v0_10.transport.RangeSet)3 ConnectionClose (org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose)2 FrameTransport (org.apache.qpid.tests.protocol.v0_10.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v0_10.Interaction)2 Acquired (org.apache.qpid.server.protocol.v0_10.transport.Acquired)1 ExecutionResult (org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult)1 SessionCommandPoint (org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1