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.56 by jsr166, Sun May 14 00:56:43 2017 UTC vs.
Revision 1.58 by jsr166, Sun May 14 04:02:06 2017 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;
22  
23   import junit.framework.Test;
24  
# Line 158 | Line 159 | public class SynchronousQueueTest extend
159                  pleaseTake.countDown();
160                  q.put(one);
161  
162 +                Thread.currentThread().interrupt();
163 +                try {
164 +                    q.put(99);
165 +                    shouldThrow();
166 +                } catch (InterruptedException success) {}
167 +                assertFalse(Thread.interrupted());
168 +
169                  pleaseInterrupt.countDown();
170                  try {
171                      q.put(99);
# Line 181 | Line 189 | public class SynchronousQueueTest extend
189      /**
190       * timed offer times out if elements not taken
191       */
192 <    public void testTimedOffer()      { testTimedOffer(false); }
193 <    public void testTimedOffer_fair() { testTimedOffer(true); }
186 <    public void testTimedOffer(boolean fair) {
192 >    public void testTimedOffer() {
193 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
194          final SynchronousQueue q = new SynchronousQueue(fair);
195          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
196          Thread t = newStartedThread(new CheckedRunnable() {
# Line 229 | Line 236 | public class SynchronousQueueTest extend
236      /**
237       * timed poll with nonzero timeout times out if no active putter
238       */
239 <    public void testTimedPoll()      { testTimedPoll(false); }
240 <    public void testTimedPoll_fair() { testTimedPoll(true); }
234 <    public void testTimedPoll(boolean fair) {
239 >    public void testTimedPoll() {
240 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
241          final SynchronousQueue q = new SynchronousQueue(fair);
242 <        long startTime = System.nanoTime();
242 >        final long startTime = System.nanoTime();
243          try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); }
244          catch (InterruptedException e) { threadUnexpectedException(e); }
245          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
# Line 243 | Line 249 | public class SynchronousQueueTest extend
249       * timed poll before a delayed offer times out, returning null;
250       * after offer succeeds; on interruption throws
251       */
252 <    public void testTimedPollWithOffer()      { testTimedPollWithOffer(false); }
253 <    public void testTimedPollWithOffer_fair() { testTimedPollWithOffer(true); }
248 <    public void testTimedPollWithOffer(boolean fair) {
252 >    public void testTimedPollWithOffer() {
253 >        final boolean fair = ThreadLocalRandom.current().nextBoolean();
254          final SynchronousQueue q = new SynchronousQueue(fair);
255          final CountDownLatch pleaseOffer = new CountDownLatch(1);
256          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines