Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

avoids reusing Executor's Thread instances

  • Loading branch information...
commit 7602636601a8e024f27157cdbabee6de7e269d80 1 parent 24cbcbc
@Tibor17 authored
View
20 src/test/java/org/junit/tests/experimental/parallel/ParallelMethodTest.java
@@ -10,28 +10,38 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.Before;
+import org.junit.BeforeClass;
+import java.util.concurrent.CountDownLatch;
public class ParallelMethodTest {
private static volatile Thread fOne= null;
private static volatile Thread fTwo= null;
public static class Example {
- @Test public void one() {
+ private static volatile CountDownLatch fSynchronizer;
+
+ @BeforeClass public static void init() {
+ fSynchronizer= new CountDownLatch(2);
+ }
+ @Test public void one() throws InterruptedException {
+ fSynchronizer.countDown();
+ fSynchronizer.await();
fOne= Thread.currentThread();
}
- @Test public void two() {
+ @Test public void two() throws InterruptedException {
+ fSynchronizer.countDown();
+ fSynchronizer.await();
fTwo= Thread.currentThread();
}
}
- @Before public void cleanupReferences() {
+ @Before public void init() {
fOne= null;
fTwo= null;
}
@Test public void testsRunInParallel() {
- Result result= JUnitCore.runClasses(ParallelComputer.methods(),
- Example.class);
+ Result result= JUnitCore.runClasses(ParallelComputer.methods(), Example.class);
assertTrue(result.wasSuccessful());
assertNotNull(fOne);
assertNotNull(fTwo);
Please sign in to comment.
Something went wrong with that request. Please try again.