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

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.38 by jsr166, Fri Nov 5 00:17:22 2010 UTC vs.
Revision 1.43 by dl, Fri May 6 11:22:07 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 296 | Line 296 | public class PriorityBlockingQueueTest e
296      /**
297       * put(null) throws NPE
298       */
299 <     public void testPutNull() {
299 >    public void testPutNull() {
300          try {
301              PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
302              q.put(null);
303              shouldThrow();
304          } catch (NullPointerException success) {}
305 <     }
305 >    }
306  
307      /**
308       * all elements successfully put are contained
309       */
310 <     public void testPut() {
311 <         PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
312 <         for (int i = 0; i < SIZE; ++i) {
313 <             Integer I = new Integer(i);
314 <             q.put(I);
315 <             assertTrue(q.contains(I));
316 <         }
317 <         assertEquals(SIZE, q.size());
310 >    public void testPut() {
311 >        PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
312 >        for (int i = 0; i < SIZE; ++i) {
313 >            Integer I = new Integer(i);
314 >            q.put(I);
315 >            assertTrue(q.contains(I));
316 >        }
317 >        assertEquals(SIZE, q.size());
318      }
319  
320      /**
# Line 330 | Line 330 | public class PriorityBlockingQueueTest e
330              }});
331  
332          t.start();
333 <        Thread.sleep(SHORT_DELAY_MS);
333 >        delay(SHORT_DELAY_MS);
334          assertEquals(q.size(), size);
335          q.take();
336          t.interrupt();
# Line 351 | Line 351 | public class PriorityBlockingQueueTest e
351              }});
352  
353          t.start();
354 <        Thread.sleep(SMALL_DELAY_MS);
354 >        delay(SMALL_DELAY_MS);
355          t.interrupt();
356          t.join();
357      }
# Line 383 | Line 383 | public class PriorityBlockingQueueTest e
383              }});
384  
385          t.start();
386 <        Thread.sleep(SHORT_DELAY_MS);
386 >        delay(SHORT_DELAY_MS);
387          t.interrupt();
388          t.join();
389      }
# Line 427 | Line 427 | public class PriorityBlockingQueueTest e
427       * returning timeout status
428       */
429      public void testInterruptedTimedPoll() throws InterruptedException {
430 <        Thread t = new Thread(new CheckedRunnable() {
430 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
431 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
432 >        Thread t = newStartedThread(new CheckedRunnable() {
433              public void realRun() throws InterruptedException {
432                PriorityBlockingQueue q = populatedQueue(SIZE);
434                  for (int i = 0; i < SIZE; ++i) {
435 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
435 >                    long t0 = System.nanoTime();
436 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
437 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
438                  }
439 +                long t0 = System.nanoTime();
440 +                aboutToWait.countDown();
441                  try {
442 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
442 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
443                      shouldThrow();
444 <                } catch (InterruptedException success) {}
444 >                } catch (InterruptedException success) {
445 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
446 >                }
447              }});
448  
449 <        t.start();
450 <        Thread.sleep(SHORT_DELAY_MS);
449 >        aboutToWait.await();
450 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
451          t.interrupt();
452 <        t.join();
452 >        awaitTermination(t, MEDIUM_DELAY_MS);
453      }
454  
455      /**
# Line 494 | Line 501 | public class PriorityBlockingQueueTest e
501      public void testRemoveElement() {
502          PriorityBlockingQueue q = populatedQueue(SIZE);
503          for (int i = 1; i < SIZE; i+=2) {
504 <            assertTrue(q.remove(new Integer(i)));
504 >            assertTrue(q.contains(i));
505 >            assertTrue(q.remove(i));
506 >            assertFalse(q.contains(i));
507 >            assertTrue(q.contains(i-1));
508          }
509          for (int i = 0; i < SIZE; i+=2) {
510 <            assertTrue(q.remove(new Integer(i)));
511 <            assertFalse(q.remove(new Integer(i+1)));
510 >            assertTrue(q.contains(i));
511 >            assertTrue(q.remove(i));
512 >            assertFalse(q.contains(i));
513 >            assertFalse(q.remove(i+1));
514 >            assertFalse(q.contains(i+1));
515          }
516          assertTrue(q.isEmpty());
517      }
# Line 685 | Line 698 | public class PriorityBlockingQueueTest e
698  
699          executor.execute(new CheckedRunnable() {
700              public void realRun() throws InterruptedException {
701 <                Thread.sleep(SMALL_DELAY_MS);
701 >                delay(SMALL_DELAY_MS);
702                  q.put(one);
703              }});
704  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines