Search in sources :

Example 1 with ExecutionResult

use of org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult 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(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.negotiateOpen().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 = interaction.consume(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 = interaction.consume(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 2 with ExecutionResult

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

the class QueueTest method queuePurge.

@Test
@SpecificationTest(section = "10.queue.purge", description = "This command removes all messages from a queue.")
public void queuePurge() throws Exception {
    getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message");
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ExecutionResult result = interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).queue().queryQueue(BrokerAdmin.TEST_QUEUE_NAME).queryId(1).query().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        assertThat(((QueueQueryResult) result.getValue()).getMessageCount(), is(1L));
        interaction.queue().purgeQueue(BrokerAdmin.TEST_QUEUE_NAME).purgeId(0).purge().session().flushCompleted().flush().consumeResponse(SessionFlush.class).consumeResponse(SessionCompleted.class);
        result = interaction.queue().queryQueue(BrokerAdmin.TEST_QUEUE_NAME).queryId(1).query().session().flushCompleted().flush().consumeResponse(SessionCompleted.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        assertThat(((QueueQueryResult) result.getValue()).getMessageCount(), is(0L));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) SessionFlush(org.apache.qpid.server.protocol.v0_10.transport.SessionFlush) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with ExecutionResult

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

the class ExchangeTest method exchangeBindMultipleBindings.

@Test
@SpecificationTest(section = "10.exchange.bind", description = " Bindings between durable queues and durable exchanges are automatically durable and" + "  the server MUST restore such bindings after a server restart.")
public void exchangeBindMultipleBindings() throws Exception {
    assumeThat(getBrokerAdmin().supportsRestart(), Matchers.is(true));
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareId(0).declareDurable(true).declare().session().flushCompleted().flush().consumeResponse(SessionCompleted.class).exchange().bindId(1).bindExchange("amq.direct").bindQueue(BrokerAdmin.TEST_QUEUE_NAME).bindBindingKey("bk").bind().session().flushCompleted().flush().consumeResponse(SessionCompleted.class);
    }
    getBrokerAdmin().restart();
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ExecutionResult execResult = interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).exchange().boundId(0).boundExchange("amq.direct").boundQueue(BrokerAdmin.TEST_QUEUE_NAME).boundBindingKey("bk").bound().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        assertThat(execResult.getValue(), is(instanceOf(ExchangeBoundResult.class)));
        ExchangeBoundResult result = (ExchangeBoundResult) execResult.getValue();
        assertThat(result.getExchangeNotFound(), is(equalTo(false)));
        assertThat(result.getQueueNotFound(), is(equalTo(false)));
        assertThat(result.getKeyNotMatched(), is(equalTo(false)));
    }
}
Also used : ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) ExchangeBoundResult(org.apache.qpid.server.protocol.v0_10.transport.ExchangeBoundResult) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with ExecutionResult

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

the class ExchangeTest method exchangeDelete.

@Test
@SpecificationTest(section = "10.exchange.delete", description = "delete an exchange")
public void exchangeDelete() throws Exception {
    String exchangeName = "myexch";
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).exchange().declareExchange(exchangeName).declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).declareId(0).declare().session().flushCompleted().flush().consumeResponse(SessionCompleted.class);
        interaction.exchange().deleteExchange(exchangeName).deleteId(1).delete().session().flushCompleted().flush().consumeResponse(SessionCompleted.class);
        ExecutionResult result = interaction.exchange().queryExchange(exchangeName).queryId(2).query().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        ExchangeQueryResult queryResult = (ExchangeQueryResult) result.getValue();
        assertThat(queryResult.getNotFound(), is(equalTo(true)));
    }
}
Also used : ExchangeQueryResult(org.apache.qpid.server.protocol.v0_10.transport.ExchangeQueryResult) ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with ExecutionResult

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

the class ExchangeTest method exchangeQuery.

@Test
@SpecificationTest(section = "10.exchange.query", description = "request information about an exchange")
public void exchangeQuery() throws Exception {
    String exchangeName = "myexch";
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ExecutionResult result = interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).exchange().declareId(0).declareExchange(exchangeName).declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).declare().exchange().queryId(1).queryExchange(exchangeName).query().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        ExchangeQueryResult queryResult = (ExchangeQueryResult) result.getValue();
        assertThat(queryResult.getNotFound(), is(equalTo(false)));
    }
}
Also used : ExchangeQueryResult(org.apache.qpid.server.protocol.v0_10.transport.ExchangeQueryResult) ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ExecutionResult (org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 Test (org.junit.Test)9 ExchangeBoundResult (org.apache.qpid.server.protocol.v0_10.transport.ExchangeBoundResult)4 SessionCompleted (org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted)3 ExchangeQueryResult (org.apache.qpid.server.protocol.v0_10.transport.ExchangeQueryResult)2 Acquired (org.apache.qpid.server.protocol.v0_10.transport.Acquired)1 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)1 QueueQueryResult (org.apache.qpid.server.protocol.v0_10.transport.QueueQueryResult)1 RangeSet (org.apache.qpid.server.protocol.v0_10.transport.RangeSet)1 SessionFlush (org.apache.qpid.server.protocol.v0_10.transport.SessionFlush)1