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.74 by jsr166, Sat May 13 22:49:01 2017 UTC vs.
Revision 1.83 by jsr166, Thu Sep 5 21:11:13 2019 UTC

# Line 227 | Line 227 | public class LinkedTransferQueueTest ext
227              }});
228  
229          await(pleaseInterrupt);
230 <        assertThreadBlocks(t, Thread.State.WAITING);
230 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
231          t.interrupt();
232          awaitTermination(t);
233      }
# Line 278 | 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)
284 >                for (int i = 0; i < SIZE; i++)
285                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
286 <                aboutToWait.countDown();
286 >
287 >                Thread.currentThread().interrupt();
288                  try {
289 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
289 >                    q.poll(randomTimeout(), randomTimeUnit());
290                      shouldThrow();
291                  } catch (InterruptedException success) {}
292 <                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
292 >                assertFalse(Thread.interrupted());
293 >
294 >                pleaseInterrupt.countDown();
295 >                try {
296 >                    q.poll(LONGER_DELAY_MS, MILLISECONDS);
297 >                    shouldThrow();
298 >                } catch (InterruptedException success) {}
299 >                assertFalse(Thread.interrupted());
300              }});
301  
302 <        await(aboutToWait);
303 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
302 >        await(pleaseInterrupt);
303 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
304          t.interrupt();
305          awaitTermination(t);
306          checkEmpty(q);
# Line 310 | Line 317 | public class LinkedTransferQueueTest ext
317                  long startTime = System.nanoTime();
318                  Thread.currentThread().interrupt();
319                  for (int i = 0; i < SIZE; ++i)
320 <                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
320 >                    assertEquals(i, (int) q.poll(randomTimeout(), randomTimeUnit()));
321                  try {
322 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
322 >                    q.poll(randomTimeout(), randomTimeUnit());
323                      shouldThrow();
324                  } catch (InterruptedException success) {}
325 +                assertFalse(Thread.interrupted());
326                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
327              }});
328  
# Line 464 | Line 472 | public class LinkedTransferQueueTest ext
472       */
473      public void testToArray() {
474          LinkedTransferQueue q = populatedQueue(SIZE);
475 <        Object[] o = q.toArray();
476 <        for (int i = 0; i < o.length; i++) {
477 <            assertSame(o[i], q.poll());
478 <        }
475 >        Object[] a = q.toArray();
476 >        assertSame(Object[].class, a.getClass());
477 >        for (Object o : a)
478 >            assertSame(o, q.poll());
479 >        assertTrue(q.isEmpty());
480      }
481  
482      /**
# Line 478 | Line 487 | public class LinkedTransferQueueTest ext
487          Integer[] ints = new Integer[SIZE];
488          Integer[] array = q.toArray(ints);
489          assertSame(ints, array);
490 <        for (int i = 0; i < ints.length; i++) {
491 <            assertSame(ints[i], q.poll());
492 <        }
490 >        for (Integer o : ints)
491 >            assertSame(o, q.poll());
492 >        assertTrue(q.isEmpty());
493      }
494  
495      /**
# Line 636 | Line 645 | public class LinkedTransferQueueTest ext
645      }
646  
647      /**
648 <     * A deserialized serialized queue has same elements in same order
648 >     * A deserialized/reserialized queue has same elements in same order
649       */
650      public void testSerialization() throws Exception {
651          Queue x = populatedQueue(SIZE);
# Line 763 | Line 772 | public class LinkedTransferQueueTest ext
772      }
773  
774      /**
775 <     * transfer waits until a poll occurs. The transfered element
775 >     * transfer waits until a poll occurs. The transferred element
776       * is returned by the associated poll.
777       */
778      public void testTransfer2() throws InterruptedException {
# Line 844 | Line 853 | public class LinkedTransferQueueTest ext
853      }
854  
855      /**
856 <     * transfer waits until a take occurs. The transfered element
856 >     * transfer waits until a take occurs. The transferred element
857       * is returned by the associated take.
858       */
859      public void testTransfer5() throws InterruptedException {
# Line 946 | Line 955 | public class LinkedTransferQueueTest ext
955                  long startTime = System.nanoTime();
956                  Thread.currentThread().interrupt();
957                  try {
958 <                    q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
958 >                    q.tryTransfer(new Object(), randomTimeout(), randomTimeUnit());
959                      shouldThrow();
960                  } catch (InterruptedException success) {}
961                  assertFalse(Thread.interrupted());
# Line 957 | Line 966 | public class LinkedTransferQueueTest ext
966                      shouldThrow();
967                  } catch (InterruptedException success) {}
968                  assertFalse(Thread.interrupted());
969 +
970                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
971              }});
972  
973          await(pleaseInterrupt);
974 <        assertThreadStaysAlive(t);
974 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
975          t.interrupt();
976          awaitTermination(t);
977          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines