use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class DischargeTest method dischargeUnsettledAfterSenderClose.
@Test
@SpecificationTest(section = "4.4.4.1", description = "Transactional Posting [...]" + " Delivery Sent Unsettled By Controller; Resource Does Not Settle [...]" + " After a successful discharge, the state of unsettled deliveries at the resource MUST" + " reflect the outcome that was applied.")
public void dischargeUnsettledAfterSenderClose() throws Exception {
assumeThat(getBrokerAdmin().isQueueDepthSupported(), is(true));
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(UnsignedInteger.ONE).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferTransactionalState(txnState.getCurrentTransactionId()).transferPayloadData("test message").transferHandle(UnsignedInteger.ONE).transfer().consumeResponse(Disposition.class).detachHandle(UnsignedInteger.ONE).detachClose(true).detach().consumeResponse(Detach.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
interaction.txnDischarge(txnState, false);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class TransactionalTransferTest method assertUnknownTransactionIdError.
private void assertUnknownTransactionIdError(final Response<?> response) {
assertThat(response, is(notNullValue()));
final Object body = response.getBody();
assertThat(body, is(notNullValue()));
Error error = null;
if (body instanceof Close) {
error = ((Close) body).getError();
} else if (body instanceof End) {
error = ((End) body).getError();
} else if (body instanceof Detach) {
error = ((Detach) body).getError();
} else {
fail(String.format("Unexpected response %s", body.getClass().getSimpleName()));
}
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), equalTo(TransactionError.UNKNOWN_ID));
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class AttachTest method attachSenderWithNullSource.
@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
public void attachSenderWithNullSource() throws Exception {
String queueName = "testQueue";
getBrokerAdmin().createQueue(queueName);
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
final Attach responseAttach = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSource(null).attachTargetAddress(queueName).attachInitialDeliveryCount(UnsignedInteger.ZERO).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.RECEIVER));
assertThat(responseAttach.getSource(), is(nullValue()));
assertThat(responseAttach.getTarget(), is(nullValue()));
final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
assertThat(responseDetach.getClosed(), is(true));
assertThat(responseDetach.getError(), is(notNullValue()));
assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
assertThat(endResponse.getError(), is(notNullValue()));
// QPID-7954
// assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class AttachTest method attachReceiverWithNullTarget.
@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
public void attachReceiverWithNullTarget() throws Exception {
String queueName = "testQueue";
getBrokerAdmin().createQueue(queueName);
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
final Attach responseAttach = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(queueName).attachTarget(null).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.SENDER));
assertThat(responseAttach.getSource(), is(nullValue()));
assertThat(responseAttach.getTarget(), is(nullValue()));
final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
assertThat(responseDetach.getClosed(), is(true));
assertThat(responseDetach.getError(), is(notNullValue()));
assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
assertThat(endResponse.getError(), is(notNullValue()));
// QPID-7954
// assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class AbstractLinkEndpoint method detach.
protected void detach(Error error, boolean close) {
if (error != null && !getSession().isSyntheticError(error)) {
_errored = true;
}
// TODO: QPID-7954: improve detach
switch(_state) {
case ATTACHED:
_state = State.DETACH_SENT;
break;
case DETACH_RECVD:
_state = State.DETACHED;
break;
default:
// disassociate the link from the session so that the new connection can use it.
if (close) {
getSession().dissociateEndpoint(this);
destroy();
_link.linkClosed();
}
return;
}
if (getSession().getSessionState() != SessionState.END_RECVD && !getSession().isEnded()) {
Detach detach = new Detach();
detach.setHandle(getLocalHandle());
if (close) {
detach.setClosed(close);
}
detach.setError(error);
getSession().sendDetach(detach);
}
if (close) {
destroy();
_link.linkClosed();
}
setLocalHandle(null);
}
Aggregations