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.77 by jsr166, Sun May 14 00:56:43 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 316 | Line 318 | public class LinkedTransferQueueTest ext
318                      q.poll(LONG_DELAY_MS, MILLISECONDS);
319                      shouldThrow();
320                  } catch (InterruptedException success) {}
321 +                assertFalse(Thread.interrupted());
322                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
323              }});
324  
# Line 739 | Line 742 | public class LinkedTransferQueueTest ext
742              }});
743  
744          threadStarted.await();
745 <        waitForThreadToEnterWaitState(t);
746 <        assertEquals(1, q.getWaitingConsumerCount());
747 <        assertTrue(q.hasWaitingConsumer());
745 >        Callable<Boolean> oneConsumer
746 >            = new Callable<Boolean>() { public Boolean call() {
747 >                return q.hasWaitingConsumer()
748 >                && q.getWaitingConsumerCount() == 1; }};
749 >        waitForThreadToEnterWaitState(t, oneConsumer);
750  
751          assertTrue(q.offer(one));
752          assertEquals(0, q.getWaitingConsumerCount());
# Line 777 | Line 782 | public class LinkedTransferQueueTest ext
782              }});
783  
784          threadStarted.await();
785 <        waitForThreadToEnterWaitState(t);
786 <        assertEquals(1, q.size());
785 >        Callable<Boolean> oneElement
786 >            = new Callable<Boolean>() { public Boolean call() {
787 >                return !q.isEmpty() && q.size() == 1; }};
788 >        waitForThreadToEnterWaitState(t, oneElement);
789 >
790          assertSame(five, q.poll());
791          checkEmpty(q);
792          awaitTermination(t);
# Line 793 | Line 801 | public class LinkedTransferQueueTest ext
801          Thread first = newStartedThread(new CheckedRunnable() {
802              public void realRun() throws InterruptedException {
803                  q.transfer(four);
804 <                assertTrue(!q.contains(four));
804 >                assertFalse(q.contains(four));
805                  assertEquals(1, q.size());
806              }});
807  
# Line 957 | Line 965 | public class LinkedTransferQueueTest ext
965              }});
966  
967          await(pleaseInterrupt);
968 <        assertThreadStaysAlive(t);
968 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
969          t.interrupt();
970          awaitTermination(t);
971          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines