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.80 by jsr166, Tue Aug 15 20:30:30 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 281 | Line 281 | public class LinkedTransferQueueTest ext
281          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
282          Thread t = newStartedThread(new CheckedRunnable() {
283              public void realRun() throws InterruptedException {
284                long startTime = System.nanoTime();
284                  for (int i = 0; i < SIZE; i++)
285                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
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                  assertFalse(Thread.interrupted());
293  
294                  pleaseInterrupt.countDown();
295                  try {
296 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
296 >                    q.poll(LONGER_DELAY_MS, MILLISECONDS);
297                      shouldThrow();
298                  } catch (InterruptedException success) {}
299                  assertFalse(Thread.interrupted());
301
302                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
300              }});
301  
302          await(pleaseInterrupt);
303 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
303 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
304          t.interrupt();
305          awaitTermination(t);
306          checkEmpty(q);
# Line 320 | 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());
# Line 475 | 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 489 | 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 957 | 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 968 | 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 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
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