[jboss-cvs] JBoss Messaging SVN: r7561 - in branches/Branch_1_4: tests/src/org/jboss/test/messaging/core and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 13 00:05:19 EDT 2009
Author: gaohoward
Date: 2009-07-13 00:05:18 -0400 (Mon, 13 Jul 2009)
New Revision: 7561
Modified:
branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java
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
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java
Log:
JBMESSAGING-1682
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java 2009-07-10 15:07:49 UTC (rev 7560)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/NullPersistenceManager.java 2009-07-13 04:05:18 UTC (rev 7561)
@@ -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: 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-10 15:07:49 UTC (rev 7560)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/RotatingID.java 2009-07-13 04:05:18 UTC (rev 7561)
@@ -27,8 +27,8 @@
*
* 64 bits, made up of:
*
- * First 16 bits - node id
- * Next 33 bits - lowest 34 bits of system time
+ * 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>
@@ -42,23 +42,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() << 15) & 0x0000FFFFFFFFFFFFL;
-
long id = id1 | id2 | count;
if (count == Short.MAX_VALUE)
@@ -69,11 +71,11 @@
//Safety - not likely to happen
- while (now == lastTime)
+ while (now <= lastTime + 8)
{
try
{
- Thread.sleep(1);
+ Thread.sleep(8);
}
catch (InterruptedException e)
{}
@@ -90,4 +92,7 @@
return id;
}
-}
\ No newline at end of file
+}
+
+
+
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-10 15:07:49 UTC (rev 7560)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/RotatingIDTest.java 2009-07-13 04:05:18 UTC (rev 7561)
@@ -34,6 +34,7 @@
* 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
@@ -75,14 +76,75 @@
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 = 2345678;
+
+ 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 8000
+ //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 = 0x8000;
+ final int nodeID = 0x0200;
RotatingID id = new RotatingID(nodeID);
final int NUM_ID = 65535;
Set<Long> ids = new HashSet<Long>(NUM_ID);
@@ -121,17 +183,17 @@
long endTm = System.currentTimeMillis();
- long beginTmVal = beginTm & 0x00000001FFFFFFFFL;
- long endTmVal = endTm & 0x00000001FFFFFFFFL;
+ 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 >> 48) & 0x000000000000FFFFL;
+ long nodeIdVal = (gid >> 54) & 0x00000000000003FFL;
assertEquals(nodeID, nodeIdVal);
- long tmVal = (gid >> 15) & 0x00000001FFFFFFFFL;
+ long tmVal = (gid >> 15) & 0x0000007FFFFFFFFFL;
assertTrue(tmVal > beginTmVal);
assertTrue(tmVal < endTmVal);
@@ -141,7 +203,6 @@
}
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java 2009-07-10 15:07:49 UTC (rev 7560)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerConfigurationTest.java 2009-07-13 04:05:18 UTC (rev 7561)
@@ -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