57 |
|
return super.getQueuedThreads(); |
58 |
|
} |
59 |
|
public ConditionObject newCondition() { |
60 |
< |
return new PublicCondition(this); |
60 |
> |
return new PublicCondition(); |
61 |
|
} |
62 |
|
|
63 |
< |
static class PublicCondition extends ReentrantLock.ConditionObject { |
64 |
< |
PublicCondition(PublicReentrantLock l) { super(l); } |
63 |
> |
class PublicCondition extends ReentrantLock.ConditionObject { |
64 |
> |
PublicCondition() { } |
65 |
|
public Collection<Thread> getWaitingThreads() { |
66 |
|
return super.getWaitingThreads(); |
67 |
|
} |
69 |
|
|
70 |
|
} |
71 |
|
|
72 |
< |
/* |
72 |
> |
/** |
73 |
> |
* Constructor sets given fairness |
74 |
> |
*/ |
75 |
> |
public void testConstructor() { |
76 |
> |
ReentrantLock rl = new ReentrantLock(); |
77 |
> |
assertFalse(rl.isFair()); |
78 |
> |
ReentrantLock r2 = new ReentrantLock(true); |
79 |
> |
assertTrue(r2.isFair()); |
80 |
> |
} |
81 |
> |
|
82 |
> |
/** |
83 |
|
* locking an unlocked lock succeeds |
84 |
|
*/ |
85 |
|
public void testLock() { |
89 |
|
rl.unlock(); |
90 |
|
} |
91 |
|
|
92 |
< |
/* |
92 |
> |
/** |
93 |
|
* locking an unlocked fair lock succeeds |
94 |
|
*/ |
95 |
|
public void testFairLock() { |
99 |
|
rl.unlock(); |
100 |
|
} |
101 |
|
|
102 |
< |
/* |
102 |
> |
/** |
103 |
|
* Unlocking an unlocked lock throws IllegalMonitorStateException |
104 |
|
*/ |
105 |
|
public void testUnlock_IllegalMonitorStateException() { |
111 |
|
} catch(IllegalMonitorStateException success){} |
112 |
|
} |
113 |
|
|
114 |
< |
/* |
114 |
> |
/** |
115 |
|
* trylock on an unlocked lock succeeds |
116 |
|
*/ |
117 |
|
public void testTryLock() { |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
/* |
126 |
< |
* getLockQueueLength reports number of waiting threads |
125 |
> |
/** |
126 |
> |
* getQueueLength reports number of waiting threads |
127 |
|
*/ |
128 |
< |
public void testGetLockQueueLength() { |
128 |
> |
public void testGetQueueLength() { |
129 |
|
final ReentrantLock lock = new ReentrantLock(); |
130 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
131 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
132 |
|
try { |
133 |
< |
assertEquals(0, lock.getLockQueueLength()); |
133 |
> |
assertEquals(0, lock.getQueueLength()); |
134 |
|
lock.lock(); |
135 |
|
t1.start(); |
136 |
|
Thread.sleep(SHORT_DELAY_MS); |
137 |
< |
assertEquals(1, lock.getLockQueueLength()); |
137 |
> |
assertEquals(1, lock.getQueueLength()); |
138 |
|
t2.start(); |
139 |
|
Thread.sleep(SHORT_DELAY_MS); |
140 |
< |
assertEquals(2, lock.getLockQueueLength()); |
140 |
> |
assertEquals(2, lock.getQueueLength()); |
141 |
|
t1.interrupt(); |
142 |
|
Thread.sleep(SHORT_DELAY_MS); |
143 |
< |
assertEquals(1, lock.getLockQueueLength()); |
143 |
> |
assertEquals(1, lock.getQueueLength()); |
144 |
|
lock.unlock(); |
145 |
|
Thread.sleep(SHORT_DELAY_MS); |
146 |
< |
assertEquals(0, lock.getLockQueueLength()); |
146 |
> |
assertEquals(0, lock.getQueueLength()); |
147 |
|
t1.join(); |
148 |
|
t2.join(); |
149 |
|
} catch(Exception e){ |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
< |
/* |
154 |
> |
/** |
155 |
|
* getQueuedThreads includes waiting threads |
156 |
|
*/ |
157 |
|
public void testGetQueuedThreads() { |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
/* |
187 |
> |
/** |
188 |
|
* timed trylock is interruptible. |
189 |
|
*/ |
190 |
|
public void testInterruptedException2() { |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
< |
/* |
303 |
> |
/** |
304 |
|
* lockInterruptibly is interruptible. |
305 |
|
*/ |
306 |
|
public void testLockInterruptibly1() { |