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

Comparing jsr166/src/test/tck/CountedCompleterTest.java (file contents):
Revision 1.17 by jsr166, Fri Feb 27 21:43:18 2015 UTC vs.
Revision 1.21 by jsr166, Sun Oct 18 16:43:53 2015 UTC

# Line 23 | Line 23 | import junit.framework.TestSuite;
23   public class CountedCompleterTest extends JSR166TestCase {
24  
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28  
29      public static Test suite() {
# Line 49 | Line 49 | public class CountedCompleterTest extend
49      }
50  
51      private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) {
52 <        try {
52 >        try (PoolCleaner cleaner = cleaner(pool)) {
53              assertFalse(a.isDone());
54              assertFalse(a.isCompletedNormally());
55              assertFalse(a.isCompletedAbnormally());
# Line 65 | Line 65 | public class CountedCompleterTest extend
65              assertFalse(a.isCancelled());
66              assertNull(a.getException());
67              assertNull(a.getRawResult());
68        } finally {
69            joinPool(pool);
68          }
69      }
70  
# Line 95 | Line 93 | public class CountedCompleterTest extend
93  
94          {
95              Thread.currentThread().interrupt();
96 <            long t0 = System.nanoTime();
96 >            long startTime = System.nanoTime();
97              assertNull(a.join());
98 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
98 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
99              Thread.interrupted();
100          }
101  
102          {
103              Thread.currentThread().interrupt();
104 <            long t0 = System.nanoTime();
104 >            long startTime = System.nanoTime();
105              a.quietlyJoin();        // should be no-op
106 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
106 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
107              Thread.interrupted();
108          }
109  
# Line 138 | Line 136 | public class CountedCompleterTest extend
136          Thread.interrupted();
137  
138          {
139 <            long t0 = System.nanoTime();
139 >            long startTime = System.nanoTime();
140              a.quietlyJoin();        // should be no-op
141 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
141 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
142          }
143  
144          try {
# Line 176 | Line 174 | public class CountedCompleterTest extend
174          Thread.interrupted();
175  
176          {
177 <            long t0 = System.nanoTime();
177 >            long startTime = System.nanoTime();
178              a.quietlyJoin();        // should be no-op
179 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
179 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
180          }
181  
182          try {
# Line 280 | Line 278 | public class CountedCompleterTest extend
278      final class NoopCC extends CheckedCC {
279          NoopCC() { super(); }
280          NoopCC(CountedCompleter p) { super(p); }
281 +        NoopCC(CountedCompleter p, int initialPendingCount) {
282 +            super(p, initialPendingCount);
283 +        }
284          protected void realCompute() {}
285      }
286  
# Line 311 | Line 312 | public class CountedCompleterTest extend
312      }
313  
314      /**
315 <     * completeExceptionally(null) throws NullPointerException
315 >     * completeExceptionally(null) surprisingly has the same effect as
316 >     * completeExceptionally(new RuntimeException())
317       */
318      public void testCompleteExceptionally_null() {
319 +        NoopCC a = new NoopCC();
320 +        a.completeExceptionally(null);
321          try {
322 <            new NoopCC()
319 <                .checkCompletesExceptionally(null);
322 >            a.invoke();
323              shouldThrow();
324 <        } catch (NullPointerException success) {}
324 >        } catch (RuntimeException success) {
325 >            assertSame(success.getClass(), RuntimeException.class);
326 >            assertNull(success.getCause());
327 >            a.checkCompletedExceptionally(success);
328 >        }
329      }
330  
331      /**
# Line 349 | Line 356 | public class CountedCompleterTest extend
356       * decrementPendingCountUnlessZero decrements reported pending
357       * count unless zero
358       */
359 <    public void testDecrementPendingCount() {
360 <        NoopCC a = new NoopCC();
361 <        assertEquals(0, a.getPendingCount());
362 <        a.addToPendingCount(1);
359 >    public void testDecrementPendingCountUnlessZero() {
360 >        NoopCC a = new NoopCC(null, 2);
361 >        assertEquals(2, a.getPendingCount());
362 >        assertEquals(2, a.decrementPendingCountUnlessZero());
363          assertEquals(1, a.getPendingCount());
364 <        a.decrementPendingCountUnlessZero();
364 >        assertEquals(1, a.decrementPendingCountUnlessZero());
365          assertEquals(0, a.getPendingCount());
366 <        a.decrementPendingCountUnlessZero();
366 >        assertEquals(0, a.decrementPendingCountUnlessZero());
367          assertEquals(0, a.getPendingCount());
368      }
369  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines