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

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.69 by jsr166, Sat Feb 18 01:17:06 2017 UTC vs.
Revision 1.76 by jsr166, Sun May 14 00:48:20 2017 UTC

# Line 15 | Line 15 | import java.util.List;
15   import java.util.NoSuchElementException;
16   import java.util.Queue;
17   import java.util.concurrent.BlockingQueue;
18 + import java.util.concurrent.Callable;
19   import java.util.concurrent.CountDownLatch;
20   import java.util.concurrent.Executors;
21   import java.util.concurrent.ExecutorService;
# Line 208 | Line 209 | public class LinkedTransferQueueTest ext
209          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
210          Thread t = newStartedThread(new CheckedRunnable() {
211              public void realRun() throws InterruptedException {
212 <                for (int i = 0; i < SIZE; ++i) {
212 <                    assertEquals(i, q.take());
213 <                }
212 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
213  
214                  Thread.currentThread().interrupt();
215                  try {
# Line 228 | Line 227 | public class LinkedTransferQueueTest ext
227              }});
228  
229          await(pleaseInterrupt);
230 <        assertThreadStaysAlive(t);
230 >        assertThreadBlocks(t, Thread.State.WAITING);
231          t.interrupt();
232          awaitTermination(t);
233      }
# Line 279 | Line 278 | public class LinkedTransferQueueTest ext
278       */
279      public void testInterruptedTimedPoll() throws InterruptedException {
280          final BlockingQueue<Integer> q = populatedQueue(SIZE);
281 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
281 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
282          Thread t = newStartedThread(new CheckedRunnable() {
283              public void realRun() throws InterruptedException {
284                  long startTime = System.nanoTime();
285                  for (int i = 0; i < SIZE; ++i)
286                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
287 <                aboutToWait.countDown();
287 >
288 >                pleaseInterrupt.countDown();
289                  try {
290                      q.poll(LONG_DELAY_MS, MILLISECONDS);
291                      shouldThrow();
292                  } catch (InterruptedException success) {}
293 +                assertFalse(Thread.interrupted());
294 +
295                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
296              }});
297  
298 <        aboutToWait.await();
299 <        waitForThreadToEnterWaitState(t);
298 >        await(pleaseInterrupt);
299 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
300          t.interrupt();
301          awaitTermination(t);
302          checkEmpty(q);
# Line 739 | Line 741 | public class LinkedTransferQueueTest ext
741              }});
742  
743          threadStarted.await();
744 <        waitForThreadToEnterWaitState(t);
745 <        assertEquals(1, q.getWaitingConsumerCount());
746 <        assertTrue(q.hasWaitingConsumer());
744 >        Callable<Boolean> oneConsumer
745 >            = new Callable<Boolean>() { public Boolean call() {
746 >                return q.hasWaitingConsumer()
747 >                && q.getWaitingConsumerCount() == 1; }};
748 >        waitForThreadToEnterWaitState(t, oneConsumer);
749  
750          assertTrue(q.offer(one));
751          assertEquals(0, q.getWaitingConsumerCount());
# Line 777 | Line 781 | public class LinkedTransferQueueTest ext
781              }});
782  
783          threadStarted.await();
784 <        waitForThreadToEnterWaitState(t);
785 <        assertEquals(1, q.size());
784 >        Callable<Boolean> oneElement
785 >            = new Callable<Boolean>() { public Boolean call() {
786 >                return !q.isEmpty() && q.size() == 1; }};
787 >        waitForThreadToEnterWaitState(t, oneElement);
788 >
789          assertSame(five, q.poll());
790          checkEmpty(q);
791          awaitTermination(t);
# Line 793 | Line 800 | public class LinkedTransferQueueTest ext
800          Thread first = newStartedThread(new CheckedRunnable() {
801              public void realRun() throws InterruptedException {
802                  q.transfer(four);
803 <                assertTrue(!q.contains(four));
803 >                assertFalse(q.contains(four));
804                  assertEquals(1, q.size());
805              }});
806  
# Line 957 | Line 964 | public class LinkedTransferQueueTest ext
964              }});
965  
966          await(pleaseInterrupt);
967 <        assertThreadStaysAlive(t);
967 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
968          t.interrupt();
969          awaitTermination(t);
970          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines