activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1477574 - in /activemq/trunk: activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java
Date Tue, 30 Apr 2013 11:44:03 GMT
Author: dejanb
Date: Tue Apr 30 11:44:03 2013
New Revision: 1477574

URL: http://svn.apache.org/r1477574
Log:
https://issues.apache.org/jira/browse/AMQ-4467 - cursor memory usage when pfc is off

Added:
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java
Modified:
    activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java

Modified: activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java?rev=1477574&r1=1477573&r2=1477574&view=diff
==============================================================================
--- activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java
(original)
+++ activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/AbstractPendingMessageCursor.java
Tue Apr 30 11:44:03 2013
@@ -149,7 +149,7 @@ public abstract class AbstractPendingMes
     }
 
     public boolean hasSpace() {
-        return systemUsage != null ? (systemUsage.getMemoryUsage().getPercentUsage() <
memoryUsageHighWaterMark) : true;
+        return systemUsage != null ? (!systemUsage.getMemoryUsage().isFull(memoryUsageHighWaterMark))
: true;
     }
 
     public boolean isFull() {

Added: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java?rev=1477574&view=auto
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java
(added)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/MemoryUsageBrokerTest.java
Tue Apr 30 11:44:03 2013
@@ -0,0 +1,90 @@
+/**
+ * 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.activemq.bugs;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.BrokerTestSupport;
+import org.apache.activemq.broker.region.policy.PolicyEntry;
+import org.apache.activemq.store.kahadb.KahaDBStore;
+import org.apache.activemq.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.*;
+import java.io.File;
+
+public class MemoryUsageBrokerTest extends BrokerTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(MemoryUsageBrokerTest.class);
+
+    protected void setUp() throws Exception {
+        this.setAutoFail(true);
+        super.setUp();
+    }
+
+    @Override
+    protected PolicyEntry getDefaultPolicy() {
+        PolicyEntry policy = super.getDefaultPolicy();
+        // Disable PFC and assign a large memory limit that's larger than the default broker
memory limit for queues
+        policy.setProducerFlowControl(false);
+        policy.setQueue(">");
+        policy.setMemoryLimit(128 * 1024 * 1024);
+        return policy;
+    }
+
+    protected BrokerService createBroker() throws Exception {
+        BrokerService broker = new BrokerService();
+        KahaDBStore kaha = new KahaDBStore();
+        File directory = new File("target/activemq-data/kahadb");
+        IOHelper.deleteChildren(directory);
+        kaha.setDirectory(directory);
+        kaha.deleteAllMessages();
+        broker.setPersistenceAdapter(kaha);
+        return broker;
+    }
+
+    protected ConnectionFactory createConnectionFactory() {
+        return new ActiveMQConnectionFactory(broker.getVmConnectorURI());
+    }
+
+    protected Connection createJmsConnection() throws JMSException {
+        return createConnectionFactory().createConnection();
+    }
+
+    public void testMemoryUsage() throws Exception {
+        Connection conn = createJmsConnection();
+        Session session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
+        Queue queue = session.createQueue("queue.a.b");
+        MessageProducer producer = session.createProducer(queue);
+        for (int i = 0; i < 100000; i++) {
+            BytesMessage bm = session.createBytesMessage();
+            bm.writeBytes(new byte[1024]);
+            producer.send(bm);
+            if ((i + 1) % 100 == 0) {
+                session.commit();
+                int memoryUsagePercent = broker.getSystemUsage().getMemoryUsage().getPercentUsage();
+                LOG.info((i + 1) + " messages have been sent; broker memory usage " + memoryUsagePercent
+ "%");
+                assertTrue("Used more than available broker memory", memoryUsagePercent <=
100);
+            }
+        }
+        session.commit();
+        producer.close();
+        session.close();
+        conn.close();
+    }
+
+}
\ No newline at end of file



Mime
View raw message