[jboss-cvs] JBossAS SVN: r79339 - in projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton: unit and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 10 05:53:36 EDT 2008
Author: alex.loubyansky at jboss.com
Date: 2008-10-10 05:53:36 -0400 (Fri, 10 Oct 2008)
New Revision: 79339
Modified:
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonBean.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonRemote.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/unit/SingletonUnitTestCase.java
Log:
EJBTHREE-1518 changed the logic for the read concurrency test
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonBean.java 2008-10-10 09:46:23 UTC (rev 79338)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonBean.java 2008-10-10 09:53:36 UTC (rev 79339)
@@ -101,57 +101,34 @@
/**
* This method demonstrates that two threads can be active in the same session bean instance in case of read concurrency.
*
- * 1. check that the value (instance variable) is equal to the expectedCurrentValue.
- * If it's not then wait for the other thread to set it to the expectedCurrentValue.
- * 2. increase the value
- * 3. if the expectedCurrentValue != 0 then just return the current value.
- * Otherwise wait for the other thread to change the value and return the current value.
+ * 1. Increase the current value
+ * 2. If the current value is less than valueThreshold then wait and let other threads to increase the value
+ * until it reaches the valueThreshold.
+ * 3. Return the current value (which should be equal to valueThreshold).
*
* if waiting takes longer than timeout then throw an exception.
*/
- public int getReadLock(int expectedCurrentValue, long timeout)
+ public int getReadLock(int valueThreshold, long timeout)
{
- long startTime = System.currentTimeMillis();
synchronized(instanceLock)
{
- // make sure value has the expected value
- while(expectedCurrentValue != this.value)
+ ++this.value;
+
+ instanceLock.notify();
+
+ // wait until the other thread increases the current value
+ long startTime = System.currentTimeMillis();
+ while (this.value < valueThreshold)
{
if (System.currentTimeMillis() - startTime > timeout)
throw new IllegalStateException("The method took too long.");
+
try
{
instanceLock.wait(timeout);
}
catch (InterruptedException e)
{
- }
- }
-
- // at this point value == expectedCurrentValue
- if(expectedCurrentValue != this.value)
- throw new IllegalStateException("Unexpected instance variable value. Expected " + expectedCurrentValue + " but was " + this.value);
-
- // increase the value
- ++this.value;
- instanceLock.notify();
-
- if(expectedCurrentValue == 0)
- {
- // wait until the other thread increases the current value
- startTime = System.currentTimeMillis();
- while (this.value == expectedCurrentValue + 1)
- {
- if (System.currentTimeMillis() - startTime > timeout)
- throw new IllegalStateException("The method took too long.");
-
- try
- {
- instanceLock.wait(timeout);
- }
- catch (InterruptedException e)
- {
- }
}
}
}
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonRemote.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonRemote.java 2008-10-10 09:46:23 UTC (rev 79338)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/SingletonRemote.java 2008-10-10 09:53:36 UTC (rev 79339)
@@ -43,5 +43,5 @@
/**
* This method demonstrates that two threads can be active in the same session bean instance in case of read concurrency.
*/
- int getReadLock(int expectedCurrentValue, long timeout);
+ int getReadLock(int valueThreshold, long timeout);
}
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/unit/SingletonUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/unit/SingletonUnitTestCase.java 2008-10-10 09:46:23 UTC (rev 79338)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/singleton/unit/SingletonUnitTestCase.java 2008-10-10 09:53:36 UTC (rev 79339)
@@ -135,19 +135,20 @@
{
final SingletonRemote remote = (SingletonRemote) getInitialContext().lookup("SingletonBean/remote");
+ final Thread[] threads = new Thread[5];
+ final int[] results = new int[threads.length];
final Throwable error[] = new Throwable[1];
- final int[] results = new int[2];
- final Thread[] threads = new Thread[2];
+ final int[] finishedThreads = new int[1];
for(int i = 0; i < threads.length; ++i)
{
final int threadIndex = i;
- threads[i] = new Thread(new Runnable()
+ threads[threadIndex] = new Thread(new Runnable()
{
public void run()
{
try
{
- results[threadIndex] = remote.getReadLock(threadIndex, 1000);
+ results[threadIndex] = remote.getReadLock(threads.length, 1000);
}
catch(Throwable t)
{
@@ -156,9 +157,10 @@
}
finally
{
- synchronized (results)
+ synchronized (finishedThreads)
{
- results.notify();
+ ++finishedThreads[0];
+ finishedThreads.notify();
}
}
}
@@ -168,13 +170,13 @@
for(int i = 0; i < threads.length; ++i)
threads[i].start();
- synchronized(results)
+ synchronized(finishedThreads)
{
- while((results[0] == 0 || results[1] == 0) && error[0] == null)
+ while(finishedThreads[0] < threads.length)
{
try
{
- results.wait();
+ finishedThreads.wait();
}
catch(InterruptedException e)
{
@@ -185,8 +187,9 @@
if(error[0] != null)
throw error[0];
- assertEquals(2, results[0]);
- assertEquals(2, results[1]);
+ for(int i = 0; i < threads.length; ++i)
+ assertEquals(threads.length, results[i]);
+
assertEquals(1, remote.getInstanceCount());
}
}
More information about the jboss-cvs-commits
mailing list