10 |
|
import java.util.concurrent.*; |
11 |
|
import java.io.*; |
12 |
|
|
13 |
< |
public class ReentrantReadWriteLockTest extends TestCase { |
14 |
< |
static int HOLD_COUNT_TEST_LIMIT = 20; |
15 |
< |
|
13 |
> |
public class ReentrantReadWriteLockTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
15 |
|
junit.textui.TestRunner.run (suite()); |
16 |
|
} |
19 |
– |
|
17 |
|
public static Test suite() { |
18 |
|
return new TestSuite(ReentrantReadWriteLockTest.class); |
19 |
|
} |
20 |
|
|
21 |
< |
|
25 |
< |
private static long SHORT_DELAY_MS = 100; |
26 |
< |
private static long MEDIUM_DELAY_MS = 1000; |
27 |
< |
private static long LONG_DELAY_MS = 10000; |
21 |
> |
static int HOLD_COUNT_TEST_LIMIT = 20; |
22 |
|
|
23 |
|
/* |
24 |
|
* Unlocks an unlocked lock, throws Illegal Monitor State |
25 |
|
* |
26 |
|
*/ |
33 |
– |
|
27 |
|
public void testIllegalMonitorStateException(){ |
28 |
|
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
29 |
|
try{ |
42 |
|
public void run(){ |
43 |
|
try{ |
44 |
|
lock.writeLock().lockInterruptibly(); |
45 |
< |
fail("should throw"); |
45 |
> |
threadFail("should throw"); |
46 |
|
}catch(InterruptedException success){} |
47 |
|
} |
48 |
|
}); |
63 |
|
public void run(){ |
64 |
|
try{ |
65 |
|
lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS); |
66 |
< |
fail("should throw"); |
66 |
> |
threadFail("should throw"); |
67 |
|
}catch(InterruptedException success){} |
68 |
|
} |
69 |
|
}); |
84 |
|
public void run(){ |
85 |
|
try{ |
86 |
|
lock.readLock().lockInterruptibly(); |
87 |
< |
fail("should throw"); |
87 |
> |
threadFail("should throw"); |
88 |
|
}catch(InterruptedException success){} |
89 |
|
} |
90 |
|
}); |
105 |
|
public void run(){ |
106 |
|
try{ |
107 |
|
lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS); |
108 |
< |
fail("should throw"); |
108 |
> |
threadFail("should throw"); |
109 |
|
}catch(InterruptedException success){} |
110 |
|
} |
111 |
|
}); |
124 |
|
lock.writeLock().lock(); |
125 |
|
Thread t = new Thread(new Runnable() { |
126 |
|
public void run(){ |
127 |
< |
assertFalse(lock.writeLock().tryLock()); |
127 |
> |
threadAssertFalse(lock.writeLock().tryLock()); |
128 |
|
} |
129 |
|
}); |
130 |
|
try { |
141 |
|
lock.writeLock().lock(); |
142 |
|
Thread t = new Thread(new Runnable() { |
143 |
|
public void run(){ |
144 |
< |
assertFalse(lock.readLock().tryLock()); |
144 |
> |
threadAssertFalse(lock.readLock().tryLock()); |
145 |
|
} |
146 |
|
}); |
147 |
|
try { |
158 |
|
lock.readLock().lock(); |
159 |
|
Thread t = new Thread(new Runnable() { |
160 |
|
public void run(){ |
161 |
< |
assertTrue(lock.readLock().tryLock()); |
161 |
> |
threadAssertTrue(lock.readLock().tryLock()); |
162 |
|
lock.readLock().unlock(); |
163 |
|
} |
164 |
|
}); |
239 |
|
lock.readLock().lock(); |
240 |
|
Thread t = new Thread(new Runnable() { |
241 |
|
public void run(){ |
242 |
< |
assertTrue(lock.readLock().tryLock()); |
242 |
> |
threadAssertTrue(lock.readLock().tryLock()); |
243 |
|
lock.readLock().unlock(); |
244 |
|
} |
245 |
|
}); |
259 |
|
lock.readLock().lock(); |
260 |
|
Thread t = new Thread(new Runnable() { |
261 |
|
public void run(){ |
262 |
< |
assertFalse(lock.writeLock().tryLock()); |
262 |
> |
threadAssertFalse(lock.writeLock().tryLock()); |
263 |
|
} |
264 |
|
}); |
265 |
|
try { |
279 |
|
Thread t = new Thread(new Runnable() { |
280 |
|
public void run(){ |
281 |
|
try { |
282 |
< |
assertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS)); |
282 |
> |
threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS)); |
283 |
|
} catch (Exception ex) { |
284 |
< |
fail("unexpected exception"); |
284 |
> |
threadFail("unexpected exception"); |
285 |
|
} |
286 |
|
} |
287 |
|
}); |
300 |
|
Thread t = new Thread(new Runnable() { |
301 |
|
public void run(){ |
302 |
|
try { |
303 |
< |
assertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS)); |
303 |
> |
threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS)); |
304 |
|
} catch (Exception ex) { |
305 |
< |
fail("unexpected exception"); |
305 |
> |
threadFail("unexpected exception"); |
306 |
|
} |
307 |
|
} |
308 |
|
}); |
327 |
|
public void run() { |
328 |
|
try { |
329 |
|
lock.writeLock().lockInterruptibly(); |
330 |
< |
fail("should throw"); |
330 |
> |
threadFail("should throw"); |
331 |
|
} |
332 |
|
catch(InterruptedException success) { |
333 |
|
} |
354 |
|
public void run() { |
355 |
|
try { |
356 |
|
lock.readLock().lockInterruptibly(); |
357 |
< |
fail("should throw"); |
357 |
> |
threadFail("should throw"); |
358 |
|
} |
359 |
|
catch(InterruptedException success) { |
360 |
|
} |
450 |
|
lock.writeLock().unlock(); |
451 |
|
} |
452 |
|
catch(InterruptedException e) { |
453 |
< |
fail("unexpected exception"); |
453 |
> |
threadFail("unexpected exception"); |
454 |
|
} |
455 |
|
} |
456 |
|
}); |
504 |
|
lock.writeLock().lock(); |
505 |
|
c.await(); |
506 |
|
lock.writeLock().unlock(); |
507 |
< |
fail("should throw"); |
507 |
> |
threadFail("should throw"); |
508 |
|
} |
509 |
|
catch(InterruptedException success) { |
510 |
|
} |
532 |
|
lock.writeLock().lock(); |
533 |
|
c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000); |
534 |
|
lock.writeLock().unlock(); |
535 |
< |
fail("should throw"); |
535 |
> |
threadFail("should throw"); |
536 |
|
} |
537 |
|
catch(InterruptedException success) { |
538 |
|
} |
561 |
|
java.util.Date d = new java.util.Date(); |
562 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
563 |
|
lock.writeLock().unlock(); |
564 |
< |
fail("should throw"); |
564 |
> |
threadFail("should throw"); |
565 |
|
} |
566 |
|
catch(InterruptedException success) { |
567 |
|
} |
591 |
|
lock.writeLock().unlock(); |
592 |
|
} |
593 |
|
catch(InterruptedException e) { |
594 |
< |
fail("unexpected exception"); |
594 |
> |
threadFail("unexpected exception"); |
595 |
|
} |
596 |
|
} |
597 |
|
}); |
604 |
|
lock.writeLock().unlock(); |
605 |
|
} |
606 |
|
catch(InterruptedException e) { |
607 |
< |
fail("unexpected exception"); |
607 |
> |
threadFail("unexpected exception"); |
608 |
|
} |
609 |
|
} |
610 |
|
}); |