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.57 by jsr166, Sun May 14 03:48:35 2017 UTC vs.
Revision 1.67 by jsr166, Mon Dec 16 22:55:54 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 97 | Line 96 | public class SynchronousQueueTest extend
96      }
97  
98      /**
99 <     * addAll throws ISE if no active taker
99 >     * addAll throws IllegalStateException if no active taker
100       */
101      public void testAddAll_ISE()      { testAddAll_ISE(false); }
102      public void testAddAll_ISE_fair() { testAddAll_ISE(true); }
# 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 159 | Line 158 | public class SynchronousQueueTest extend
158                  pleaseTake.countDown();
159                  q.put(one);
160  
161 +                Thread.currentThread().interrupt();
162 +                try {
163 +                    q.put(99);
164 +                    shouldThrow();
165 +                } catch (InterruptedException success) {}
166 +                assertFalse(Thread.interrupted());
167 +
168                  pleaseInterrupt.countDown();
169                  try {
170                      q.put(99);
# Line 173 | 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 183 | 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(), 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(), LONGER_DELAY_MS, MILLISECONDS);
212                      shouldThrow();
213                  } catch (InterruptedException success) {}
214                  assertFalse(Thread.interrupted());
215              }});
216  
217          await(pleaseInterrupt);
218 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
218 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
219          t.interrupt();
220          awaitTermination(t);
221      }
# Line 230 | Line 245 | public class SynchronousQueueTest extend
245       * timed poll with nonzero timeout times out if no active putter
246       */
247      public void testTimedPoll() {
248 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
248 >        final boolean fair = randomBoolean();
249          final SynchronousQueue q = new SynchronousQueue(fair);
250          final long startTime = System.nanoTime();
251          try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); }
# Line 243 | Line 258 | public class SynchronousQueueTest extend
258       * after offer succeeds; on interruption throws
259       */
260      public void testTimedPollWithOffer() {
261 <        final boolean fair = ThreadLocalRandom.current().nextBoolean();
261 >        final boolean fair = randomBoolean();
262          final SynchronousQueue q = new SynchronousQueue(fair);
263          final CountDownLatch pleaseOffer = new CountDownLatch(1);
264          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
# Line 259 | Line 274 | public class SynchronousQueueTest extend
274  
275                  Thread.currentThread().interrupt();
276                  try {
277 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
277 >                    q.poll(randomTimeout(), randomTimeUnit());
278                      shouldThrow();
279                  } catch (InterruptedException success) {}
280                  assertFalse(Thread.interrupted());
# Line 281 | Line 296 | public class SynchronousQueueTest extend
296          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
297  
298          await(pleaseInterrupt);
299 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
299 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
300          t.interrupt();
301          awaitTermination(t);
302      }
# Line 422 | Line 437 | public class SynchronousQueueTest extend
437      public void testToArray_null(boolean fair) {
438          final SynchronousQueue q = new SynchronousQueue(fair);
439          try {
440 <            Object[] o = q.toArray(null);
440 >            Object[] unused = q.toArray((Object[])null);
441              shouldThrow();
442          } catch (NullPointerException success) {}
443      }
# Line 437 | Line 452 | public class SynchronousQueueTest extend
452      }
453  
454      /**
455 <     * iterator remove throws ISE
455 >     * iterator remove throws IllegalStateException
456       */
457      public void testIteratorRemove()      { testIteratorRemove(false); }
458      public void testIteratorRemove_fair() { testIteratorRemove(true); }
# Line 515 | Line 530 | public class SynchronousQueueTest extend
530      }
531  
532      /**
533 <     * a deserialized serialized queue is usable
533 >     * a deserialized/reserialized queue is usable
534       */
535      public void testSerialization() {
536          final SynchronousQueue x = new SynchronousQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines