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.64 by jsr166, Sun Oct 16 20:44:18 2016 UTC vs.
Revision 1.72 by jsr166, Sun May 14 00:56:43 2017 UTC

# Line 41 | Line 41 | public class LinkedBlockingQueueTest ext
41      }
42  
43      public static Test suite() {
44 +        class Implementation implements CollectionImplementation {
45 +            public Class<?> klazz() { return LinkedBlockingQueue.class; }
46 +            public Collection emptyCollection() { return new LinkedBlockingQueue(); }
47 +            public Object makeElement(int i) { return i; }
48 +            public boolean isConcurrent() { return true; }
49 +            public boolean permitsNulls() { return false; }
50 +        }
51          return newTestSuite(LinkedBlockingQueueTest.class,
52                              new Unbounded().testSuite(),
53 <                            new Bounded().testSuite());
53 >                            new Bounded().testSuite(),
54 >                            CollectionTest.testSuite(new Implementation()));
55      }
56  
57      /**
58       * Returns a new queue of given size containing consecutive
59       * Integers 0 ... n - 1.
60       */
61 <    private LinkedBlockingQueue<Integer> populatedQueue(int n) {
61 >    private static LinkedBlockingQueue<Integer> populatedQueue(int n) {
62          LinkedBlockingQueue<Integer> q =
63              new LinkedBlockingQueue<Integer>(n);
64          assertTrue(q.isEmpty());
# Line 284 | Line 292 | public class LinkedBlockingQueueTest ext
292              }});
293  
294          await(pleaseInterrupt);
295 <        assertThreadStaysAlive(t);
295 >        assertThreadBlocks(t, Thread.State.WAITING);
296          t.interrupt();
297          awaitTermination(t);
298          assertEquals(SIZE, q.size());
# Line 319 | Line 327 | public class LinkedBlockingQueueTest ext
327          assertEquals(0, q.take());
328  
329          await(pleaseInterrupt);
330 <        assertThreadStaysAlive(t);
330 >        assertThreadBlocks(t, Thread.State.WAITING);
331          t.interrupt();
332          awaitTermination(t);
333          assertEquals(0, q.remainingCapacity());
# Line 343 | Line 351 | public class LinkedBlockingQueueTest ext
351                      q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
352                      shouldThrow();
353                  } catch (InterruptedException success) {}
354 +                assertFalse(Thread.interrupted());
355              }});
356  
357          await(pleaseInterrupt);
358 <        assertThreadStaysAlive(t);
358 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
359          t.interrupt();
360          awaitTermination(t);
361      }
# Line 369 | Line 378 | public class LinkedBlockingQueueTest ext
378          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
379          Thread t = newStartedThread(new CheckedRunnable() {
380              public void realRun() throws InterruptedException {
381 <                for (int i = 0; i < SIZE; ++i) {
373 <                    assertEquals(i, q.take());
374 <                }
381 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
382  
383                  Thread.currentThread().interrupt();
384                  try {
# Line 389 | Line 396 | public class LinkedBlockingQueueTest ext
396              }});
397  
398          await(pleaseInterrupt);
399 <        assertThreadStaysAlive(t);
399 >        assertThreadBlocks(t, Thread.State.WAITING);
400          t.interrupt();
401          awaitTermination(t);
402      }
# Line 438 | Line 445 | public class LinkedBlockingQueueTest ext
445       */
446      public void testInterruptedTimedPoll() throws InterruptedException {
447          final BlockingQueue<Integer> q = populatedQueue(SIZE);
448 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
448 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
449          Thread t = newStartedThread(new CheckedRunnable() {
450              public void realRun() throws InterruptedException {
451                  long startTime = System.nanoTime();
452                  for (int i = 0; i < SIZE; ++i) {
453                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
454                  }
455 <                aboutToWait.countDown();
455 >
456 >                pleaseInterrupt.countDown();
457                  try {
458                      q.poll(LONG_DELAY_MS, MILLISECONDS);
459                      shouldThrow();
460 <                } catch (InterruptedException success) {
461 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
462 <                }
460 >                } catch (InterruptedException success) {}
461 >                assertFalse(Thread.interrupted());
462 >
463 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
464              }});
465  
466 <        await(aboutToWait);
467 <        waitForThreadToEnterWaitState(t);
466 >        await(pleaseInterrupt);
467 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
468          t.interrupt();
469          awaitTermination(t);
470          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines