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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.38 by jsr166, Thu Nov 18 20:21:53 2010 UTC vs.
Revision 1.42 by dl, Fri May 6 16:43:45 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 277 | Line 277 | public class LinkedBlockingQueueTest ext
277      /**
278       * put(null) throws NPE
279       */
280 <     public void testPutNull() throws InterruptedException {
280 >    public void testPutNull() throws InterruptedException {
281          try {
282              LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
283              q.put(null);
284              shouldThrow();
285          } catch (NullPointerException success) {}
286 <     }
286 >    }
287  
288      /**
289       * all elements successfully put are contained
# Line 316 | Line 316 | public class LinkedBlockingQueueTest ext
316              }});
317  
318          t.start();
319 <        Thread.sleep(SHORT_DELAY_MS);
319 >        delay(SHORT_DELAY_MS);
320          t.interrupt();
321          t.join();
322          assertEquals(SIZE, q.size());
# Line 340 | Line 340 | public class LinkedBlockingQueueTest ext
340              }});
341  
342          t.start();
343 <        Thread.sleep(SHORT_DELAY_MS);
343 >        delay(SHORT_DELAY_MS);
344          assertEquals(q.remainingCapacity(), 0);
345          assertEquals(0, q.take());
346 <        Thread.sleep(SHORT_DELAY_MS);
346 >        delay(SHORT_DELAY_MS);
347          t.interrupt();
348          t.join();
349          assertEquals(q.remainingCapacity(), 0);
# Line 366 | Line 366 | public class LinkedBlockingQueueTest ext
366              }});
367  
368          t.start();
369 <        Thread.sleep(SMALL_DELAY_MS);
369 >        delay(SMALL_DELAY_MS);
370          t.interrupt();
371          t.join();
372      }
# Line 398 | Line 398 | public class LinkedBlockingQueueTest ext
398              }});
399  
400          t.start();
401 <        Thread.sleep(SHORT_DELAY_MS);
401 >        delay(SHORT_DELAY_MS);
402          t.interrupt();
403          t.join();
404      }
# Line 441 | Line 441 | public class LinkedBlockingQueueTest ext
441       * returning timeout status
442       */
443      public void testInterruptedTimedPoll() throws InterruptedException {
444 <        Thread t = new Thread(new CheckedRunnable() {
444 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
445 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
446 >        Thread t = newStartedThread(new CheckedRunnable() {
447              public void realRun() throws InterruptedException {
446                LinkedBlockingQueue q = populatedQueue(SIZE);
448                  for (int i = 0; i < SIZE; ++i) {
449 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
449 >                    long t0 = System.nanoTime();
450 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
451 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
452                  }
453 +                long t0 = System.nanoTime();
454 +                aboutToWait.countDown();
455                  try {
456 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
456 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
457                      shouldThrow();
458 <                } catch (InterruptedException success) {}
458 >                } catch (InterruptedException success) {
459 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
460 >                }
461              }});
462  
463 <        t.start();
464 <        Thread.sleep(SHORT_DELAY_MS);
463 >        aboutToWait.await();
464 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
465          t.interrupt();
466 <        t.join();
466 >        awaitTermination(t, MEDIUM_DELAY_MS);
467 >        checkEmpty(q);
468      }
469  
470      /**
# Line 750 | Line 758 | public class LinkedBlockingQueueTest ext
758  
759          executor.execute(new CheckedRunnable() {
760              public void realRun() throws InterruptedException {
761 <                Thread.sleep(SMALL_DELAY_MS);
761 >                delay(SMALL_DELAY_MS);
762                  assertSame(one, q.take());
763              }});
764  
# Line 772 | Line 780 | public class LinkedBlockingQueueTest ext
780  
781          executor.execute(new CheckedRunnable() {
782              public void realRun() throws InterruptedException {
783 <                Thread.sleep(SMALL_DELAY_MS);
783 >                delay(SMALL_DELAY_MS);
784                  q.put(one);
785              }});
786  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines