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.62 by jsr166, Tue Oct 6 00:03:55 2015 UTC vs.
Revision 1.74 by jsr166, Sun May 14 04:02:06 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.
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 59 | Line 67 | public class LinkedBlockingQueueTest ext
67          assertFalse(q.isEmpty());
68          assertEquals(0, q.remainingCapacity());
69          assertEquals(n, q.size());
70 +        assertEquals((Integer) 0, q.peek());
71          return q;
72      }
73  
# Line 283 | 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 305 | Line 314 | public class LinkedBlockingQueueTest ext
314                  pleaseTake.countDown();
315                  q.put(86);
316  
317 +                Thread.currentThread().interrupt();
318 +                try {
319 +                    q.put(99);
320 +                    shouldThrow();
321 +                } catch (InterruptedException success) {}
322 +                assertFalse(Thread.interrupted());
323 +
324                  pleaseInterrupt.countDown();
325                  try {
326                      q.put(99);
# Line 318 | Line 334 | public class LinkedBlockingQueueTest ext
334          assertEquals(0, q.take());
335  
336          await(pleaseInterrupt);
337 <        assertThreadStaysAlive(t);
337 >        assertThreadBlocks(t, Thread.State.WAITING);
338          t.interrupt();
339          awaitTermination(t);
340          assertEquals(0, q.remainingCapacity());
# Line 342 | Line 358 | public class LinkedBlockingQueueTest ext
358                      q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
359                      shouldThrow();
360                  } catch (InterruptedException success) {}
361 +                assertFalse(Thread.interrupted());
362              }});
363  
364          await(pleaseInterrupt);
365 <        assertThreadStaysAlive(t);
365 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
366          t.interrupt();
367          awaitTermination(t);
368      }
# Line 368 | Line 385 | public class LinkedBlockingQueueTest ext
385          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
386          Thread t = newStartedThread(new CheckedRunnable() {
387              public void realRun() throws InterruptedException {
388 <                for (int i = 0; i < SIZE; ++i) {
372 <                    assertEquals(i, q.take());
373 <                }
388 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
389  
390                  Thread.currentThread().interrupt();
391                  try {
# Line 388 | Line 403 | public class LinkedBlockingQueueTest ext
403              }});
404  
405          await(pleaseInterrupt);
406 <        assertThreadStaysAlive(t);
406 >        assertThreadBlocks(t, Thread.State.WAITING);
407          t.interrupt();
408          awaitTermination(t);
409      }
# Line 437 | Line 452 | public class LinkedBlockingQueueTest ext
452       */
453      public void testInterruptedTimedPoll() throws InterruptedException {
454          final BlockingQueue<Integer> q = populatedQueue(SIZE);
455 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
455 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
456          Thread t = newStartedThread(new CheckedRunnable() {
457              public void realRun() throws InterruptedException {
458                  long startTime = System.nanoTime();
459 <                for (int i = 0; i < SIZE; ++i) {
459 >                for (int i = 0; i < SIZE; i++)
460                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
461 <                }
462 <                aboutToWait.countDown();
461 >
462 >                Thread.currentThread().interrupt();
463                  try {
464                      q.poll(LONG_DELAY_MS, MILLISECONDS);
465                      shouldThrow();
466 <                } catch (InterruptedException success) {
467 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
468 <                }
466 >                } catch (InterruptedException success) {}
467 >                assertFalse(Thread.interrupted());
468 >
469 >                pleaseInterrupt.countDown();
470 >                try {
471 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
472 >                    shouldThrow();
473 >                } catch (InterruptedException success) {}
474 >                assertFalse(Thread.interrupted());
475 >
476 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
477              }});
478  
479 <        await(aboutToWait);
480 <        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
479 >        await(pleaseInterrupt);
480 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
481          t.interrupt();
482          awaitTermination(t);
483          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines