You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2014/04/30 18:09:09 UTC
git commit: https://issues.apache.org/jira/browse/AMQ-5136 - fix and
test (thanks barlabanov)
Repository: activemq
Updated Branches:
refs/heads/trunk ad1f751a4 -> c5c149533
https://issues.apache.org/jira/browse/AMQ-5136 - fix and test (thanks barlabanov)
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/c5c14953
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/c5c14953
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/c5c14953
Branch: refs/heads/trunk
Commit: c5c1495330dbad20c2f25e4b44f017005fb97a42
Parents: ad1f751
Author: gtully <ga...@gmail.com>
Authored: Wed Apr 30 17:08:20 2014 +0100
Committer: gtully <ga...@gmail.com>
Committed: Wed Apr 30 17:08:20 2014 +0100
----------------------------------------------------------------------
.../apache/activemq/broker/region/Topic.java | 5 ++
.../org/apache/activemq/bugs/AMQ5136Test.java | 95 ++++++++++++++++++++
2 files changed, 100 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/c5c14953/activemq-broker/src/main/java/org/apache/activemq/broker/region/Topic.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Topic.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Topic.java
index f85ed66..277ce05 100755
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Topic.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Topic.java
@@ -498,6 +498,11 @@ public class Topic extends BaseDestination implements Task {
message.decrementReferenceCount();
}
}
+
+ @Override
+ public void afterRollback() throws Exception {
+ message.decrementReferenceCount();
+ }
});
} else {
http://git-wip-us.apache.org/repos/asf/activemq/blob/c5c14953/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ5136Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ5136Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ5136Test.java
new file mode 100644
index 0000000..c2cb11e
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ5136Test.java
@@ -0,0 +1,95 @@
+/**
+ * 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 javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.Topic;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerRegistry;
+import org.apache.activemq.broker.BrokerService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AMQ5136Test {
+
+ BrokerService brokerService;
+ @Before
+ public void startBroker() throws Exception {
+ brokerService = new BrokerService();
+ brokerService.setPersistent(false);
+ brokerService.start();
+ }
+
+ @After
+ public void stopBroker() throws Exception {
+ brokerService.stop();
+ }
+
+ @Test
+ public void memoryUsageOnCommit() throws Exception {
+ sendMessagesAndAssertMemoryUsage(new TransactionHandler() {
+ @Override
+ public void finishTransaction(Session session) throws JMSException {
+ session.commit();
+ }
+ });
+ }
+
+ @Test
+ public void memoryUsageOnRollback() throws Exception {
+ sendMessagesAndAssertMemoryUsage(new TransactionHandler() {
+ @Override
+ public void finishTransaction(Session session) throws JMSException {
+ session.rollback();
+ }
+ });
+ }
+
+ private void sendMessagesAndAssertMemoryUsage(TransactionHandler transactionHandler) throws Exception {
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
+ Connection connection = connectionFactory.createConnection();
+ Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+ Topic destination = session.createTopic("ActiveMQBug");
+ MessageProducer producer = session.createProducer(destination);
+ for (int i = 0; i < 100; i++) {
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(generateBytes());
+ producer.send(message);
+ transactionHandler.finishTransaction(session);
+ }
+ connection.close();
+ org.junit.Assert.assertEquals(0, BrokerRegistry.getInstance().findFirst().getSystemUsage().getMemoryUsage().getPercentUsage());
+ }
+
+ private byte[] generateBytes() {
+ byte[] bytes = new byte[100000];
+ for (int i = 0; i < 100000; i++) {
+ bytes[i] = (byte) i;
+ }
+ return bytes;
+ }
+
+ private static interface TransactionHandler {
+ void finishTransaction(Session session) throws JMSException;
+ }
+}