ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPoolTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.67 by jsr166, Thu Oct 8 03:03:36 2015 UTC vs.
Revision 1.70 by jsr166, Tue Oct 13 21:18:28 2015 UTC

# Line 213 | Line 213 | public class ForkJoinPoolTest extends JS
213       * getPoolSize returns number of started workers.
214       */
215      public void testGetPoolSize() {
216 <        ForkJoinPool p = new ForkJoinPool(1);
216 >        final CountDownLatch taskStarted = new CountDownLatch(1);
217 >        final CountDownLatch done = new CountDownLatch(1);
218 >        final ForkJoinPool p = new ForkJoinPool(1);
219          try (PoolCleaner cleaner = cleaner(p)) {
220              assertEquals(0, p.getActiveThreadCount());
221 <            Future<String> future = p.submit(new StringTask());
221 >            final Runnable task = new CheckedRunnable() {
222 >                public void realRun() throws InterruptedException {
223 >                    taskStarted.countDown();
224 >                    assertEquals(1, p.getPoolSize());
225 >                    assertEquals(1, p.getActiveThreadCount());
226 >                    done.await();
227 >                }};
228 >            Future<?> future = p.submit(task);
229 >            await(taskStarted);
230              assertEquals(1, p.getPoolSize());
231 +            assertEquals(1, p.getActiveThreadCount());
232 +            done.countDown();
233          }
234 +        assertEquals(0, p.getPoolSize());
235 +        assertEquals(0, p.getActiveThreadCount());
236      }
237  
238      /**
# Line 305 | Line 319 | public class ForkJoinPoolTest extends JS
319  
320              assertTrue(p.isQuiescent());
321              assertFalse(p.getAsyncMode());
308            assertEquals(0, p.getActiveThreadCount());
322              assertEquals(0, p.getQueuedTaskCount());
323              assertEquals(0, p.getQueuedSubmissionCount());
324              assertFalse(p.hasQueuedSubmissions());
325 +            while (p.getActiveThreadCount() != 0
326 +                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
327 +                Thread.yield();
328              assertFalse(p.isShutdown());
329              assertFalse(p.isTerminating());
330              assertFalse(p.isTerminated());
331              assertTrue(f.isDone());
332              assertEquals(6765, (int) f.get());
333 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
334          }
335      }
336  
# Line 840 | Line 857 | public class ForkJoinPoolTest extends JS
857      public void testTimedInvokeAny5() throws Throwable {
858          ExecutorService e = new ForkJoinPool(1);
859          try (PoolCleaner cleaner = cleaner(e)) {
860 +            long startTime = System.nanoTime();
861              List<Callable<String>> l = new ArrayList<Callable<String>>();
862              l.add(new StringTask());
863              l.add(new StringTask());
864 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
864 >            String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
865              assertSame(TEST_STRING, result);
866 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
867          }
868      }
869  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines