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)));
}
}
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));
}
}
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)));
}
}
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)));
}
}
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)));
}
}
Aggregations