OPENJPA-1022 - correct test case to properly handle notify/wait testing protocol between multi-threads test scenario. This fix corrects some timing related failures.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@762559 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Albert Lee 2009-04-06 22:59:21 +00:00
parent bdce39ae28
commit 4386138356
1 changed files with 15 additions and 2 deletions

View File

@ -294,7 +294,7 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
} }
} }
int numThreads = actions.length; int numThreads = actions.length;
threads = new ArrayList<TestThread>(numThreads - 1); threads = new ArrayList<TestThread>(numThreads);
TestThread mainThread = new TestThread(0, actions); TestThread mainThread = new TestThread(0, actions);
threads.add(mainThread); threads.add(mainThread);
launchCommonSequence(mainThread); launchCommonSequence(mainThread);
@ -508,6 +508,10 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
threads.get((Integer) args[1]).start(); threads.get((Integer) args[1]).start();
break; break;
case Notify: case Notify:
// sleep and let other threads has a chance to wait,
// otherwise this notify may trigger before the other
// thread has a chance to wait.
Thread.sleep(500);
int notifyThreadid = 0; int notifyThreadid = 0;
if (args.length > 1 && args[1] != null) { if (args.length > 1 && args[1] != null) {
notifyThreadid = (Integer) args[1]; notifyThreadid = (Integer) args[1];
@ -526,10 +530,12 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
if (args.length > 1 && args[1] != null) { if (args.length > 1 && args[1] != null) {
waitThreadid = (Integer) args[1]; waitThreadid = (Integer) args[1];
} }
int waitTime = 5000; //15000; int waitTime = (int)(waitInMsec / 5);
if (args.length > 2 && args[2] != null) { if (args.length > 2 && args[2] != null) {
waitTime = (Integer) args[2]; waitTime = (Integer) args[2];
} }
if( waitTime < 15000)
waitTime = 15000;
if( waitThreadid != 0) { if( waitThreadid != 0) {
thisThread.wait(waitTime); thisThread.wait(waitTime);
} else { } else {
@ -898,6 +904,13 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
} }
public synchronized void run() { public synchronized void run() {
// sleep and let other threads has a chance to do stuffs,
// otherwise this new thread may perform a notify before
// the other thread has a chance to wait.
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
getLog().trace("Thread " + threadToRun + ": run()"); getLog().trace("Thread " + threadToRun + ": run()");
launchCommonSequence(this); launchCommonSequence(this);
} }