10 |
|
import java.util.concurrent.*; |
11 |
|
import java.io.*; |
12 |
|
|
13 |
< |
public class SemaphoreTest extends TestCase{ |
13 |
> |
public class SemaphoreTest extends JSR166TestCase { |
14 |
|
|
15 |
|
public static void main(String[] args) { |
16 |
|
junit.textui.TestRunner.run (suite()); |
20 |
|
return new TestSuite(SemaphoreTest.class); |
21 |
|
} |
22 |
|
|
23 |
– |
private static long SHORT_DELAY_MS = 100; |
24 |
– |
private static long MEDIUM_DELAY_MS = 1000; |
25 |
– |
private static long LONG_DELAY_MS = 10000; |
26 |
– |
|
27 |
– |
|
23 |
|
public void testConstructor1() { |
24 |
|
Semaphore s = new Semaphore(0); |
25 |
|
assertEquals(0, s.availablePermits()); |
87 |
|
s.release(); |
88 |
|
s.acquire(); |
89 |
|
}catch(InterruptedException ie){ |
90 |
< |
fail("unexpected exception"); |
90 |
> |
threadFail("unexpected exception"); |
91 |
|
} |
92 |
|
} |
93 |
|
}); |
128 |
|
public void run(){ |
129 |
|
try{ |
130 |
|
s.release(); |
131 |
< |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
131 |
> |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
132 |
|
s.release(); |
133 |
< |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
133 |
> |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
134 |
|
|
135 |
|
}catch(InterruptedException ie){ |
136 |
< |
fail("unexpected exception"); |
136 |
> |
threadFail("unexpected exception"); |
137 |
|
} |
138 |
|
} |
139 |
|
}); |
155 |
|
public void run(){ |
156 |
|
try{ |
157 |
|
s.acquire(); |
158 |
< |
fail("should throw"); |
158 |
> |
threadFail("should throw"); |
159 |
|
}catch(InterruptedException success){} |
160 |
|
} |
161 |
|
}); |
175 |
|
public void run(){ |
176 |
|
try{ |
177 |
|
s.tryAcquire(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
178 |
< |
fail("should throw"); |
178 |
> |
threadFail("should throw"); |
179 |
|
}catch(InterruptedException success){ |
180 |
|
} |
181 |
|
} |
192 |
|
|
193 |
|
public void testSerialization() { |
194 |
|
Semaphore l = new Semaphore(3); |
200 |
– |
|
195 |
|
try { |
196 |
|
l.acquire(); |
197 |
|
l.release(); |