7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.concurrent.locks.*; |
11 |
< |
import java.util.concurrent.*; |
10 |
> |
import java.util.concurrent.locks.Condition; |
11 |
> |
import java.util.concurrent.locks.ReentrantLock; |
12 |
> |
import java.util.concurrent.CountDownLatch; |
13 |
> |
import java.util.concurrent.CyclicBarrier; |
14 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 |
|
import java.util.*; |
14 |
– |
import java.io.*; |
16 |
|
|
17 |
|
public class ReentrantLockTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
287 |
|
} |
288 |
|
|
289 |
|
/** |
290 |
< |
* hasQueuedThread reports whether a thread is queued. |
290 |
> |
* hasQueuedThread reports whether a thread is queued |
291 |
|
*/ |
292 |
|
public void testHasQueuedThread() { testHasQueuedThread(false); } |
293 |
|
public void testHasQueuedThread_fair() { testHasQueuedThread(true); } |
348 |
|
} |
349 |
|
|
350 |
|
/** |
351 |
< |
* timed tryLock is interruptible. |
351 |
> |
* timed tryLock is interruptible |
352 |
|
*/ |
353 |
|
public void testTryLock_Interruptible() { testTryLock_Interruptible(false); } |
354 |
|
public void testTryLock_Interruptible_fair() { testTryLock_Interruptible(true); } |
986 |
|
} |
987 |
|
|
988 |
|
/** |
989 |
< |
* signal wakes up waiting threads in FIFO order. |
989 |
> |
* signal wakes up waiting threads in FIFO order |
990 |
|
*/ |
991 |
|
public void testSignalWakesFifo() { testSignalWakesFifo(false); } |
992 |
|
public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); } |
1111 |
|
public void testToString_fair() { testToString(true); } |
1112 |
|
public void testToString(boolean fair) { |
1113 |
|
ReentrantLock lock = new ReentrantLock(fair); |
1114 |
< |
String us = lock.toString(); |
1114 |
< |
assertTrue(us.indexOf("Unlocked") >= 0); |
1114 |
> |
assertTrue(lock.toString().contains("Unlocked")); |
1115 |
|
lock.lock(); |
1116 |
< |
String ls = lock.toString(); |
1117 |
< |
assertTrue(ls.indexOf("Locked") >= 0); |
1116 |
> |
assertTrue(lock.toString().contains("Locked")); |
1117 |
> |
lock.unlock(); |
1118 |
> |
assertTrue(lock.toString().contains("Unlocked")); |
1119 |
|
} |
1120 |
|
} |