[jboss-cvs] JBoss Messaging SVN: r7567 - in tags: JBossMessaging_1_4_0_SP3_CP08.patch01 and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 14 03:32:02 EDT 2009
Author: gaohoward
Date: 2009-07-14 03:32:02 -0400 (Tue, 14 Jul 2009)
New Revision: 7567
Added:
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/
Modified:
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/build-messaging.xml
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/RotatingID.java
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java
tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java
Log:
JBMESSAGING-1683
create patch01 for cp08
Copied: tags/JBossMessaging_1_4_0_SP3_CP08.patch01 (from rev 7566, tags/JBossMessaging_1_4_0_SP3_CP08)
Modified: tags/JBossMessaging_1_4_0_SP3_CP08.patch01/build-messaging.xml
===================================================================
--- tags/JBossMessaging_1_4_0_SP3_CP08/build-messaging.xml 2009-07-14 01:23:11 UTC (rev 7566)
+++ tags/JBossMessaging_1_4_0_SP3_CP08.patch01/build-messaging.xml 2009-07-14 07:32:02 UTC (rev 7567)
@@ -53,9 +53,9 @@
<property name="messaging.version.minor" value="4"/>
<property name="messaging.version.revision" value="0"/>
<property name="messaging.version.incrementing" value="32"/>
- <property name="messaging.version.tag" value="SP3-CP08"/>
+ <property name="messaging.version.tag" value="SP3-CP08.patch01"/>
<property name="messaging.version.name" value="MaunaLoa"/>
- <property name="messaging.version.cvstag" value="JBossMessaging_1_4_0_SP3_CP08"/>
+ <property name="messaging.version.cvstag" value="JBossMessaging_1_4_0_SP3_CP08.patch01"/>
<property name="module.name" value="messaging"/>
<property name="module.Name" value="JBoss Messaging"/>
<property name="module.version" value="${messaging.version.major}.${messaging.version.minor}.${messaging.version.revision}.${messaging.version.tag}"/>
Modified: tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java
===================================================================
--- tags/JBossMessaging_1_4_0_SP3_CP08/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java 2009-07-14 01:23:11 UTC (rev 7566)
+++ tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java 2009-07-14 07:32:02 UTC (rev 7567)
@@ -39,11 +39,11 @@
*/
public class NullPersistenceManager implements PersistenceManager
{
- private static final int MAX_PEER_ID = 65535;
+ private static final int MAX_PEER_ID = 1023;
private ConcurrentMap<String, IDCounter> counters = new ConcurrentHashMap<String, IDCounter>();
- private int peerID; // 0 - 65535
+ private int peerID; // 0 - 1023
private long timeMark;
Modified: tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/RotatingID.java
===================================================================
--- tags/JBossMessaging_1_4_0_SP3_CP08/src/main/org/jboss/messaging/core/impl/RotatingID.java 2009-07-14 01:23:11 UTC (rev 7566)
+++ tags/JBossMessaging_1_4_0_SP3_CP08.patch01/src/main/org/jboss/messaging/core/impl/RotatingID.java 2009-07-14 07:32:02 UTC (rev 7567)
@@ -27,9 +27,9 @@
*
* 64 bits, made up of:
*
- * First 16 bits - node id
- * Next 34 bits - lowest 34 bits of system time
- * Next 14 bits - rotating counter
+ * First 10 bits - node id
+ * Next 39 bits - 4th - 42nd bits of system time
+ * Next 15 bits - rotating counter
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*
@@ -41,23 +41,25 @@
private long lastTime = System.currentTimeMillis();
private final long nodeID;
+
+ private final long id1;
public RotatingID(final int nodeID)
{
- if (nodeID < 0 || nodeID > 65535)
+ if (nodeID < 0 || nodeID > 1023)
{
- throw new IllegalArgumentException("node id must be between 0 to 65535 inclusive");
+ throw new IllegalArgumentException("node id must be between 0 to 1023 inclusive, wrong id: " + nodeID);
}
this.nodeID = nodeID;
+ id1 = this.nodeID << 54;
}
public synchronized long getID()
{
- long id1 = nodeID << 48;
+ //https://jira.jboss.org/jira/browse/JBMESSAGING-1682
+ long id2 = (System.currentTimeMillis() << 12) & 0x003FFFFFFFFF8000L;
- long id2 = System.currentTimeMillis() << 14;
-
long id = id1 | id2 | count;
if (count == Short.MAX_VALUE)
@@ -68,11 +70,11 @@
//Safety - not likely to happen
- while (now == lastTime)
+ while (now <= lastTime + 8)
{
try
{
- Thread.sleep(1);
+ Thread.sleep(8);
}
catch (InterruptedException e)
{}
@@ -89,4 +91,4 @@
return id;
}
-}
\ No newline at end of file
+}
Modified: tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java
===================================================================
--- tags/JBossMessaging_1_4_0_SP3_CP08/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java 2009-07-14 01:23:11 UTC (rev 7566)
+++ tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java 2009-07-14 07:32:02 UTC (rev 7567)
@@ -21,8 +21,16 @@
*/
package org.jboss.test.messaging.core;
+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;
@@ -32,12 +40,15 @@
* A RotatingIDTest
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
*
*/
public class RotatingIDTest extends MessagingTestCase
{
// Constants -----------------------------------------------------
+ private String failMsg = null;
+
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
@@ -50,6 +61,13 @@
}
// Public --------------------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ failMsg = null;
+ }
+
public void testRotatingID() throws Exception
{
@@ -73,8 +91,165 @@
System.out.println(l);
}
}
+
+ public void testNodeIDLimits() throws Exception
+ {
+ //max id 1023, fine
+ int nodeID = 0x03FF;
+ new RotatingID(nodeID);
+
+ //min id 0, fine
+ new RotatingID(0);
+
+ //wrong id 1024, exceeding max
+ nodeID = 1024;
+ try
+ {
+ new RotatingID(nodeID);
+ fail("shouldn't allow values greater than 1023!");
+ }
+ catch (IllegalArgumentException e)
+ {
+ //ignore
+ }
+
+ //negative id
+ nodeID = -1;
+ try
+ {
+ new RotatingID(nodeID);
+ fail("shouldn't allow negative values!");
+ }
+ catch (IllegalArgumentException e)
+ {
+ //ignore
+ }
+ }
+ //Because we now use 4th to 42nd bits of time,
+ //the max rate of generating id should never be greater than 4096000 ids/sec.
+ public void testIDGenSpeed() throws Exception
+ {
+ RotatingID id = new RotatingID(555);
+ long beginTm = System.currentTimeMillis();
+
+ final int NUM_IDS = 4096000;
+
+ for (int i = 0; i < NUM_IDS; i++)
+ {
+ id.getID();
+ }
+
+ long endTm = System.currentTimeMillis();
+
+ long dur = (endTm - beginTm)/1000;
+
+ long rate = NUM_IDS/dur;
+
+ log.info("duration: " + dur);
+ log.info("sending Rate: " + rate);
+
+ assertTrue(rate <= 4096000);
+ }
+
+ //https://jira.jboss.org/jira/browse/JBMESSAGING-1682
+ //this test new a RotatingID with node id 0200
+ //in order to examine that the node id field is not
+ //overlapped with the time field.
+ public void testRotatingIDStructure() throws Exception
+ {
+ final int nodeID = 0x0200;
+ RotatingID id = new RotatingID(nodeID);
+ final int NUM_ID = 65535;
+ Set<Long> ids = new HashSet<Long>(NUM_ID);
+ List<Long> idlst = new ArrayList<Long>(NUM_ID);
+
+ long beginTm = System.currentTimeMillis();
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ //ignore
+ }
+
+ for (int i = 0; i < NUM_ID; i++)
+ {
+ long mid = id.getID();
+ if (ids.contains(mid))
+ {
+ fail("Already produced id " + mid);
+ }
+ ids.add(mid);
+ idlst.add(mid);
+ }
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ //ignore
+ }
+
+ long endTm = System.currentTimeMillis();
+
+ long beginTmVal = (beginTm >> 3) & 0x0000007FFFFFFFFFL;
+ long endTmVal = (endTm >> 3) & 0x0000007FFFFFFFFFL;
+
+ for (int i = 0; i < NUM_ID; i++)
+ {
+ long gid = idlst.get(i);
+
+ long nodeIdVal = (gid >> 54) & 0x00000000000003FFL;
+ assertEquals(nodeID, nodeIdVal);
+
+ long tmVal = (gid >> 15) & 0x0000007FFFFFFFFFL;
+ assertTrue(tmVal > beginTmVal);
+ assertTrue(tmVal < endTmVal);
+
+ long countVal = gid & 0x0000000000007FFFL;
+ assertEquals(countVal, i%(Short.MAX_VALUE + 1));
+ }
+
+ }
+
+ //50 generators, each generating 100,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.newFixedThreadPool(50);
+
+ 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 -----------------------------------------------------
@@ -82,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 < 100000 && notFail(); i++)
+ {
+ long id = idGen.getID();
+ if (holder.get(id) != null)
+ {
+ setFail("Duplicated ID has been generated: " + id);
+ }
+ holder.put(id, id);
+ }
+ }
+ }
}
Modified: tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java
===================================================================
--- tags/JBossMessaging_1_4_0_SP3_CP08/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java 2009-07-14 01:23:11 UTC (rev 7566)
+++ tags/JBossMessaging_1_4_0_SP3_CP08.patch01/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java 2009-07-14 07:32:02 UTC (rev 7567)
@@ -106,7 +106,7 @@
LocalTestServer server = new LocalTestServer();
ServiceAttributeOverrides overrides = new ServiceAttributeOverrides();
// Can't use server.getServerPeerObjectName() here since it's not known to the server yet.
- overrides.put(ServiceContainer.SERVER_PEER_OBJECT_NAME, "ServerPeerID", "65535");
+ overrides.put(ServiceContainer.SERVER_PEER_OBJECT_NAME, "ServerPeerID", "1023");
try
{
@@ -114,13 +114,35 @@
}
catch (RuntimeMBeanException rmbe)
{
- fail("Large ServerPeerID should be allowed (0 - 65535)");
+ fail("Largest ServerPeerID should be allowed (0 - 1023)");
}
finally
{
server.stop();
}
}
+
+ public void testServerPeerIDLimit2() throws Exception
+ {
+ LocalTestServer server = new LocalTestServer();
+ ServiceAttributeOverrides overrides = new ServiceAttributeOverrides();
+ // Can't use server.getServerPeerObjectName() here since it's not known to the server yet.
+ overrides.put(ServiceContainer.SERVER_PEER_OBJECT_NAME, "ServerPeerID", "1024");
+
+ try
+ {
+ server.start("all", overrides, false, true);
+ fail("Largest ServerPeerID should be less than 1024");
+ }
+ catch (RuntimeMBeanException rmbe)
+ {
+ //ignore
+ }
+ finally
+ {
+ server.stop();
+ }
+ }
// Package protected ---------------------------------------------
More information about the jboss-cvs-commits
mailing list