[jboss-cvs] JBoss Messaging SVN: r7548 - in branches/Branch_1_4: tests/src/org/jboss/test/messaging/core and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 9 09:37:36 EDT 2009
Author: gaohoward
Date: 2009-07-09 09:37:36 -0400 (Thu, 09 Jul 2009)
New Revision: 7548
Modified:
branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/RotatingID.java
branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java
Log:
JBMESSAGING-1682
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/RotatingID.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/RotatingID.java 2009-07-09 09:32:44 UTC (rev 7547)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/RotatingID.java 2009-07-09 13:37:36 UTC (rev 7548)
@@ -28,10 +28,11 @@
* 64 bits, made up of:
*
* First 16 bits - node id
- * Next 34 bits - lowest 34 bits of system time
- * Next 14 bits - rotating counter
+ * Next 33 bits - lowest 34 bits of system time
+ * Next 15 bits - rotating counter
*
* @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 RotatingID
@@ -56,7 +57,7 @@
{
long id1 = nodeID << 48;
- long id2 = System.currentTimeMillis() << 14;
+ long id2 = (System.currentTimeMillis() << 15) & 0x0000FFFFFFFFFFFFL;
long id = id1 | id2 | count;
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-09 09:32:44 UTC (rev 7547)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java 2009-07-09 13:37:36 UTC (rev 7548)
@@ -21,7 +21,10 @@
*/
package org.jboss.test.messaging.core;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.jboss.messaging.core.impl.RotatingID;
@@ -74,7 +77,72 @@
}
}
+ //https://jira.jboss.org/jira/browse/JBMESSAGING-1682
+ //this test new a RotatingID with node id 8000
+ //in order to examine that the node id field is not
+ //overlapped with the time field.
+ public void testRotatingIDStructure() throws Exception
+ {
+ final int nodeID = 0x8000;
+ 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 & 0x00000001FFFFFFFFL;
+ long endTmVal = endTm & 0x00000001FFFFFFFFL;
+
+ for (int i = 0; i < NUM_ID; i++)
+ {
+ long gid = idlst.get(i);
+
+ long nodeIdVal = (gid >> 48) & 0x000000000000FFFFL;
+ assertEquals(nodeID, nodeIdVal);
+
+ long tmVal = (gid >> 15) & 0x00000001FFFFFFFFL;
+ assertTrue(tmVal > beginTmVal);
+ assertTrue(tmVal < endTmVal);
+
+ long countVal = gid & 0x0000000000007FFFL;
+ assertEquals(countVal, i%(Short.MAX_VALUE + 1));
+ }
+
+ }
+
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
More information about the jboss-cvs-commits
mailing list