use of org.apache.qpid.server.protocol.v1_0.type.transport.Close 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.Close in project qpid-broker-j by apache.
the class IdleTimeoutTest method brokerClosesIdleConnection.
@Test
@SpecificationTest(section = "2.4.5", description = "If the [idle timeout threshold] threshold is exceeded, then a peer SHOULD try to" + "gracefully close the connection using a close frame with an error explaining why.")
public void brokerClosesIdleConnection() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse().getLatestResponse(Open.class);
assertThat(responseOpen.getIdleTimeOut().intValue(), is(equalTo(IDLE_TIMEOUT_MS)));
// TODO: defect - broker ought to be sending a close performative but it just closes the socket.
interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.
the class OpenTest method failOpenOnNonExistingHostname.
@Test
@SpecificationTest(section = "2.7.1", description = "The name of the host (either fully qualified or relative) to which the sending peer is connecting")
public void failOpenOnNonExistingHostname() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
final Interaction interaction = transport.newInteraction();
Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openHostname("non-existing-virtual-host-" + System.currentTimeMillis()).open().consumeResponse().getLatestResponse(Open.class);
assertThat(responseOpen.getContainerId(), is(notNullValue()));
Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
assertThat(responseClose.getError(), is(notNullValue()));
assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.NOT_FOUND));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.
the class AttachTest method emptyAttach.
@Test
@SpecificationTest(section = "1.3.4", description = "Attach without mandatory fields should result in a decoding error.")
public void emptyAttach() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Close responseClose = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(null).attachHandle(null).attachName(null).attach().consumeResponse().getLatestResponse(Close.class);
assertThat(responseClose.getError(), is(notNullValue()));
assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.DECODE_ERROR));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Close 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