[jboss-cvs] JBoss Messaging SVN: r7563 - branches/Branch_1_4/tests/src/org/jboss/test/messaging/core.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 13 06:52:39 EDT 2009


Author: gaohoward
Date: 2009-07-13 06:52:39 -0400 (Mon, 13 Jul 2009)
New Revision: 7563

Modified:
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java
Log:
JBMESSAGING-1682
more test


Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java	2009-07-13 09:04:28 UTC (rev 7562)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java	2009-07-13 10:52:39 UTC (rev 7563)
@@ -24,7 +24,13 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Random;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.jboss.messaging.core.impl.RotatingID;
 import org.jboss.test.messaging.MessagingTestCase;
@@ -41,6 +47,8 @@
 {
    // Constants -----------------------------------------------------
 
+   private String failMsg = null;
+   
    // Static --------------------------------------------------------
 
    // Attributes ----------------------------------------------------
@@ -53,6 +61,13 @@
    }
 
    // Public --------------------------------------------------------
+   
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      failMsg = null;
+   }
+   
 
    public void testRotatingID() throws Exception
    {
@@ -202,7 +217,39 @@
       }
 
    }
+   
+   //50 generators, each generating 200,000 ids, 
+   //check uniqueness of those ids
+   public void testIDConflict() throws Exception
+   {
+      final int numNodes = 50;
+      Random rand = new Random();
+      final Map<Long, Long> ids = new ConcurrentHashMap<Long, Long>(10000000);
+      ExecutorService pool = Executors.newCachedThreadPool();
 
+      int nid = rand.nextInt(1024);
+      for (int i = 0; i < numNodes; i++)
+      {
+         int id = (nid+i)%1024;
+         log.info("Random node id: " + id);
+         pool.execute(new IDGenerator(new RotatingID(id), ids));
+      }
+      
+      pool.shutdown();
+      pool.awaitTermination(600, TimeUnit.SECONDS);
+      
+      assertNull(failMsg, failMsg);
+   }
+
+   public synchronized void setFail(String error)
+   {
+      failMsg = error;
+   }
+   
+   public synchronized boolean notFail()
+   {
+      return failMsg == null;
+   }
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -210,6 +257,29 @@
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
-
+   private class IDGenerator implements Runnable
+   {
+      private RotatingID idGen;
+      private Map<Long, Long> holder;
+      
+      public IDGenerator(RotatingID rid, Map<Long, Long> ids)
+      {
+         idGen = rid;
+         holder = ids;
+      }
+      
+      public void run()
+      {
+         for (int i = 0; i < 200000 && notFail(); i++)
+         {
+            long id = idGen.getID();
+            if (holder.get(id) != null)
+            {
+               setFail("Duplicated ID has been generated: " + id);
+            }
+            holder.put(id, id);
+         }
+      }
+   }
 }
 




More information about the jboss-cvs-commits mailing list