activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r939318 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
Date Thu, 29 Apr 2010 14:19:51 GMT
Author: gtully
Date: Thu Apr 29 14:19:51 2010
New Revision: 939318

URL: http://svn.apache.org/viewvc?rev=939318&view=rev
Log:
test case that validates network with virtual topics and broker restart

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
  (with props)

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java?rev=939318&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
Thu Apr 29 14:19:51 2010
@@ -0,0 +1,143 @@
+/**
+ * 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.io.File;
+import java.net.URI;
+
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+
+import org.apache.activemq.JmsMultipleBrokersTestSupport;
+import org.apache.activemq.JmsMultipleBrokersTestSupport.BrokerItem;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.region.DestinationInterceptor;
+import org.apache.activemq.broker.region.virtual.VirtualDestination;
+import org.apache.activemq.broker.region.virtual.VirtualDestinationInterceptor;
+import org.apache.activemq.broker.region.virtual.VirtualTopic;
+import org.apache.activemq.network.NetworkConnector;
+import org.apache.activemq.store.kahadb.KahaDBStore;
+import org.apache.activemq.util.MessageIdList;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class ThreeBrokerVirtualTopicNetworkTest extends JmsMultipleBrokersTestSupport {
+    private static final Log LOG = LogFactory.getLog(ThreeBrokerVirtualTopicNetworkTest.class);
+    protected static final int MESSAGE_COUNT = 1;
+    public boolean dynamicOnly = false;
+
+    
+    public void testNetworkVirtualTopic() throws Exception {
+        int networkTTL = 6;
+        boolean conduitSubs = true;
+        // Setup broker networks
+        bridgeAndConfigureBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
+
+        startAllBrokers();      
+        waitForBridgeFormation();
+        
+        // Setup destination
+        Destination dest = createDestination("TEST.FOO", true);
+
+        // Setup consumers
+        MessageConsumer clientA = createConsumer("BrokerA", createDestination("Consumer.A.TEST.FOO",
false));
+        MessageConsumer clientB = createConsumer("BrokerB", createDestination("Consumer.B.TEST.FOO",
false));
+        MessageConsumer clientC = createConsumer("BrokerB", createDestination("Consumer.C.TEST.FOO",
false));
+        
+        Thread.sleep(2000);
+
+        // Send messages
+        sendMessages("BrokerA", dest, 1);
+
+        // Get message count
+        MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
+        MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
+        MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
+
+        msgsA.waitForMessagesToArrive(1);
+        msgsB.waitForMessagesToArrive(1);
+        msgsC.waitForMessagesToArrive(1);
+
+        // ensure we don't get any more messages
+        Thread.sleep(2000);
+        
+        assertEquals(1, msgsA.getMessageCount());
+        assertEquals(1, msgsB.getMessageCount());
+        assertEquals(1, msgsC.getMessageCount());
+        
+        // restart to ensure no hanging messages
+        LOG.info("Restarting brokerA");
+        BrokerItem brokerItem = brokers.remove("BrokerA");
+        if (brokerItem != null) {
+            brokerItem.destroy();
+        }
+        
+        BrokerService restartedBroker = createAndConfigureBroker(new URI("broker:(tcp://localhost:61616)/BrokerA"));
+        bridgeAndConfigureBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
+        restartedBroker.start();
+        waitForBridgeFormation();
+        
+        clientA = createConsumer("BrokerA", createDestination("Consumer.A.TEST.FOO", false));
+        
+        Thread.sleep(2000);
+
+        sendMessages("BrokerA", dest, 1);
+
+        msgsA = getConsumerMessages("BrokerA", clientA);
+
+        msgsA.waitForMessagesToArrive(1);
+        msgsB.waitForMessagesToArrive(2);
+        msgsC.waitForMessagesToArrive(2);
+
+        // ensure we don't get any more messages
+        Thread.sleep(2000);
+        
+        assertEquals(1, msgsA.getMessageCount());
+        assertEquals(2, msgsB.getMessageCount());
+        assertEquals(2, msgsC.getMessageCount());        
+    }
+    
+
+    private void bridgeAndConfigureBrokers(String local, String remote, boolean dynamicOnly,
int networkTTL, boolean conduitSubs) throws Exception {
+        bridgeBrokers(local, remote, dynamicOnly, networkTTL, conduitSubs);
+    }
+
+    public void setUp() throws Exception {
+        super.setAutoFail(true);
+        super.setUp();
+        String options = new String("?useJmx=false&deleteAllMessagesOnStartup=true");

+        createAndConfigureBroker(new URI("broker:(tcp://localhost:61616)/BrokerA" + options));
+        createAndConfigureBroker(new URI("broker:(tcp://localhost:61617)/BrokerB" + options));
+    }
+    
+    private BrokerService createAndConfigureBroker(URI uri) throws Exception {
+        BrokerService broker = createBroker(uri);
+        
+        File dataFileDir = new File("target/test-amq-data/kahadb/" + broker.getBrokerName());
+        KahaDBStore kaha = new KahaDBStore();
+        kaha.setDirectory(dataFileDir);
+        broker.setPersistenceAdapter(kaha);
+        
+        // make all topics virtual and consumers use the default prefix
+        VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
+        virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[]{new
VirtualTopic()});
+        DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[]{virtualDestinationInterceptor};
+        broker.setDestinationInterceptors(destinationInterceptors);
+        return broker;
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ThreeBrokerVirtualTopicNetworkTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message