Ensures that max producers on a connection includes anonymous producers
in its count, based on patch from: Christopher L. Shannon (cshannon)
<christopher.l.shannon@gmail.com>

Merged the test into the existing ConfigTest that validates the max
producers functionality.
This commit is contained in:
Timothy Bish 2015-04-13 10:25:51 -04:00
parent f0ebda7ef9
commit ec9a92f6fc
2 changed files with 11 additions and 1 deletions

View File

@ -602,7 +602,10 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
// Avoid replaying dup commands // Avoid replaying dup commands
if (!ss.getProducerIds().contains(info.getProducerId())) { if (!ss.getProducerIds().contains(info.getProducerId())) {
ActiveMQDestination destination = info.getDestination(); 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()){ if (getProducerCount(connectionId) >= connector.getMaximumProducersAllowedPerConnection()){
throw new IllegalStateException("Can't add producer on connection " + connectionId + ": at maximum limit: " + connector.getMaximumProducersAllowedPerConnection()); throw new IllegalStateException("Can't add producer on connection " + connectionId + ": at maximum limit: " + connector.getMaximumProducersAllowedPerConnection());
} }

View File

@ -383,6 +383,13 @@ public class ConfigTest {
} catch (JMSException expected) { } 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 { try {
for (int i = 0; i < (MAX_CONSUMERS + 1); i++) { for (int i = 0; i < (MAX_CONSUMERS + 1); i++) {
MessageConsumer consumer = session.createConsumer(topic); MessageConsumer consumer = session.createConsumer(topic);