use of org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation in project qpid-broker-j by apache.
the class AMQPConnection_0_8Test method testConnectionEnforcesMaxSessions.
public void testConnectionEnforcesMaxSessions() throws Exception {
AMQPConnection_0_8Impl conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
conn.create();
conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
conn.receiveConnectionStartOk(new FieldTable(), SASL_MECH, SASL_RESPONSE, LOCALE);
int maxChannels = 10;
conn.receiveConnectionTuneOk(maxChannels, 65535, 0);
conn.receiveConnectionOpen(new AMQShortString(VIRTUAL_HOST_NAME), AMQShortString.EMPTY_STRING, false);
// check the channel count is correct
int channelCount = conn.getSessionModels().size();
assertEquals("Initial channel count wrong", 0, channelCount);
assertEquals("Number of channels not correctly set.", maxChannels, conn.getSessionCountLimit());
assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
for (long currentChannel = 1L; currentChannel <= maxChannels; currentChannel++) {
conn.receiveChannelOpen((int) currentChannel);
}
assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
assertEquals("Maximum number of channels not set.", maxChannels, conn.getSessionModels().size());
conn.receiveChannelOpen(maxChannels + 1);
assertTrue("Connection should be closed after opening " + (maxChannels + 1) + " channels", conn.isClosing());
}
use of org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation in project qpid-broker-j by apache.
the class FrameDecoder method decode.
@Override
public Collection<Response<?>> decode(final ByteBuffer inputBuffer) throws Exception {
_clientDecoder.decodeBuffer(inputBuffer);
List<AMQDataBlock> receivedFrames = new ArrayList<>(_methodProcessor.getProcessedMethods());
List<Response<?>> result = new ArrayList<>();
for (AMQDataBlock frame : receivedFrames) {
if (frame instanceof AMQFrame) {
AMQFrame amqFrame = (AMQFrame) frame;
if (amqFrame.getBodyFrame() instanceof ConnectionTuneBody) {
ConnectionTuneBody tuneBody = (ConnectionTuneBody) amqFrame.getBodyFrame();
_clientDecoder.setMaxFrameSize((int) tuneBody.getFrameMax());
}
result.add(new PerformativeResponse(amqFrame.getChannel(), amqFrame.getSize(), amqFrame.getBodyFrame()));
} else if (frame instanceof ProtocolInitiation) {
byte[] data = new byte[(int) frame.getSize()];
frame.writePayload(new ByteBufferSender() {
@Override
public boolean isDirectBufferPreferred() {
return false;
}
@Override
public void send(final QpidByteBuffer msg) {
msg.copyTo(data);
}
@Override
public void flush() {
}
@Override
public void close() {
}
});
result.add(new HeaderResponse(data));
} else {
throw new IllegalArgumentException(String.format("Unexpected data block received %s", frame));
}
}
_methodProcessor.getProcessedMethods().removeAll(receivedFrames);
return result;
}
Aggregations