From d97f28c4906b2d7de391a4d813814013f831d3db Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 5 Jun 2013 21:06:39 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-4487 and https://issues.apache.org/jira/browse/AMQ-4372 Additional testing and updates. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1490032 13f79535-47bb-0310-9956-ffa450edef68 --- .../broker/region/policy/PolicyEntry.java | 1 + .../ActiveMQMessageAuditNotSyncTest.java | 70 +++++++++++++++++++ .../apache/activemq/JmsQueueBrowserTest.java | 6 +- 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 activemq-client/src/test/java/org/apache/activemq/ActiveMQMessageAuditNotSyncTest.java diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java index ed73cd7e8f..b77f430aaa 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java @@ -244,6 +244,7 @@ public class PolicyEntry extends DestinationMapEntry { // is done. We should refactor the browsers to better handle message dispatch so // we can remove this and perform a more efficient dispatch. sub.setMaxProducersToAudit(Integer.MAX_VALUE); + sub.setMaxAuditDepth(Short.MAX_VALUE); } public void configure(Broker broker, SystemUsage memoryManager, QueueSubscription sub) { diff --git a/activemq-client/src/test/java/org/apache/activemq/ActiveMQMessageAuditNotSyncTest.java b/activemq-client/src/test/java/org/apache/activemq/ActiveMQMessageAuditNotSyncTest.java new file mode 100644 index 0000000000..3dd4678683 --- /dev/null +++ b/activemq-client/src/test/java/org/apache/activemq/ActiveMQMessageAuditNotSyncTest.java @@ -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.activemq; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.activemq.command.ConnectionId; +import org.apache.activemq.command.MessageId; +import org.apache.activemq.command.ProducerId; +import org.apache.activemq.command.SessionId; +import org.apache.activemq.util.IdGenerator; +import org.apache.activemq.util.LongSequenceGenerator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ActiveMQMessageAuditNotSyncTest { + + private final IdGenerator connectionIdGenerator = new IdGenerator(); + private final LongSequenceGenerator sessionIdGenerator = new LongSequenceGenerator(); + private final LongSequenceGenerator producerIdGenerator = new LongSequenceGenerator(); + private final LongSequenceGenerator sequenceIdGenerator = new LongSequenceGenerator(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testAuditDepth() { + + int maxAuditDepth = Integer.MAX_VALUE; + + ConnectionId connectionId = new ConnectionId(connectionIdGenerator.generateId()); + SessionId sessionId = new SessionId(connectionId, sessionIdGenerator.getNextSequenceId()); + ProducerId producerId = new ProducerId(sessionId, producerIdGenerator.getNextSequenceId()); + + ActiveMQMessageAuditNoSync audit = new ActiveMQMessageAuditNoSync(); + audit.setAuditDepth(maxAuditDepth); + + MessageId msgId = new MessageId(producerId, 0); + for (int i = 0; i < maxAuditDepth; i++) { + msgId.setProducerSequenceId(sequenceIdGenerator.getNextSequenceId()); + assertFalse(audit.isDuplicate(msgId)); + } + + for (int i = 0; i < maxAuditDepth; i++) { + assertTrue(audit.isDuplicate(msgId)); + } + } +} diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java index 825be5d9a5..b98a461a6d 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java @@ -307,7 +307,9 @@ public class JmsQueueBrowserTest extends JmsTestSupport { MessageProducer producer = session.createProducer(destination); - for (int i = 0; i < 1000; i++) { + int numberOfMessages = 4096; + + for (int i = 0; i < numberOfMessages; i++) { producer.send(session.createTextMessage("Message: " + i)); } @@ -329,7 +331,7 @@ public class JmsQueueBrowserTest extends JmsTestSupport { } System.out.println("Number browsed: " + numberBrowsed); - assertEquals(1000, numberBrowsed); + assertEquals(numberOfMessages, numberBrowsed); browser.close(); producer.close(); }