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.47 by jsr166, Wed Dec 31 19:05:42 2014 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());
# 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 1213 | Line 1220 | public class AbstractQueuedSynchronizerT
1220          assertFalse(l.isSignalled());
1221      }
1222  
1223 +    /**
1224 +     * awaitNanos/timed await with 0 wait times out immediately
1225 +     */
1226 +    public void testAwait_Zero() throws InterruptedException {
1227 +        final Mutex sync = new Mutex();
1228 +        final ConditionObject c = sync.newCondition();
1229 +        sync.acquire();
1230 +        assertTrue(c.awaitNanos(0L) <= 0);
1231 +        assertFalse(c.await(0L, NANOSECONDS));
1232 +        sync.release();
1233 +    }
1234 +
1235 +    /**
1236 +     * awaitNanos/timed await with maximum negative wait times does not underflow
1237 +     */
1238 +    public void testAwait_NegativeInfinity() throws InterruptedException {
1239 +        final Mutex sync = new Mutex();
1240 +        final ConditionObject c = sync.newCondition();
1241 +        sync.acquire();
1242 +        assertTrue(c.awaitNanos(Long.MIN_VALUE) <= 0);
1243 +        assertFalse(c.await(Long.MIN_VALUE, NANOSECONDS));
1244 +        sync.release();
1245 +    }
1246 +
1247   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines