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

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.44 by jsr166, Thu May 2 18:01:09 2013 UTC vs.
Revision 1.50 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
10 import java.util.*;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 + import static java.util.concurrent.TimeUnit.NANOSECONDS;
11 +
12 + import java.util.Arrays;
13 + import java.util.Collection;
14 + import java.util.HashSet;
15   import java.util.concurrent.locks.AbstractQueuedSynchronizer;
16   import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject;
17  
18 + import junit.framework.AssertionFailedError;
19 + import junit.framework.Test;
20 + import junit.framework.TestSuite;
21 +
22   public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
25      }
26      public static Test suite() {
27          return new TestSuite(AbstractQueuedSynchronizerTest.class);
# Line 198 | Line 205 | public class AbstractQueuedSynchronizerT
205                       new HashSet<Thread>(Arrays.asList(threads)));
206      }
207  
208 <    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
208 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
209  
210      /**
211       * Awaits condition using the specified AwaitMethod.
# Line 221 | Line 228 | public class AbstractQueuedSynchronizerT
228          case awaitUntil:
229              assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
230              break;
231 +        default:
232 +            throw new AssertionError();
233          }
234      }
235  
# Line 1191 | Line 1200 | public class AbstractQueuedSynchronizerT
1200      public void testTryAcquireSharedNanos_Timeout() {
1201          final BooleanLatch l = new BooleanLatch();
1202          final BooleanLatch observedQueued = new BooleanLatch();
1194        final long timeoutMillis = timeoutMillis();
1203          Thread t = newStartedThread(new CheckedRunnable() {
1204              public void realRun() throws InterruptedException {
1205                  assertFalse(l.isSignalled());
# Line 1213 | Line 1221 | public class AbstractQueuedSynchronizerT
1221          assertFalse(l.isSignalled());
1222      }
1223  
1224 +    /**
1225 +     * awaitNanos/timed await with 0 wait times out immediately
1226 +     */
1227 +    public void testAwait_Zero() throws InterruptedException {
1228 +        final Mutex sync = new Mutex();
1229 +        final ConditionObject c = sync.newCondition();
1230 +        sync.acquire();
1231 +        assertTrue(c.awaitNanos(0L) <= 0);
1232 +        assertFalse(c.await(0L, NANOSECONDS));
1233 +        sync.release();
1234 +    }
1235 +
1236 +    /**
1237 +     * awaitNanos/timed await with maximum negative wait times does not underflow
1238 +     */
1239 +    public void testAwait_NegativeInfinity() throws InterruptedException {
1240 +        final Mutex sync = new Mutex();
1241 +        final ConditionObject c = sync.newCondition();
1242 +        sync.acquire();
1243 +        assertTrue(c.awaitNanos(Long.MIN_VALUE) <= 0);
1244 +        assertFalse(c.await(Long.MIN_VALUE, NANOSECONDS));
1245 +        sync.release();
1246 +    }
1247 +
1248   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines