Author: ritchiem
Date: Fri Mar  6 12:30:20 2009
New Revision: 750875

URL: http://svn.apache.org/viewvc?rev=750875&view=rev
Log:
QPID-949, QPID-1633 : Set default Maximum Memory Usage for a queue to 100Meg. 
Future work would be to have the broker split Xmx between VirtualHost and for 
the Vhost then to use its housekeeping thread to spread the memory between the 
current queues. It could of course be clever and give more memory to queues in 
high use.
Mistype in AMQQueueFactory resulted in it setting the Max Queue Size alert 
rather than the Max Memory value

Added:
    
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java
Modified:
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
    
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java?rev=750875&r1=750874&r2=750875&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
 Fri Mar  6 12:30:20 2009
@@ -114,7 +114,7 @@
 
     public long getMemoryUsageMaximum()
     {
-        return _config.getLong("maximumMemoryUsage", -1);
+        return _config.getLong("maximumMemoryUsage", 100 * 1024 * 1024); 
//100Meg
     }
 
     public long getMemoryUsageMinimum()

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java?rev=750875&r1=750874&r2=750875&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
 Fri Mar  6 12:30:20 2009
@@ -89,7 +89,7 @@
                                                "Queue create request with 
negative size:" + queueSize, null);
                     }
 
-                    q.setMaximumMessageSize(queueSize);
+                    q.setMemoryUsageMaximum(queueSize);
                 }
                 else
                 {

Added: 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java?rev=750875&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryPriorityTest.java
 Fri Mar  6 12:30:20 2009
@@ -0,0 +1,70 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.queue;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+
+public class AMQQueueFactoryPriorityTest extends AMQQueueFactoryTest
+{
+    private static final int PRIORITIES = 5;
+
+    @Override
+    public void setUp()
+    {
+        super.setUp();
+        _arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 
PRIORITIES);
+    }
+
+    @Override
+    public void testQueueRegistration()
+    {
+        try
+        {
+            AMQQueue queue = createQueue();
+
+            assertEquals("Queue not a priorty queue", AMQPriorityQueue.class, 
queue.getClass());
+
+            assertEquals("Incorrect number of priorities set", PRIORITIES, 
((AMQPriorityQueue) queue).getPriorities());
+        }
+        catch (AMQException e)
+        {
+            fail(e.getMessage());
+        }
+    }
+
+    @Override
+    public void testQueueValuesAfterCreation()
+    {
+        try
+        {
+            AMQQueue queue = createQueue();
+
+            assertEquals("MemoryMaximumSize not set correctly:", MAX_SIZE, 
queue.getMemoryUsageMaximum());
+            //NOTE: Priority queue will show 0 as minimum as the minimum value 
is actually spread between its sub QELs
+            assertEquals("MemoryMinimumSize not 0 as expected for a priority 
queue:", 0, queue.getMemoryUsageMinimum());
+        }
+        catch (AMQException e)
+        {
+            fail(e.getMessage());
+        }
+    }
+}

Modified: 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java?rev=750875&r1=750874&r2=750875&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
 Fri Mar  6 12:30:20 2009
@@ -29,8 +29,11 @@
 
 public class AMQQueueFactoryTest extends TestCase
 {
+    final int MAX_SIZE = 50;
+
     QueueRegistry _queueRegistry;
     VirtualHost _virtualHost;
+    protected FieldTable _arguments;
 
     public void setUp()
     {
@@ -41,6 +44,15 @@
         _queueRegistry = _virtualHost.getQueueRegistry();
 
         assertEquals("Queues registered on an empty virtualhost", 0, 
_queueRegistry.getQueues().size());
+
+
+        _arguments = new FieldTable();
+
+        //Ensure we can call createQueue with a priority int value
+        _arguments.put(AMQQueueFactory.QPID_POLICY_TYPE, 
AMQQueueFactory.QPID_FLOW_TO_DISK);
+        // each message in the QBAAT is around 9-10 bytes each so only give 
space for half
+
+        _arguments.put(AMQQueueFactory.QPID_MAX_SIZE, MAX_SIZE);
     }
 
     public void tearDown()
@@ -50,17 +62,19 @@
     }
 
 
-    public void testPriorityQueueRegistration()
+    protected AMQQueue createQueue() throws AMQException
     {
-        FieldTable fieldTable = new FieldTable();
-        fieldTable.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 
5);
+        return AMQQueueFactory.createAMQQueueImpl(new 
AMQShortString(this.getName()), false, new AMQShortString("owner"), false,
+                                               _virtualHost, _arguments);
+    }
 
+
+    public void testQueueRegistration()
+    {
         try
         {
-            AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new 
AMQShortString("testPriorityQueue"), false, new AMQShortString("owner"), false,
-                                               _virtualHost, fieldTable);
-
-            assertEquals("Queue not a priorty queue", AMQPriorityQueue.class, 
queue.getClass());            
+            AMQQueue queue = createQueue();
+            assertEquals("Queue not a simple queue", SimpleAMQQueue.class, 
queue.getClass());
         }
         catch (AMQException e)
         {
@@ -68,18 +82,20 @@
         }
     }
 
-
-    public void testSimpleQueueRegistration()
+    public void testQueueValuesAfterCreation()
     {
         try
         {
-            AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new 
AMQShortString("testQueue"), false, new AMQShortString("owner"), false,
-                                               _virtualHost, null);
-            assertEquals("Queue not a simple queue", SimpleAMQQueue.class, 
queue.getClass());
+            AMQQueue queue = createQueue();
+
+            assertEquals("MemoryMaximumSize not set correctly:", MAX_SIZE, 
queue.getMemoryUsageMaximum());
+            assertEquals("MemoryMinimumSize not defaulted to half maximum:", 
MAX_SIZE / 2, queue.getMemoryUsageMinimum());
+
         }
         catch (AMQException e)
         {
             fail(e.getMessage());
         }
     }
+
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscr...@qpid.apache.org

Reply via email to