From commits-return-10874-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Tue May 26 15:55:54 2009 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 54801 invoked from network); 26 May 2009 15:55:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 May 2009 15:55:53 -0000 Received: (qmail 86708 invoked by uid 500); 26 May 2009 15:56:06 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 86672 invoked by uid 500); 26 May 2009 15:56:06 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 86663 invoked by uid 99); 26 May 2009 15:56:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 May 2009 15:56:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 May 2009 15:56:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C8D82238888E; Tue, 26 May 2009 15:55:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r778777 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/failover/FailoverTransport.java test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java Date: Tue, 26 May 2009 15:55:41 -0000 To: commits@activemq.apache.org From: gtully@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090526155541.C8D82238888E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gtully Date: Tue May 26 15:55:41 2009 New Revision: 778777 URL: http://svn.apache.org/viewvc?rev=778777&view=rev Log: have failover transport use shared random generator so random can loadbalance in the same jvm Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java (with props) Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java?rev=778777&r1=778776&r2=778777&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java Tue May 26 15:55:41 2009 @@ -573,10 +573,8 @@ } if (randomize) { // Randomly, reorder the list by random swapping - Random r = new Random(); - r.setSeed(System.currentTimeMillis()); for (int i = 0; i < l.size(); i++) { - int p = r.nextInt(l.size()); + int p = (int) (Math.random()*100 % l.size()); URI t = l.get(p); l.set(p, l.get(i)); l.set(i, t); @@ -585,6 +583,7 @@ if (removed) { l.add(failedConnectTransportURI); } + LOG.debug("urlList connectionList:" + l); return l; } Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java?rev=778777&view=auto ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java (added) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java Tue May 26 15:55:41 2009 @@ -0,0 +1,77 @@ +/** + * 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.transport.failover; + +import junit.framework.TestCase; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; + +public class FailoverRandomTest extends TestCase { + + BrokerService brokerA, brokerB; + + public void setUp() throws Exception { + brokerA = createBroker("A"); + brokerB = createBroker("B"); + } + + public void tearDown() throws Exception { + brokerA.stop(); + brokerB.stop(); + } + + private BrokerService createBroker(String name) throws Exception { + BrokerService broker = new BrokerService(); + broker.setBrokerName("Broker"+ name); + broker.addConnector("tcp://localhost:0"); + broker.getManagementContext().setCreateConnector(false); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.start(); + return broker; + } + + public void testRandomConnections() throws Exception { + String failoverUrl = "failover:(" + + brokerA.getTransportConnectors().get(0).getConnectUri() + + "," + + brokerB.getTransportConnectors().get(0).getConnectUri() + + ")"; + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(failoverUrl); + + + ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); + connection.start(); + String brokerName1 = connection.getBrokerName(); + assertNotNull(brokerName1); + connection.close(); + + String brokerName2 = brokerName1; + int attempts = 5; + while (brokerName1.equals(brokerName2) && attempts-- > 0) { + connection = (ActiveMQConnection) cf.createConnection(); + connection.start(); + brokerName2 = connection.getBrokerName(); + assertNotNull(brokerName2); + connection.close(); + } + assertTrue(brokerName1 + "!=" + brokerName2, !brokerName1.equals(brokerName2)); + } +} Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverRandomTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date