[infinispan-commits] Infinispan SVN: r699 - trunk/core/src/test/java/org/infinispan/util/concurrent.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Aug 17 09:42:59 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-08-17 09:42:59 -0400 (Mon, 17 Aug 2009)
New Revision: 699
Modified:
trunk/core/src/test/java/org/infinispan/util/concurrent/WatchableValueTest.java
Log:
More robust inter thread comms
Modified: trunk/core/src/test/java/org/infinispan/util/concurrent/WatchableValueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/util/concurrent/WatchableValueTest.java 2009-08-17 13:23:19 UTC (rev 698)
+++ trunk/core/src/test/java/org/infinispan/util/concurrent/WatchableValueTest.java 2009-08-17 13:42:59 UTC (rev 699)
@@ -4,18 +4,21 @@
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
@Test(groups = "unit", testName = "util.concurrent.WatchableValueTest")
public class WatchableValueTest {
public void testNotifier() throws InterruptedException {
final WatchableValue vn = new WatchableValue(10);
final List<Integer> threadsCompleted = new LinkedList<Integer>();
+ final CountDownLatch threadsReady = new CountDownLatch(3), valueSet1 = new CountDownLatch(2), valueSet2 = new CountDownLatch(1);
-
Thread t1 = new Thread() {
public void run() {
try {
+ threadsReady.countDown();
vn.awaitValue(50);
+ valueSet1.countDown();
threadsCompleted.add(1);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -26,7 +29,9 @@
Thread t2 = new Thread() {
public void run() {
try {
+ threadsReady.countDown();
vn.awaitValue(50);
+ valueSet1.countDown();
threadsCompleted.add(2);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -37,7 +42,9 @@
Thread t3 = new Thread() {
public void run() {
try {
+ threadsReady.countDown();
vn.awaitValue(40);
+ valueSet2.countDown();
threadsCompleted.add(3);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -49,16 +56,16 @@
t2.start();
t3.start();
- Thread.sleep(100);
+ threadsReady.await();
assert threadsCompleted.isEmpty();
vn.setValue(50);
- Thread.sleep(100);
+ valueSet1.await();
assert threadsCompleted.size() == 2;
assert threadsCompleted.contains(1);
assert threadsCompleted.contains(2);
vn.setValue(40);
- Thread.sleep(100);
+ valueSet2.await();
assert threadsCompleted.size() == 3;
assert threadsCompleted.contains(3);
}
More information about the infinispan-commits
mailing list