< prev index next >

test/jdk/java/util/concurrent/locks/StampedLock/Basic.java

Print this page
rev 51731 : imported patch 8210732


  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 8005697
  37  * @summary Basic tests for StampedLock
  38  * @library /lib/testlibrary/
  39  * @author Chris Hegarty
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.SECONDS;
  43 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  44 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  45 
  46 import java.util.Iterator;
  47 import java.util.concurrent.Phaser;
  48 import java.util.concurrent.TimeUnit;
  49 import java.util.concurrent.atomic.AtomicInteger;
  50 import java.util.concurrent.locks.Lock;
  51 import java.util.concurrent.locks.ReadWriteLock;
  52 import java.util.concurrent.locks.StampedLock;
  53 import jdk.testlibrary.Utils;
  54 
  55 public class Basic {
  56     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  57 
  58     static void checkResult(Locker l, Class<? extends Throwable> c) {
  59         Throwable t = l.thrown();
  60         if (! ((t == null && c == null) || (c != null && c.isInstance(t)))) {
  61             fail("Mismatch in thread " +
  62                  l.getName() + ": " +
  63                  t + ", " +
  64                  (c == null ? "<null>" : c.getName()));
  65         }
  66 
  67         if (c == null)
  68             check(l.stamp() != 0L);  // must have acquired the lock
  69         else
  70             check(l.stamp() == 0L);  // must NOT have acquired the lock
  71     }
  72 
  73     //----------------------------------------------------------------




  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 8005697
  37  * @summary Basic tests for StampedLock
  38  * @library /test/lib
  39  * @author Chris Hegarty
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.SECONDS;
  43 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  44 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  45 
  46 import java.util.Iterator;
  47 import java.util.concurrent.Phaser;
  48 import java.util.concurrent.TimeUnit;
  49 import java.util.concurrent.atomic.AtomicInteger;
  50 import java.util.concurrent.locks.Lock;
  51 import java.util.concurrent.locks.ReadWriteLock;
  52 import java.util.concurrent.locks.StampedLock;
  53 import jdk.test.lib.Utils;
  54 
  55 public class Basic {
  56     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  57 
  58     static void checkResult(Locker l, Class<? extends Throwable> c) {
  59         Throwable t = l.thrown();
  60         if (! ((t == null && c == null) || (c != null && c.isInstance(t)))) {
  61             fail("Mismatch in thread " +
  62                  l.getName() + ": " +
  63                  t + ", " +
  64                  (c == null ? "<null>" : c.getName()));
  65         }
  66 
  67         if (c == null)
  68             check(l.stamp() != 0L);  // must have acquired the lock
  69         else
  70             check(l.stamp() == 0L);  // must NOT have acquired the lock
  71     }
  72 
  73     //----------------------------------------------------------------


< prev index next >