From ec9a92f6fc5554017e1b3551b24e2e19e0da8fbc Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Mon, 13 Apr 2015 10:25:51 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5649 Ensures that max producers on a connection includes anonymous producers in its count, based on patch from: Christopher L. Shannon (cshannon) Merged the test into the existing ConfigTest that validates the max producers functionality. --- .../org/apache/activemq/broker/TransportConnection.java | 5 ++++- .../test/java/org/apache/activemq/config/ConfigTest.java | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java index 7f9fa6c21f..5c6307af9d 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java @@ -602,7 +602,10 @@ public class TransportConnection implements Connection, Task, CommandVisitor { // Avoid replaying dup commands if (!ss.getProducerIds().contains(info.getProducerId())) { ActiveMQDestination destination = info.getDestination(); - if (destination != null && !AdvisorySupport.isAdvisoryTopic(destination)) { + // Do not check for null here as it would cause the count of max producers to exclude + // anonymous producers. The isAdvisoryTopic method checks for null so it is safe to + // call it from here with a null Destination value. + if (!AdvisorySupport.isAdvisoryTopic(destination)) { if (getProducerCount(connectionId) >= connector.getMaximumProducersAllowedPerConnection()){ throw new IllegalStateException("Can't add producer on connection " + connectionId + ": at maximum limit: " + connector.getMaximumProducersAllowedPerConnection()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java index 82b5ebec76..a62ce071a5 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java @@ -383,6 +383,13 @@ public class ConfigTest { } catch (JMSException expected) { } + // Tests the anonymous producer case also counts. + try { + session.createProducer(null); + fail("Should have got an exception on exceeding MAX_PRODUCERS"); + } catch (JMSException expected) { + } + try { for (int i = 0; i < (MAX_CONSUMERS + 1); i++) { MessageConsumer consumer = session.createConsumer(topic);