From 7602636601a8e024f27157cdbabee6de7e269d80 Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Fri, 21 Sep 2012 18:38:22 +0200 Subject: [PATCH] avoids reusing Executor's Thread instances --- .../parallel/ParallelMethodTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/junit/tests/experimental/parallel/ParallelMethodTest.java b/src/test/java/org/junit/tests/experimental/parallel/ParallelMethodTest.java index 407d9ca22e11..e767de7c2cca 100644 --- a/src/test/java/org/junit/tests/experimental/parallel/ParallelMethodTest.java +++ b/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);