[jboss-cvs] JBoss Messaging SVN: r6098 - in trunk: tests/src/org/jboss/messaging/tests/unit/util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 16 23:08:18 EDT 2009
Author: clebert.suconic at jboss.com
Date: 2009-03-16 23:08:17 -0400 (Mon, 16 Mar 2009)
New Revision: 6098
Modified:
trunk/src/main/org/jboss/messaging/utils/SimpleString.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java
Log:
Fixing hashCode on SimpleString
Modified: trunk/src/main/org/jboss/messaging/utils/SimpleString.java
===================================================================
--- trunk/src/main/org/jboss/messaging/utils/SimpleString.java 2009-03-16 23:39:46 UTC (rev 6097)
+++ trunk/src/main/org/jboss/messaging/utils/SimpleString.java 2009-03-17 03:08:17 UTC (rev 6098)
@@ -237,10 +237,12 @@
{
if (hash == 0)
{
+ int tmphash = 0;
for (int i = 0; i < data.length; i++)
{
- hash = (hash << 5) - hash + data[i]; // (hash << 5) - hash is same as hash * 31
+ tmphash = (tmphash << 5) - tmphash + data[i]; // (hash << 5) - hash is same as hash * 31
}
+ hash = tmphash;
}
return hash;
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java 2009-03-16 23:39:46 UTC (rev 6097)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java 2009-03-17 03:08:17 UTC (rev 6098)
@@ -24,6 +24,8 @@
import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import java.util.concurrent.CountDownLatch;
+
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.utils.DataConstants;
import org.jboss.messaging.utils.SimpleString;
@@ -323,4 +325,76 @@
}
}
+
+
+ public void testMultithreadHashCode() throws Exception
+ {
+ for (int repeat = 0; repeat < 10; repeat++)
+ {
+
+ StringBuffer buffer = new StringBuffer();
+
+ for (int i = 0 ; i < 100; i++)
+ {
+ buffer.append("Some Big String " + i);
+ }
+ String strvalue = buffer.toString();
+
+ final int initialhash = new SimpleString(strvalue).hashCode();
+
+ final SimpleString value = new SimpleString(strvalue);
+
+
+ int nThreads = 100;
+ final CountDownLatch latch = new CountDownLatch(nThreads);
+ final CountDownLatch start = new CountDownLatch(1);
+
+ class T extends Thread
+ {
+ boolean failed = false;
+
+ public void run()
+ {
+ try
+ {
+ latch.countDown();
+ start.await();
+
+ int newhash = value.hashCode();
+
+ if (newhash != initialhash)
+ {
+ failed = true;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ failed = true;
+ }
+ }
+ }
+
+ T x[] = new T[nThreads];
+ for (int i = 0; i < nThreads; i++)
+ {
+ x[i] = new T();
+ x[i].start();
+ }
+
+ latch.await();
+ start.countDown();
+
+ for (T t : x)
+ {
+ t.join();
+ }
+
+ for (T t : x)
+ {
+ assertFalse(t.failed);
+ }
+ }
+ }
+
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java 2009-03-16 23:39:46 UTC (rev 6097)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java 2009-03-17 03:08:17 UTC (rev 6098)
@@ -240,6 +240,15 @@
char cc = (Character) props.getProperty(key);
assertEquals(c, cc);
}
+
+ public void testSimpleString() throws Exception
+ {
+ props = new TypedProperties();
+ SimpleString value = randomSimpleString();
+ props.putStringProperty(key, value);
+ SimpleString vv = (SimpleString)props.getProperty(key);
+ assertEquals(value, vv);
+ }
public void testTypedProperties() throws Exception
{
More information about the jboss-cvs-commits
mailing list