[jboss-cvs] JBoss Messaging SVN: r2958 - in trunk: tests/src/org/jboss/test/messaging/jms/clustering and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 6 11:43:52 EDT 2007


Author: timfox
Date: 2007-08-06 11:43:52 -0400 (Mon, 06 Aug 2007)
New Revision: 2958

Removed:
   trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingFactory.java
   trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingPolicy.java
Modified:
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java
Log:
tests speedup


Deleted: trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingFactory.java	2007-08-06 15:30:34 UTC (rev 2957)
+++ trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingFactory.java	2007-08-06 15:43:52 UTC (rev 2958)
@@ -1,61 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * by the @authors tag. See the copyright.txt in the distribution for a
-   * full listing of individual contributors.
-   *
-   * This is free software; you can redistribute it and/or modify it
-   * under the terms of the GNU Lesser General Public License as
-   * published by the Free Software Foundation; either version 2.1 of
-   * the License, or (at your option) any later version.
-   *
-   * This software is distributed in the hope that it will be useful,
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   * Lesser General Public License for more details.
-   *
-   * You should have received a copy of the GNU Lesser General Public
-   * License along with this software; if not, write to the Free
-   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-   */
-
-package org.jboss.jms.client.plugin;
-
-import org.jboss.jms.delegate.ConnectionFactoryDelegate;
-
-/**
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @version <tt>$Revision$</tt>
- * $Id$
- */
-public class RandomLoadBalancingFactory extends LoadBalancingFactory
-{
-   // Constants ------------------------------------------------------------------------------------
-
-	private static final long serialVersionUID = 1309306819552168488L;
-
-	
-   // Attributes -----------------------------------------------------------------------------------
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   // Public ---------------------------------------------------------------------------------------
-
-	// Implementation of LoadBalancingFactory -------------------------------------------------------
-   public LoadBalancingPolicy createLoadBalancingPolicy(ConnectionFactoryDelegate[] view)
-   {
-      return new RandomLoadBalancingPolicy(view);
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingPolicy.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingPolicy.java	2007-08-06 15:30:34 UTC (rev 2957)
+++ trunk/src/main/org/jboss/jms/client/plugin/RandomLoadBalancingPolicy.java	2007-08-06 15:43:52 UTC (rev 2958)
@@ -1,92 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005, JBoss Inc., and individual contributors as indicated
-   * by the @authors tag. See the copyright.txt in the distribution for a
-   * full listing of individual contributors.
-   *
-   * This is free software; you can redistribute it and/or modify it
-   * under the terms of the GNU Lesser General Public License as
-   * published by the Free Software Foundation; either version 2.1 of
-   * the License, or (at your option) any later version.
-   *
-   * This software is distributed in the hope that it will be useful,
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   * Lesser General Public License for more details.
-   *
-   * You should have received a copy of the GNU Lesser General Public
-   * License along with this software; if not, write to the Free
-   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-   */
-
-package org.jboss.jms.client.plugin;
-
-import org.jboss.jms.delegate.ConnectionFactoryDelegate;
-import java.util.Random;
-
-/**
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @version <tt>$Revision$</tt>
- * $Id$
- */
-public class RandomLoadBalancingPolicy implements LoadBalancingPolicy
-{
-   // Constants ------------------------------------------------------------------------------------
-
-	private static final long serialVersionUID = -4377960504057811985L;
-	
-   // Attributes -----------------------------------------------------------------------------------
-
-	private ConnectionFactoryDelegate[] delegates;
-   private transient Random random = null;
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public RandomLoadBalancingPolicy(ConnectionFactoryDelegate[] delegates)
-   {
-      this.delegates = delegates;
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public synchronized ConnectionFactoryDelegate getNext()
-   {
-      return delegates[randomSelect()];
-   }
-
-   public synchronized void updateView(ConnectionFactoryDelegate[] delegates)
-   {
-      this.delegates = delegates;
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   protected int randomSelect()
-   {
-      if (random == null)
-      {
-      	long seed = System.currentTimeMillis() ^ (long)new Object().hashCode();
-      	
-         random = new Random(seed);
-      }
-      
-      int nextInt = random.nextInt() % delegates.length;
-      
-      if (nextInt < 0)
-      {
-         nextInt *= -1;
-      }
-
-      return nextInt;
-   }
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java	2007-08-06 15:30:34 UTC (rev 2957)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java	2007-08-06 15:43:52 UTC (rev 2958)
@@ -8,19 +8,15 @@
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
-import javax.management.ObjectName;
 import javax.naming.InitialContext;
 
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
 import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.plugin.RandomLoadBalancingPolicy;
 import org.jboss.jms.client.plugin.RoundRobinLoadBalancingPolicy;
 import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.container.ServiceAttributeOverrides;
 
 /**
  * This test DOESN'T extend ClusteringTestBase because I want to have control over first invocations
@@ -31,7 +27,7 @@
  *
  * $Id$
  */
-public class LoadBalancingTest extends MessagingTestCase
+public class LoadBalancingTest extends NewClusteringTestBase
 {
 
    // Constants ------------------------------------------------------------------------------------
@@ -53,105 +49,69 @@
    {
       // the round robin policy is default
 
-      ServerManagement.start(0, "all", true);
+      JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
+      ClientClusteredConnectionFactoryDelegate clusteredDelegate =
+         (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
 
-      try
-      {
-         InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment(0));
+      assertSame(RoundRobinLoadBalancingPolicy.class,
+         clusteredDelegate.getLoadBalancingPolicy().getClass());
 
-         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
+      Connection conn0 = cf.createConnection();
+      
+      final int oneId = getServerId(conn0);
+      final int otherId = 1 - oneId;
 
-         JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
-         ClientClusteredConnectionFactoryDelegate clusteredDelegate =
-            (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
+      Connection conn1 = cf.createConnection();
+      
+      assertEquals(otherId, getServerId(conn1));
 
-         assertSame(RoundRobinLoadBalancingPolicy.class,
-            clusteredDelegate.getLoadBalancingPolicy().getClass());
+      Connection conn2 = cf.createConnection();
+      
+      assertEquals(oneId, getServerId(conn2));
 
-         Connection conn0 = cf.createConnection();
-
-         assertEquals(0, getServerId(conn0));
-
-         Connection conn1 = cf.createConnection();
-
-         assertEquals(0, getServerId(conn1));
-
-         Connection conn2 = cf.createConnection();
-
-         assertEquals(0, getServerId(conn2));
-
-         conn0.close();
-         conn1.close();
-         conn2.close();
-
-         ic.close();
-      }
-      finally
-      {
-         ServerManagement.stop(0);
-      }
+      conn0.close();
+      conn1.close();
+      conn2.close();
    }
+   
 
    public void testRoundRobinLoadBalancingTwoNodes() throws Exception
    {
-      // Make sure all servers are created and started; make sure that database is zapped ONLY for
-      // the first server, the others rely on values they expect to find in shared tables; don't
-      // clear the database for those.
+      JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
+      ClientClusteredConnectionFactoryDelegate clusteredDelegate =
+         (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
 
-      ServerManagement.start(0, "all", true);
-      ServerManagement.start(1, "all", false);
+      assertSame(RoundRobinLoadBalancingPolicy.class,
+         clusteredDelegate.getLoadBalancingPolicy().getClass());
 
-      // the round robin policy is default
+      Connection conn0 = cf.createConnection();
+      
+      final int oneId = getServerId(conn0);
+      final int otherId = 1 - oneId;
 
-      try
-      {
-         InitialContext ic0 = new InitialContext(ServerManagement.getJNDIEnvironment(0));
+      assertEquals(oneId, getServerId(conn0));
 
-         ConnectionFactory cf = (ConnectionFactory)ic0.lookup("/ClusteredConnectionFactory");
+      Connection conn1 = cf.createConnection();
 
-         JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
-         ClientClusteredConnectionFactoryDelegate clusteredDelegate =
-            (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
+      assertEquals(otherId, getServerId(conn1));
 
-         assertSame(RoundRobinLoadBalancingPolicy.class,
-            clusteredDelegate.getLoadBalancingPolicy().getClass());
+      Connection conn2 = cf.createConnection();
 
-         Connection conn0 = cf.createConnection();
-         
-         final int oneId = getServerId(conn0);
-         final int otherId = 1 - oneId;
+      assertEquals(oneId, getServerId(conn2));
 
-         assertEquals(oneId, getServerId(conn0));
+      Connection conn3 = cf.createConnection();
 
-         Connection conn1 = cf.createConnection();
+      assertEquals(otherId, getServerId(conn3));
 
-         assertEquals(otherId, getServerId(conn1));
+      Connection conn4 = cf.createConnection();
 
-         Connection conn2 = cf.createConnection();
+      assertEquals(oneId, getServerId(conn4));
 
-         assertEquals(oneId, getServerId(conn2));
-
-         Connection conn3 = cf.createConnection();
-
-         assertEquals(otherId, getServerId(conn3));
-
-         Connection conn4 = cf.createConnection();
-
-         assertEquals(oneId, getServerId(conn4));
-
-         conn0.close();
-         conn1.close();
-         conn2.close();
-         conn3.close();
-         conn4.close();
-
-         ic0.close();
-      }
-      finally
-      {
-         ServerManagement.stop(1);
-         ServerManagement.stop(0);
-      }
+      conn0.close();
+      conn1.close();
+      conn2.close();
+      conn3.close();
+      conn4.close();
    }
    
    public void testRoundRobinLoadBalancingStartsWithRandomNode() throws Exception
@@ -160,143 +120,25 @@
       // the first server, the others rely on values they expect to find in shared tables; don't
       // clear the database for those.
 
-      ServerManagement.start(0, "all", true);
-      ServerManagement.start(1, "all", false);
-
-      try
+      int[] counts = new int[2];
+      
+      for (int i = 0; i < 10; i++)
       {
-         int[] counts = new int[2];
-         
-         for (int i = 0; i < 10; i++)
-         {
-            InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment(0));
-            ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
-            Connection firstConnection = cf.createConnection();
-            int serverPeerID = getServerId(firstConnection);
-            firstConnection.close();
-            ic.close();
+         InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment(0));
+         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
+         Connection firstConnection = cf.createConnection();
+         int serverPeerID = getServerId(firstConnection);
+         firstConnection.close();
+         ic.close();
 
-            counts[serverPeerID]++;
-         }
-         
-         assertTrue("Should have connected to ServerPeer 0 at least once", counts[0] > 0);
-         assertTrue("Should have connected to ServerPeer 1 at least once", counts[1] > 0);
+         counts[serverPeerID]++;
       }
-      finally
-      {
-         ServerManagement.stop(1);
-         ServerManagement.stop(0);
-      }
+      
+      assertTrue("Should have connected to ServerPeer 0 at least once", counts[0] > 0);
+      assertTrue("Should have connected to ServerPeer 1 at least once", counts[1] > 0);
    }
 
-   public void testRandomRobinLoadBalancingSingleNode() throws Exception
-   {
-      // Make sure all servers are created and started; make sure that database is zapped ONLY for
-      // the first server, the others rely on values they expect to find in shared tables; don't
-      // clear the database for those.
-
-      ServiceAttributeOverrides override = new ServiceAttributeOverrides();
-      override.put(new ObjectName("jboss.messaging.connectionfactory:service=ClusteredConnectionFactory"),
-         "LoadBalancingFactory", "org.jboss.jms.client.plugin.RandomLoadBalancingFactory");
-      ServerManagement.start(0, "all", override, true);
-
-      try
-      {
-         InitialContext ic0 = new InitialContext(ServerManagement.getJNDIEnvironment(0));
-
-         ConnectionFactory cf = (ConnectionFactory)ic0.lookup("/ClusteredConnectionFactory");
-
-         JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
-         ClientClusteredConnectionFactoryDelegate clusteredDelegate =
-            (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
-
-         assertSame(RandomLoadBalancingPolicy.class,
-            clusteredDelegate.getLoadBalancingPolicy().getClass());
-
-         Connection conn0 = cf.createConnection();
-         assertEquals(0, getConnectionState(conn0).getServerID());
-
-         Connection conn1 = cf.createConnection();
-         assertEquals(0, getConnectionState(conn1).getServerID());
-
-         Connection conn2 = cf.createConnection();
-         assertEquals(0, getConnectionState(conn2).getServerID());
-
-         Connection conn3 = cf.createConnection();
-         assertEquals(0, getConnectionState(conn3).getServerID());
-
-         Connection conn4 = cf.createConnection();
-         assertEquals(0, getConnectionState(conn4).getServerID());
-
-         conn0.close();
-         conn1.close();
-         conn2.close();
-         conn3.close();
-         conn4.close();
-
-         ic0.close();
-      }
-      finally
-      {
-         ServerManagement.stop(1);
-         ServerManagement.stop(0);
-      }
-   }
-
-
-
-   public void testRandomRobinLoadBalancingTwoNodes() throws Exception
-   {
-      // Make sure all servers are created and started; make sure that database is zapped ONLY for
-      // the first server, the others rely on values they expect to find in shared tables; don't
-      // clear the database for those.
-
-      ServiceAttributeOverrides override = new ServiceAttributeOverrides();
-      override.put(new ObjectName("jboss.messaging.connectionfactory:service=ClusteredConnectionFactory"),
-         "LoadBalancingFactory", "org.jboss.jms.client.plugin.RandomLoadBalancingFactory");
-      ServerManagement.start(0, "all", override, true);
-      ServerManagement.start(1, "all", override, false);
-
-      try
-      {
-         InitialContext ic0 = new InitialContext(ServerManagement.getJNDIEnvironment(0));
-
-         ConnectionFactory cf = (ConnectionFactory)ic0.lookup("/ClusteredConnectionFactory");
-
-         JBossConnectionFactory jbcf = (JBossConnectionFactory)cf;
-         ClientClusteredConnectionFactoryDelegate clusteredDelegate =
-            (ClientClusteredConnectionFactoryDelegate )jbcf.getDelegate();
-
-         assertSame(RandomLoadBalancingPolicy.class,
-            clusteredDelegate.getLoadBalancingPolicy().getClass());
-
-         Connection conn0 = cf.createConnection();
-
-         Connection conn1 = cf.createConnection();
-
-         Connection conn2 = cf.createConnection();
-
-         Connection conn3 = cf.createConnection();
-
-         Connection conn4 = cf.createConnection();
-
-         conn0.close();
-         conn1.close();
-         conn2.close();
-         conn3.close();
-         conn4.close();
-
-         ic0.close();
-      }
-      finally
-      {
-         ServerManagement.stop(1);
-         ServerManagement.stop(0);
-      }
-   }
-
-
-
+ 
    // Package protected ----------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------
@@ -309,15 +151,10 @@
 
    protected void setUp() throws Exception
    {
+   	nodeCount = 2;
       super.setUp();
-      log.debug("setup done");
    }
 
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-   }
-
    // Private --------------------------------------------------------------------------------------
 
    // Inner classes --------------------------------------------------------------------------------




More information about the jboss-cvs-commits mailing list