You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2007/04/23 18:38:25 UTC
svn commit: r531526 - in /incubator/qpid/branches/M2/java:
broker/src/main/java/org/apache/qpid/server/protocol/
systests/src/main/java/org/apache/qpid/server/channel/
Author: ritchiem
Date: Mon Apr 23 09:38:24 2007
New Revision: 531526
URL: http://svn.apache.org/viewvc?view=rev&rev=531526
Log:
QPID-290 - Java broker does not honor maximum number of channels threshold
Applied patch from Nuno Santos
Added:
incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/
incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java (with props)
Modified:
incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java
Modified: incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java?view=diff&rev=531526&r1=531525&r2=531526
==============================================================================
--- incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java (original)
+++ incubator/qpid/branches/M2/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java Mon Apr 23 09:38:24 2007
@@ -463,7 +463,17 @@
throw new AMQException("Session is marked awaiting channel close");
}
- _channelMap.put(channelId, channel);
+ if (_channelMap.size() == _maxNoOfChannels)
+ {
+ String errorMessage = toString() + ": maximum number of channels has been reached (" +
+ _maxNoOfChannels + "); can't create channel";
+ _logger.error(errorMessage);
+ throw new AMQException(AMQConstant.NOT_ALLOWED, errorMessage);
+ }
+ else
+ {
+ _channelMap.put(channel.getChannelId(), channel);
+ }
if (((channelId & CHANNEL_CACHE_SIZE) == channelId))
{
@@ -755,8 +765,9 @@
{
return _authorizedID;
}
+
public String getClientVersion()
{
- return _clientVersion == null ? null : _clientVersion.toString();
+ return _clientVersion == null ? null : _clientVersion.toString();
}
}
Added: incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java?view=auto&rev=531526
==============================================================================
--- incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java (added)
+++ incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java Mon Apr 23 09:38:24 2007
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.server.protocol;
+
+import junit.framework.TestCase;
+import org.apache.mina.common.IoSession;
+import org.apache.qpid.codec.AMQCodecFactory;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.server.queue.QueueRegistry;
+import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.SkeletonMessageStore;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.framing.AMQShortString;
+
+import javax.management.JMException;
+
+/** Test class to test MBean operations for AMQMinaProtocolSession. */
+public class MaxChannelsTest extends TestCase
+{
+// private MessageStore _messageStore = new SkeletonMessageStore();
+
+ public void testChannels() throws Exception
+ {
+ IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
+ AMQMinaProtocolSession _protocolSession = new AMQMinaProtocolSession(new MockIoSession(),
+ appRegistry.getVirtualHostRegistry(),
+ new AMQCodecFactory(true),
+ null);
+ _protocolSession.setVirtualHost(appRegistry.getVirtualHostRegistry().getVirtualHost("test"));
+
+ // check the channel count is correct
+ int channelCount = _protocolSession.getChannels().size();
+ assertEquals("Initial channel count wrong", 0, channelCount);
+
+ long maxChannels = 10L;
+ _protocolSession.setMaximumNumberOfChannels(maxChannels);
+ assertEquals("Number of channels not correctly set.", new Long(maxChannels), _protocolSession.getMaximumNumberOfChannels());
+
+
+ try
+ {
+ for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
+ {
+ _protocolSession.addChannel(new AMQChannel(_protocolSession, (int) currentChannel, null, null));
+ }
+ }
+ catch (AMQException e)
+ {
+ assertEquals("Wrong exception recevied.", e.getErrorCode(), AMQConstant.NOT_ALLOWED);
+ }
+ assertEquals("Maximum number of channels not set.", new Long(maxChannels), new Long(_protocolSession.getChannels().size()));
+ }
+
+}
Propchange: incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date