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.82 by jsr166, Sun Aug 11 22:29:27 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)
285 >                for (int i = 0; i < SIZE; i++)
286                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
287 <                aboutToWait.countDown();
287 >
288 >                Thread.currentThread().interrupt();
289 >                try {
290 >                    q.poll(randomTimeout(), randomTimeUnit());
291 >                    shouldThrow();
292 >                } catch (InterruptedException success) {}
293 >                assertFalse(Thread.interrupted());
294 >
295 >                pleaseInterrupt.countDown();
296                  try {
297                      q.poll(LONG_DELAY_MS, MILLISECONDS);
298                      shouldThrow();
299                  } catch (InterruptedException success) {}
300 +                assertFalse(Thread.interrupted());
301 +
302                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
303              }});
304  
305 <        await(aboutToWait);
306 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
305 >        await(pleaseInterrupt);
306 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
307          t.interrupt();
308          awaitTermination(t);
309          checkEmpty(q);
# Line 310 | Line 320 | public class LinkedTransferQueueTest ext
320                  long startTime = System.nanoTime();
321                  Thread.currentThread().interrupt();
322                  for (int i = 0; i < SIZE; ++i)
323 <                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
323 >                    assertEquals(i, (int) q.poll(randomTimeout(), randomTimeUnit()));
324                  try {
325 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
325 >                    q.poll(randomTimeout(), randomTimeUnit());
326                      shouldThrow();
327                  } catch (InterruptedException success) {}
328 +                assertFalse(Thread.interrupted());
329                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
330              }});
331  
# Line 464 | Line 475 | public class LinkedTransferQueueTest ext
475       */
476      public void testToArray() {
477          LinkedTransferQueue q = populatedQueue(SIZE);
478 <        Object[] o = q.toArray();
479 <        for (int i = 0; i < o.length; i++) {
480 <            assertSame(o[i], q.poll());
481 <        }
478 >        Object[] a = q.toArray();
479 >        assertSame(Object[].class, a.getClass());
480 >        for (Object o : a)
481 >            assertSame(o, q.poll());
482 >        assertTrue(q.isEmpty());
483      }
484  
485      /**
# Line 478 | Line 490 | public class LinkedTransferQueueTest ext
490          Integer[] ints = new Integer[SIZE];
491          Integer[] array = q.toArray(ints);
492          assertSame(ints, array);
493 <        for (int i = 0; i < ints.length; i++) {
494 <            assertSame(ints[i], q.poll());
495 <        }
493 >        for (Integer o : ints)
494 >            assertSame(o, q.poll());
495 >        assertTrue(q.isEmpty());
496      }
497  
498      /**
# Line 636 | Line 648 | public class LinkedTransferQueueTest ext
648      }
649  
650      /**
651 <     * A deserialized serialized queue has same elements in same order
651 >     * A deserialized/reserialized queue has same elements in same order
652       */
653      public void testSerialization() throws Exception {
654          Queue x = populatedQueue(SIZE);
# Line 763 | Line 775 | public class LinkedTransferQueueTest ext
775      }
776  
777      /**
778 <     * transfer waits until a poll occurs. The transfered element
778 >     * transfer waits until a poll occurs. The transferred element
779       * is returned by the associated poll.
780       */
781      public void testTransfer2() throws InterruptedException {
# Line 844 | Line 856 | public class LinkedTransferQueueTest ext
856      }
857  
858      /**
859 <     * transfer waits until a take occurs. The transfered element
859 >     * transfer waits until a take occurs. The transferred element
860       * is returned by the associated take.
861       */
862      public void testTransfer5() throws InterruptedException {
# Line 946 | Line 958 | public class LinkedTransferQueueTest ext
958                  long startTime = System.nanoTime();
959                  Thread.currentThread().interrupt();
960                  try {
961 <                    q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
961 >                    q.tryTransfer(new Object(), randomTimeout(), randomTimeUnit());
962                      shouldThrow();
963                  } catch (InterruptedException success) {}
964                  assertFalse(Thread.interrupted());
# Line 957 | Line 969 | public class LinkedTransferQueueTest ext
969                      shouldThrow();
970                  } catch (InterruptedException success) {}
971                  assertFalse(Thread.interrupted());
972 +
973                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
974              }});
975  
976          await(pleaseInterrupt);
977 <        assertThreadStaysAlive(t);
977 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
978          t.interrupt();
979          awaitTermination(t);
980          checkEmpty(q);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines