You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2016/06/10 15:50:18 UTC

activemq git commit: Wait for bridge formation before attempting to receive otherwise the timed receive might not work.

Repository: activemq
Updated Branches:
  refs/heads/master 534dbee44 -> cf750d5ce


Wait for bridge formation before attempting to receive otherwise the
timed receive might not work. 

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/cf750d5c
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/cf750d5c
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/cf750d5c

Branch: refs/heads/master
Commit: cf750d5cee79a46c6521312019c659b24c80c0e0
Parents: 534dbee
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jun 10 11:22:45 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jun 10 11:22:45 2016 -0400

----------------------------------------------------------------------
 .../jms/TopicOutboundBridgeReconnectTest.java   | 57 +++++++++++++++++++-
 1 file changed, 55 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/cf750d5c/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java
index 6a64b5c..b3f8b06 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/jms/TopicOutboundBridgeReconnectTest.java
@@ -33,9 +33,11 @@ import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.management.ObjectName;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.BrokerViewMBean;
 import org.apache.activemq.command.ActiveMQTopic;
 import org.apache.activemq.util.Wait;
 import org.junit.After;
@@ -114,6 +116,14 @@ public class TopicOutboundBridgeReconnectTest {
 
         MessageConsumer consumer = createConsumer();
 
+        assertTrue("Should have a bridge to the topic", Wait.waitFor(new Wait.Condition() {
+
+            @Override
+            public boolean isSatisified() throws Exception {
+                return getProxyToProducerBroker().getTopicSubscribers().length > 0;
+            }
+        }));
+
         sendMessage("test123");
         Message message = consumer.receive(5000);
         assertNotNull(message);
@@ -124,6 +134,14 @@ public class TopicOutboundBridgeReconnectTest {
         stopProducerBroker();
         startProducerBroker();
 
+        assertTrue("Should have a bridge to the topic", Wait.waitFor(new Wait.Condition() {
+
+            @Override
+            public boolean isSatisified() throws Exception {
+                return getProxyToProducerBroker().getTopicSubscribers().length > 0;
+            }
+        }));
+
         sendMessage("test123");
         message = consumer.receive(5000);
         assertNotNull(message);
@@ -201,6 +219,15 @@ public class TopicOutboundBridgeReconnectTest {
         startConsumerBroker();
         MessageConsumer consumer = createConsumer();
 
+        final BrokerViewMBean producerBrokerView = getProxyToProducerBroker();
+        assertTrue("Should have a bridge to the topic", Wait.waitFor(new Wait.Condition() {
+
+            @Override
+            public boolean isSatisified() throws Exception {
+                return producerBrokerView.getTopicSubscribers().length > 0;
+            }
+        }));
+
         sendMessage("test123");
         Message message = consumer.receive(2000);
         assertNotNull(message);
@@ -266,11 +293,36 @@ public class TopicOutboundBridgeReconnectTest {
         }
     }
 
+    protected BrokerViewMBean getProxyToProducerBroker() throws Exception {
+        if (producerBroker == null) {
+            throw new IllegalStateException("Producer broker is not running.");
+        }
+
+        ObjectName brokerViewMBean = new ObjectName(
+            "org.apache.activemq:type=Broker,brokerName=" + producerBroker.getBrokerName());
+        BrokerViewMBean proxy = (BrokerViewMBean) producerBroker.getManagementContext()
+                .newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
+        return proxy;
+    }
+
+    protected BrokerViewMBean getProxyToConsumerBroker() throws Exception {
+        if (producerBroker == null) {
+            throw new IllegalStateException("Consumer broker is not running.");
+        }
+
+        ObjectName brokerViewMBean = new ObjectName(
+            "org.apache.activemq:type=Broker,brokerName=" + consumerBroker.getBrokerName());
+        BrokerViewMBean proxy = (BrokerViewMBean) consumerBroker.getManagementContext()
+                .newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
+        return proxy;
+    }
+
     protected BrokerService createFirstBroker() throws Exception {
         BrokerService broker = new BrokerService();
         broker.setBrokerName("broker1");
         broker.setPersistent(false);
-        broker.setUseJmx(false);
+        broker.setUseJmx(true);
+        broker.getManagementContext().setCreateConnector(false);
         broker.addConnector("tcp://localhost:61616");
         broker.addConnector("vm://broker1");
 
@@ -289,7 +341,8 @@ public class TopicOutboundBridgeReconnectTest {
         BrokerService broker = new BrokerService();
         broker.setBrokerName("broker2");
         broker.setPersistent(false);
-        broker.setUseJmx(false);
+        broker.setUseJmx(true);
+        broker.getManagementContext().setCreateConnector(false);
         broker.addConnector("tcp://localhost:61617");
         broker.addConnector("vm://broker2");