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

Comparing jsr166/src/test/tck/FutureTaskTest.java (file contents):
Revision 1.22 by jsr166, Sun Nov 28 20:20:00 2010 UTC vs.
Revision 1.23 by jsr166, Fri Jan 7 07:46:26 2011 UTC

# Line 251 | Line 251 | public class FutureTaskTest extends JSR1
251      }
252  
253      /**
254 <     * set in one thread causes get in another thread to retrieve value
254 >     * run in one thread causes get in another thread to retrieve value
255       */
256 <    public void testGet1() throws InterruptedException {
256 >    public void testGetRun() throws InterruptedException {
257 >        final CountDownLatch threadStarted = new CountDownLatch(1);
258 >
259          final FutureTask task =
260              new FutureTask(new CheckedCallable<Object>() {
261                  public Object realCall() throws InterruptedException {
262                      return Boolean.TRUE;
263                  }});
262        checkNotDone(task);
264  
265          Thread t = newStartedThread(new CheckedRunnable() {
266              public void realRun() throws Exception {
267 +                threadStarted.countDown();
268                  assertSame(Boolean.TRUE, task.get());
269              }});
270  
271 +        threadStarted.await();
272 +        checkNotDone(task);
273 +        assertTrue(t.isAlive());
274          task.run();
275          checkCompletedNormally(task, Boolean.TRUE);
276          awaitTermination(t, MEDIUM_DELAY_MS);
277      }
278  
279      /**
280 <     * set in one thread causes timed get in another thread to retrieve value
280 >     * set in one thread causes get in another thread to retrieve value
281 >     */
282 >    public void testGetSet() throws InterruptedException {
283 >        final CountDownLatch threadStarted = new CountDownLatch(1);
284 >
285 >        final PublicFutureTask task =
286 >            new PublicFutureTask(new CheckedCallable<Object>() {
287 >                public Object realCall() throws InterruptedException {
288 >                    return Boolean.TRUE;
289 >                }});
290 >
291 >        Thread t = newStartedThread(new CheckedRunnable() {
292 >            public void realRun() throws Exception {
293 >                threadStarted.countDown();
294 >                assertSame(Boolean.FALSE, task.get());
295 >            }});
296 >
297 >        threadStarted.await();
298 >        checkNotDone(task);
299 >        assertTrue(t.isAlive());
300 >        task.set(Boolean.FALSE);
301 >        checkCompletedNormally(task, Boolean.FALSE);
302 >        awaitTermination(t, MEDIUM_DELAY_MS);
303 >    }
304 >
305 >    /**
306 >     * run in one thread causes timed get in another thread to retrieve value
307       */
308 <    public void testTimedGet1() throws InterruptedException {
308 >    public void testTimedGetRun() throws InterruptedException {
309 >        final CountDownLatch threadStarted = new CountDownLatch(1);
310 >
311          final FutureTask task =
312              new FutureTask(new CheckedCallable<Object>() {
313                  public Object realCall() throws InterruptedException {
314                      return Boolean.TRUE;
315                  }});
283        checkNotDone(task);
316  
317          Thread t = newStartedThread(new CheckedRunnable() {
318              public void realRun() throws Exception {
319 <                assertSame(Boolean.TRUE, task.get(SMALL_DELAY_MS, MILLISECONDS));
319 >                threadStarted.countDown();
320 >                assertSame(Boolean.TRUE,
321 >                           task.get(MEDIUM_DELAY_MS, MILLISECONDS));
322              }});
323  
324 +        threadStarted.await();
325 +        checkNotDone(task);
326 +        assertTrue(t.isAlive());
327          task.run();
328          checkCompletedNormally(task, Boolean.TRUE);
329          awaitTermination(t, MEDIUM_DELAY_MS);
330      }
331  
332 +    /**
333 +     * set in one thread causes timed get in another thread to retrieve value
334 +     */
335 +    public void testTimedGetSet() throws InterruptedException {
336 +        final CountDownLatch threadStarted = new CountDownLatch(1);
337 +
338 +        final PublicFutureTask task =
339 +            new PublicFutureTask(new CheckedCallable<Object>() {
340 +                public Object realCall() throws InterruptedException {
341 +                    return Boolean.TRUE;
342 +                }});
343 +
344 +        Thread t = newStartedThread(new CheckedRunnable() {
345 +            public void realRun() throws Exception {
346 +                threadStarted.countDown();
347 +                assertSame(Boolean.FALSE,
348 +                           task.get(MEDIUM_DELAY_MS, MILLISECONDS));
349 +            }});
350 +
351 +        threadStarted.await();
352 +        checkNotDone(task);
353 +        assertTrue(t.isAlive());
354 +        task.set(Boolean.FALSE);
355 +        checkCompletedNormally(task, Boolean.FALSE);
356 +        awaitTermination(t, MEDIUM_DELAY_MS);
357 +    }
358 +
359      /**
360       * Cancelling a task causes timed get in another thread to throw
361       * CancellationException

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines