use of org.apache.qpid.server.protocol.v0_10.transport.SessionAttached in project qpid-broker-j by apache.
the class SessionTest method attach.
@Test
@SpecificationTest(section = "9.session.attach", description = "Requests that the current transport be attached to the named session.")
public void attach() 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;
SessionAttached sessionAttached = interaction.openAnonymousConnection().channelId(channelId).session().attachName(sessionName).attach().consumeResponse().getLatestResponse(SessionAttached.class);
assertThat(sessionAttached.getName(), IsEqual.equalTo(sessionName));
assertThat(sessionAttached.getChannel(), IsEqual.equalTo(channelId));
}
}
use of org.apache.qpid.server.protocol.v0_10.transport.SessionAttached in project qpid-broker-j by apache.
the class SessionTest method attachSameSessionTwiceDisallowed.
@Test
@SpecificationTest(section = "9.session", description = "A session MUST NOT be attached to more than one transport at a time.")
public void attachSameSessionTwiceDisallowed() throws Exception {
try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction1 = transport1.newInteraction();
byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
final int channelId1 = 1;
SessionAttached sessionAttached = interaction1.openAnonymousConnection().channelId(channelId1).session().attachName(sessionName).attach().consumeResponse().getLatestResponse(SessionAttached.class);
assertThat(sessionAttached.getName(), IsEqual.equalTo(sessionName));
assertThat(sessionAttached.getChannel(), IsEqual.equalTo(channelId1));
try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction2 = transport2.newInteraction();
final int channelId2 = 2;
SessionDetached sessionDetached = interaction2.openAnonymousConnection().channelId(channelId2).session().attachName(sessionName).attach().consumeResponse().getLatestResponse(SessionDetached.class);
assertThat(sessionDetached.getName(), IsEqual.equalTo(sessionName));
assertThat(sessionDetached.getCode(), IsEqual.equalTo(SessionDetachCode.SESSION_BUSY));
assertThat(sessionDetached.getChannel(), IsEqual.equalTo(channelId2));
}
}
}
Aggregations