use of org.apache.qpid.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class QueueTest method queueDeclareAutoDeleteAndExclusiveDeletedBySessionDetach.
@Test
@SpecificationTest(section = "10.queue.declare", description = "If this field [auto-delete] is set and the exclusive field is also set, then the queue " + "MUST be deleted when the session closes.")
public void queueDeclareAutoDeleteAndExclusiveDeletedBySessionDetach() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channelId(1).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareId(0).declareExclusive(true).declareAutoDelete(true).declare().session().flushCompleted().flush().consumeResponse(SessionCompleted.class).session().detachName(SESSION_NAME).detach().consumeResponse(SessionDetached.class);
ExecutionException response = interaction.channelId(2).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareId(0).declarePassive(true).declare().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionException.class);
assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
}
}
use of org.apache.qpid.tests.protocol.SpecificationTest 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(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ExecutionResult result = interaction.openAnonymousConnection().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.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class SessionTest method detach.
@Test
@SpecificationTest(section = "9.session.detach", description = "Detaches the current transport from the named session.")
public void detach() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
final int channelId = 1;
SessionDetached sessionDetached = interaction.openAnonymousConnection().channelId(channelId).session().attachName(sessionName).attach().consumeResponse(SessionAttached.class).session().detachName(sessionName).detach().consumeResponse().getLatestResponse(SessionDetached.class);
assertThat(sessionDetached.getName(), IsEqual.equalTo(sessionName));
assertThat(sessionDetached.getChannel(), IsEqual.equalTo(channelId));
}
}
use of org.apache.qpid.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class SessionTest method detachUnknownSession.
@Test
@SpecificationTest(section = "9.session", description = "The transport MUST be attached in order to use any control other than" + " \"attach\", \"attached\", \"detach\", or \"detached\"." + " A peer receiving any other control on a detached transport MUST discard it and send a" + " session.detached with the \"not-attached\" reason code.")
public void detachUnknownSession() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
final int channelId = 1;
SessionDetached sessionDetached = interaction.openAnonymousConnection().channelId(channelId).session().detachName(sessionName).detach().consumeResponse().getLatestResponse(SessionDetached.class);
assertThat(sessionDetached.getName(), IsEqual.equalTo(sessionName));
assertThat(sessionDetached.getChannel(), IsEqual.equalTo(channelId));
}
}
use of org.apache.qpid.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class BasicTest method publishUnrouteableMandatoryMessage.
@Test
@SpecificationTest(section = "1.8.3.7", description = "This flag [mandatory] tells the server how to react if the message cannot be routed to a " + "queue. If this flag is set, the server will return an unroutable message with a " + "Return method.")
public void publishUnrouteableMandatoryMessage() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
String messageContent = "Test";
BasicReturnBody returned = interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publishExchange("").publishRoutingKey("unrouteable").publishMandatory(true).content(messageContent).publishMessage().consumeResponse().getLatestResponse(BasicReturnBody.class);
assertThat(returned.getReplyCode(), is(equalTo(ErrorCodes.NO_ROUTE)));
ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content), is(equalTo(messageContent)));
interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
}
}
Aggregations