activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5639 - implement and test - relaxing the restriction on advisories to those that are relevant to the bridge
Date Wed, 04 Mar 2015 21:40:38 GMT
Repository: activemq
Updated Branches:
  refs/heads/master fe9e38622 -> 11afd5f0b


https://issues.apache.org/jira/browse/AMQ-5639 - implement and test - relaxing the restriction
on advisories to those that are relevant to the bridge


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

Branch: refs/heads/master
Commit: 11afd5f0bcb129300cbb6944bbceccbc026dfd2b
Parents: fe9e386
Author: gtully <gary.tully@gmail.com>
Authored: Wed Mar 4 21:32:35 2015 +0000
Committer: gtully <gary.tully@gmail.com>
Committed: Wed Mar 4 21:33:00 2015 +0000

----------------------------------------------------------------------
 .../activemq/command/NetworkBridgeFilter.java   |   7 +-
 .../usecases/AdvisoryViaNetworkTest.java        | 124 +++++++++++++++++++
 2 files changed, 130 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/11afd5f0/activemq-client/src/main/java/org/apache/activemq/command/NetworkBridgeFilter.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/NetworkBridgeFilter.java
b/activemq-client/src/main/java/org/apache/activemq/command/NetworkBridgeFilter.java
index 8544071..af0c09e 100644
--- a/activemq-client/src/main/java/org/apache/activemq/command/NetworkBridgeFilter.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/NetworkBridgeFilter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.command;
 
+import org.apache.activemq.advisory.AdvisorySupport;
 import org.apache.activemq.filter.BooleanExpression;
 import org.apache.activemq.filter.MessageEvaluationContext;
 import org.apache.activemq.util.JMSExceptionSupport;
@@ -96,7 +97,7 @@ public class NetworkBridgeFilter implements DataStructure, BooleanExpression
{
         }
 
         if (message.isAdvisory()) {
-            if (consumerInfo != null && consumerInfo.isNetworkSubscription()) {
+            if (consumerInfo != null && consumerInfo.isNetworkSubscription() &&
advisoryIsInterpretedByNetworkBridge(message)) {
                 // they will be interpreted by the bridge leading to dup commands
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("not propagating advisory to network sub: " + consumerInfo.getConsumerId()
+ ", message: "+ message);
@@ -123,6 +124,10 @@ public class NetworkBridgeFilter implements DataStructure, BooleanExpression
{
         return true;
     }
 
+    private boolean advisoryIsInterpretedByNetworkBridge(Message message) {
+        return AdvisorySupport.isConsumerAdvisoryTopic(message.getDestination()) || AdvisorySupport.isTempDestinationAdvisoryTopic(message.getDestination());
+    }
+
     public static boolean contains(BrokerId[] brokerPath, BrokerId brokerId) {
         if (brokerPath != null && brokerId != null) {
             for (int i = 0; i < brokerPath.length; i++) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/11afd5f0/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AdvisoryViaNetworkTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AdvisoryViaNetworkTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AdvisoryViaNetworkTest.java
new file mode 100644
index 0000000..aa7d6ee
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AdvisoryViaNetworkTest.java
@@ -0,0 +1,124 @@
+/**
+ * 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.usecases;
+
+import java.net.URI;
+import javax.jms.MessageConsumer;
+import org.apache.activemq.JmsMultipleBrokersTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.region.RegionBroker;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.command.BrokerInfo;
+import org.apache.activemq.network.NetworkConnector;
+import org.apache.activemq.util.MessageIdList;
+import org.apache.activemq.util.Wait;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AdvisoryViaNetworkTest extends JmsMultipleBrokersTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(AdvisoryViaNetworkTest.class);
+
+
+    protected BrokerService createBroker(String brokerName) throws Exception {
+        BrokerService broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.setUseJmx(false);
+        broker.setBrokerName(brokerName);
+        broker.addConnector(new URI(AUTO_ASSIGN_TRANSPORT));
+        brokers.put(brokerName, new BrokerItem(broker));
+
+        return broker;
+    }
+
+    public void testAdvisoryForwarding() throws Exception {
+        ActiveMQTopic advisoryTopic = new ActiveMQTopic("ActiveMQ.Advisory.Producer.Topic.FOO");
+
+        createBroker("A");
+        createBroker("B");
+        NetworkConnector networkBridge = bridgeBrokers("A", "B");
+        networkBridge.addStaticallyIncludedDestination(advisoryTopic);
+        startAllBrokers();
+        verifyPeerBrokerInfo(brokers.get("A"), 1);
+
+
+        MessageConsumer consumerA = createConsumer("A", advisoryTopic);
+        MessageConsumer consumerB = createConsumer("B", advisoryTopic);
+
+        this.sendMessages("A", new ActiveMQTopic("FOO"), 1);
+
+        MessageIdList messagesA = getConsumerMessages("A", consumerA);
+        MessageIdList messagesB = getConsumerMessages("B", consumerB);
+
+        LOG.info("consumerA = " + messagesA);
+        LOG.info("consumerB = " + messagesB);
+
+        messagesA.assertMessagesReceived(2);
+        messagesB.assertMessagesReceived(2);
+    }
+
+
+    public void testBridgeRelevantAdvisoryNotAvailable() throws Exception {
+        ActiveMQTopic advisoryTopic = new ActiveMQTopic("ActiveMQ.Advisory.Consumer.Topic.FOO");
+        createBroker("A");
+        createBroker("B");
+        NetworkConnector networkBridge = bridgeBrokers("A", "B");
+        networkBridge.addStaticallyIncludedDestination(advisoryTopic);
+
+        startAllBrokers();
+        verifyPeerBrokerInfo(brokers.get("A"), 1);
+
+
+        MessageConsumer consumerA = createConsumer("A", advisoryTopic);
+        MessageConsumer consumerB = createConsumer("B", advisoryTopic);
+
+        createConsumer("A", new ActiveMQTopic("FOO"));
+
+        MessageIdList messagesA = getConsumerMessages("A", consumerA);
+        MessageIdList messagesB = getConsumerMessages("B", consumerB);
+
+        LOG.info("consumerA = " + messagesA);
+        LOG.info("consumerB = " + messagesB);
+
+        messagesA.assertMessagesReceived(1);
+        messagesB.assertMessagesReceived(0);
+    }
+
+    private void verifyPeerBrokerInfo(BrokerItem brokerItem, final int max) throws Exception
{
+        final BrokerService broker = brokerItem.broker;
+        final RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
+        Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                LOG.info("verify infos " + broker.getBrokerName() + ", len: " + regionBroker.getPeerBrokerInfos().length);
+                return max == regionBroker.getPeerBrokerInfos().length;
+            }
+         }, 120 * 1000);
+        LOG.info("verify infos " + broker.getBrokerName() + ", len: " + regionBroker.getPeerBrokerInfos().length);
+        for (BrokerInfo info : regionBroker.getPeerBrokerInfos()) {
+            LOG.info(info.getBrokerName());
+        }
+        assertEquals(broker.getBrokerName(), max, regionBroker.getPeerBrokerInfos().length);
+    }
+
+
+    @Override
+    public void setUp() throws Exception {
+        super.setAutoFail(true);
+        super.setUp();
+    }
+
+}


Mime
View raw message