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.51 by jsr166, Wed Jan 4 06:09:58 2017 UTC vs.
Revision 1.65 by jsr166, Tue Aug 13 23:06:39 2019 UTC

# Line 96 | 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 138 | Line 138 | public class SynchronousQueueTest extend
138              }});
139  
140          await(pleaseInterrupt);
141 <        assertThreadStaysAlive(t);
141 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
142          t.interrupt();
143          awaitTermination(t);
144          assertEquals(0, q.remainingCapacity());
# Line 158 | 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 172 | Line 179 | public class SynchronousQueueTest extend
179          catch (InterruptedException e) { threadUnexpectedException(e); }
180  
181          await(pleaseInterrupt);
182 <        assertThreadStaysAlive(t);
182 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
183          t.interrupt();
184          awaitTermination(t);
185          assertEquals(0, q.remainingCapacity());
# Line 181 | Line 188 | public class SynchronousQueueTest extend
188      /**
189       * timed offer times out if elements not taken
190       */
191 <    public void testTimedOffer()      { testTimedOffer(false); }
192 <    public void testTimedOffer_fair() { testTimedOffer(true); }
186 <    public void testTimedOffer(boolean fair) {
191 >    public void testTimedOffer() {
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(), 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 <        assertThreadStaysAlive(t);
220 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
221          t.interrupt();
222          awaitTermination(t);
223      }
# Line 228 | Line 246 | public class SynchronousQueueTest extend
246      /**
247       * timed poll with nonzero timeout times out if no active putter
248       */
249 <    public void testTimedPoll()      { testTimedPoll(false); }
250 <    public void testTimedPoll_fair() { testTimedPoll(true); }
233 <    public void testTimedPoll(boolean fair) {
249 >    public void testTimedPoll() {
250 >        final boolean fair = randomBoolean();
251          final SynchronousQueue q = new SynchronousQueue(fair);
252 <        long startTime = System.nanoTime();
252 >        final long startTime = System.nanoTime();
253          try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); }
254          catch (InterruptedException e) { threadUnexpectedException(e); }
255          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
# Line 242 | Line 259 | public class SynchronousQueueTest extend
259       * timed poll before a delayed offer times out, returning null;
260       * after offer succeeds; on interruption throws
261       */
262 <    public void testTimedPollWithOffer()      { testTimedPollWithOffer(false); }
263 <    public void testTimedPollWithOffer_fair() { testTimedPollWithOffer(true); }
247 <    public void testTimedPollWithOffer(boolean fair) {
262 >    public void testTimedPollWithOffer() {
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 260 | 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 282 | Line 298 | public class SynchronousQueueTest extend
298          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
299  
300          await(pleaseInterrupt);
301 <        assertThreadStaysAlive(t);
301 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
302          t.interrupt();
303          awaitTermination(t);
304      }
# Line 423 | 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 438 | Line 454 | public class SynchronousQueueTest extend
454      }
455  
456      /**
457 <     * iterator remove throws ISE
457 >     * iterator remove throws IllegalStateException
458       */
459      public void testIteratorRemove()      { testIteratorRemove(false); }
460      public void testIteratorRemove_fair() { testIteratorRemove(true); }
# Line 516 | 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();
# Line 569 | Line 585 | public class SynchronousQueueTest extend
585                  fail("timed out");
586              Thread.yield();
587          }
588 <        assertTrue(l.size() == 1);
588 >        assertEquals(1, l.size());
589          assertSame(one, l.get(0));
590          awaitTermination(t);
591      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines