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

Comparing jsr166/src/test/tck/SynchronousQueueTest.java (file contents):
Revision 1.60 by jsr166, Mon May 29 22:44:27 2017 UTC vs.
Revision 1.65 by jsr166, Tue Aug 13 23:06:39 2019 UTC

# Line 18 | Line 18 | import java.util.concurrent.CountDownLat
18   import java.util.concurrent.Executors;
19   import java.util.concurrent.ExecutorService;
20   import java.util.concurrent.SynchronousQueue;
21 import java.util.concurrent.ThreadLocalRandom;
21  
22   import junit.framework.Test;
23  
# Line 139 | Line 138 | public class SynchronousQueueTest extend
138              }});
139  
140          await(pleaseInterrupt);
141 <        assertThreadBlocks(t, Thread.State.WAITING);
141 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
142          t.interrupt();
143          awaitTermination(t);
144          assertEquals(0, q.remainingCapacity());
# Line 180 | Line 179 | public class SynchronousQueueTest extend
179          catch (InterruptedException e) { threadUnexpectedException(e); }
180  
181          await(pleaseInterrupt);
182 <        assertThreadBlocks(t, Thread.State.WAITING);
182 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
183          t.interrupt();
184          awaitTermination(t);
185          assertEquals(0, q.remainingCapacity());
# Line 190 | Line 189 | public class SynchronousQueueTest extend
189       * timed offer times out if elements not taken
190       */
191      public void testTimedOffer() {
192 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
192 >        final boolean fair = randomBoolean();
193          final SynchronousQueue q = new SynchronousQueue(fair);
194          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
195          Thread t = newStartedThread(new CheckedRunnable() {
196              public void realRun() throws InterruptedException {
197                  long startTime = System.nanoTime();
198 +
199                  assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
200                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
201  
202                  Thread.currentThread().interrupt();
203                  try {
204 <                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
204 >                    q.offer(new Object(), randomTimeout(), randomTimeUnit());
205                      shouldThrow();
206                  } catch (InterruptedException success) {}
207                  assertFalse(Thread.interrupted());
208  
209                  pleaseInterrupt.countDown();
210                  try {
211 <                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
211 >                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
212                      shouldThrow();
213                  } catch (InterruptedException success) {}
214                  assertFalse(Thread.interrupted());
215 +
216 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
217              }});
218  
219          await(pleaseInterrupt);
220 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
220 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
221          t.interrupt();
222          awaitTermination(t);
223      }
# Line 245 | Line 247 | public class SynchronousQueueTest extend
247       * timed poll with nonzero timeout times out if no active putter
248       */
249      public void testTimedPoll() {
250 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
250 >        final boolean fair = randomBoolean();
251          final SynchronousQueue q = new SynchronousQueue(fair);
252          final long startTime = System.nanoTime();
253          try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); }
# Line 258 | Line 260 | public class SynchronousQueueTest extend
260       * after offer succeeds; on interruption throws
261       */
262      public void testTimedPollWithOffer() {
263 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
263 >        final boolean fair = randomBoolean();
264          final SynchronousQueue q = new SynchronousQueue(fair);
265          final CountDownLatch pleaseOffer = new CountDownLatch(1);
266          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
# Line 274 | Line 276 | public class SynchronousQueueTest extend
276  
277                  Thread.currentThread().interrupt();
278                  try {
279 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
279 >                    q.poll(randomTimeout(), randomTimeUnit());
280                      shouldThrow();
281                  } catch (InterruptedException success) {}
282                  assertFalse(Thread.interrupted());
# Line 296 | Line 298 | public class SynchronousQueueTest extend
298          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
299  
300          await(pleaseInterrupt);
301 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
301 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
302          t.interrupt();
303          awaitTermination(t);
304      }
# Line 437 | Line 439 | public class SynchronousQueueTest extend
439      public void testToArray_null(boolean fair) {
440          final SynchronousQueue q = new SynchronousQueue(fair);
441          try {
442 <            Object[] o = q.toArray(null);
442 >            Object[] o = q.toArray((Object[])null);
443              shouldThrow();
444          } catch (NullPointerException success) {}
445      }
# Line 530 | Line 532 | public class SynchronousQueueTest extend
532      }
533  
534      /**
535 <     * a deserialized serialized queue is usable
535 >     * a deserialized/reserialized queue is usable
536       */
537      public void testSerialization() {
538          final SynchronousQueue x = new SynchronousQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines