From fd760888147b1db69a330c32a3630ddd87c2a53c Mon Sep 17 00:00:00 2001 From: gtully Date: Wed, 17 Feb 2016 14:09:05 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5875 - additional test that shows durable sub registration does not error out with this fix --- .../vm/VmTransportNetworkBrokerTest.java | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/vm/VmTransportNetworkBrokerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/vm/VmTransportNetworkBrokerTest.java index e837e05c7a..dc782a2bea 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/vm/VmTransportNetworkBrokerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/vm/VmTransportNetworkBrokerTest.java @@ -24,14 +24,22 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.jms.Connection; +import javax.jms.Session; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.bugs.embedded.ThreadExplorer; +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.network.DurableConduitBridge; import org.apache.activemq.network.NetworkConnector; +import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.Wait; +import org.apache.log4j.Level; +import org.apache.log4j.spi.LoggingEvent; +import org.junit.Ignore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,7 +123,72 @@ public class VmTransportNetworkBrokerTest extends TestCase { ok); } - + + public void testInvalidClientIdAndDurableSubs() throws Exception { + + BrokerService broker = new BrokerService(); + broker.setUseJmx(false); + broker.setDedicatedTaskRunner(true); + broker.setPersistent(false); + broker.addConnector("tcp://localhost:0"); + broker.start(); + + // ensure remoteConnection fails with InvalidClientId + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString()); + Connection connection = connectionFactory.createConnection("system", "manager"); + connection.setClientID("F1_forwarder_outbound"); + connection.start(); + + BrokerService forwarder = new BrokerService(); + forwarder.setBrokerName("forwarder"); + forwarder.setPersistent(false); + forwarder.setUseJmx(false); + + forwarder.start(); + + // setup some durable subs to have some local work to do + ActiveMQConnectionFactory vmFactory = new ActiveMQConnectionFactory("vm://forwarder"); + Connection vmConnection = vmFactory.createConnection("system", "manager"); + vmConnection.setClientID("vm_local"); + vmConnection.start(); + Session session = vmConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + for (int i=0; i<5000; i++) { + session.createDurableSubscriber(new ActiveMQTopic("T" + i), "" + i); + } + vmConnection.close(); + + final AtomicInteger logCounts = new AtomicInteger(0); + DefaultTestAppender appender = new DefaultTestAppender() { + @Override + public void doAppend(LoggingEvent event) { + if (event.getLevel() == Level.ERROR) { + logCounts.incrementAndGet(); + } + } + }; + + org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).addAppender(appender); + try { + + NetworkConnector networkConnector = forwarder.addNetworkConnector("static:(" + + broker.getTransportConnectors().get(0).getPublishableConnectString() + ")"); + networkConnector.setName("F1"); + forwarder.addNetworkConnector(networkConnector); + forwarder.startAllConnectors(); + + TimeUnit.SECONDS.sleep(1); + connection.close(); + + forwarder.stop(); + broker.stop(); + + assertEquals("no errors", 0, logCounts.get()); + + } finally { + org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).removeAppender(appender); + } + } + /** * Filters any daemon threads from the thread list. *