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.24 by jsr166, Sun Oct 18 19:20:05 2015 UTC vs.
Revision 1.35 by dl, Thu Oct 26 22:50:07 2017 UTC

# Line 5 | Line 5
5   */
6  
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 import static java.util.concurrent.TimeUnit.SECONDS;
8  
9   import java.util.HashSet;
10   import java.util.concurrent.CancellationException;
# Line 77 | Line 76 | public class CountedCompleterTest extend
76          assertNull(a.getRawResult());
77  
78          try {
79 <            a.get(0L, SECONDS);
79 >            a.get(randomExpiredTimeout(), randomTimeUnit());
80              shouldThrow();
81          } catch (TimeoutException success) {
82          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 95 | Line 94 | public class CountedCompleterTest extend
94              Thread.currentThread().interrupt();
95              long startTime = System.nanoTime();
96              assertNull(a.join());
97 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
97 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
98              Thread.interrupted();
99          }
100  
# Line 103 | Line 102 | public class CountedCompleterTest extend
102              Thread.currentThread().interrupt();
103              long startTime = System.nanoTime();
104              a.quietlyJoin();        // should be no-op
105 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
105 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
106              Thread.interrupted();
107          }
108  
# Line 111 | Line 110 | public class CountedCompleterTest extend
110          assertFalse(a.cancel(true));
111          try {
112              assertNull(a.get());
113 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
114 <        try {
116 <            assertNull(a.get(5L, SECONDS));
117 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
113 >            assertNull(a.get(randomTimeout(), randomTimeUnit()));
114 >        } catch (Exception fail) { threadUnexpectedException(fail); }
115      }
116  
117      void checkCancelled(CountedCompleter a) {
# Line 138 | Line 135 | public class CountedCompleterTest extend
135          {
136              long startTime = System.nanoTime();
137              a.quietlyJoin();        // should be no-op
138 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
138 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
139          }
140  
141          try {
# Line 148 | Line 145 | public class CountedCompleterTest extend
145          } catch (Throwable fail) { threadUnexpectedException(fail); }
146  
147          try {
148 <            a.get(5L, SECONDS);
148 >            a.get(randomTimeout(), randomTimeUnit());
149              shouldThrow();
150          } catch (CancellationException success) {
151          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 176 | Line 173 | public class CountedCompleterTest extend
173          {
174              long startTime = System.nanoTime();
175              a.quietlyJoin();        // should be no-op
176 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
176 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
177          }
178  
179          try {
# Line 187 | Line 184 | public class CountedCompleterTest extend
184          } catch (Throwable fail) { threadUnexpectedException(fail); }
185  
186          try {
187 <            a.get(5L, SECONDS);
187 >            a.get(randomTimeout(), randomTimeUnit());
188              shouldThrow();
189          } catch (ExecutionException success) {
190              assertSame(t.getClass(), success.getCause().getClass());
# Line 210 | Line 207 | public class CountedCompleterTest extend
207          final AtomicInteger onCompletionN = new AtomicInteger(0);
208          final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
209          final AtomicInteger setRawResultN = new AtomicInteger(0);
210 <        final AtomicReference<Object> rawResult = new AtomicReference<Object>(null);
210 >        final AtomicReference<Object> rawResult = new AtomicReference<>(null);
211          int computeN() { return computeN.get(); }
212          int onCompletionN() { return onCompletionN.get(); }
213          int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }
# Line 335 | Line 332 | public class CountedCompleterTest extend
332      public void testSetPendingCount() {
333          NoopCC a = new NoopCC();
334          assertEquals(0, a.getPendingCount());
335 <        for (int val : new int[] { -1, 0, 1, Integer.MIN_VALUE, Integer.MAX_VALUE }) {
335 >        int[] vals = {
336 >             -1, 0, 1,
337 >             Integer.MIN_VALUE,
338 >             Integer.MAX_VALUE,
339 >        };
340 >        for (int val : vals) {
341              a.setPendingCount(val);
342              assertEquals(val, a.getPendingCount());
343          }
# Line 351 | Line 353 | public class CountedCompleterTest extend
353          assertEquals(1, a.getPendingCount());
354          a.addToPendingCount(27);
355          assertEquals(28, a.getPendingCount());
356 +        a.addToPendingCount(-28);
357 +        assertEquals(0, a.getPendingCount());
358      }
359  
360      /**
# Line 492 | Line 496 | public class CountedCompleterTest extend
496      }
497  
498      /**
499 <     * quietlyCompleteRoot completes root task
499 >     * quietlyCompleteRoot completes root task and only root task
500       */
501      public void testQuietlyCompleteRoot() {
502          NoopCC a = new NoopCC();
# Line 695 | Line 699 | public class CountedCompleterTest extend
699                  CCF f = new LCCF(8);
700                  assertSame(f, f.fork());
701                  try {
702 <                    f.get(5L, null);
702 >                    f.get(randomTimeout(), null);
703                      shouldThrow();
704                  } catch (NullPointerException success) {}
705              }};
# Line 727 | Line 731 | public class CountedCompleterTest extend
731                  CCF f = new LCCF(8);
732                  assertSame(f, f.fork());
733                  helpQuiesce();
734 +                while (!f.isDone()) // wait out race
735 +                    ;
736                  assertEquals(21, f.number);
737                  assertEquals(0, getQueuedTaskCount());
738                  checkCompletedNormally(f);
# Line 1417 | Line 1423 | public class CountedCompleterTest extend
1423                  CCF f = new LCCF(8);
1424                  assertSame(f, f.fork());
1425                  try {
1426 <                    f.get(5L, null);
1426 >                    f.get(randomTimeout(), null);
1427                      shouldThrow();
1428                  } catch (NullPointerException success) {}
1429              }};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines