14 |
|
|
15 |
|
public class SemaphoreTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
|
return new TestSuite(SemaphoreTest.class); |
49 |
|
|
50 |
|
|
51 |
|
/** |
52 |
< |
* A runnable calling acquire that expects to be |
53 |
< |
* interrupted |
52 |
> |
* A runnable calling acquire that expects to be interrupted |
53 |
|
*/ |
54 |
|
class InterruptedLockRunnable extends CheckedInterruptedRunnable { |
55 |
|
final Semaphore lock; |
212 |
|
Thread t = new Thread(new CheckedRunnable() { |
213 |
|
public void realRun() throws InterruptedException { |
214 |
|
s.release(); |
215 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
215 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
216 |
|
s.release(); |
217 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
217 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
218 |
|
}}); |
219 |
|
|
220 |
|
t.start(); |
594 |
|
final Semaphore s = new Semaphore(1, true); |
595 |
|
Thread t = new Thread(new CheckedRunnable() { |
596 |
|
public void realRun() throws InterruptedException { |
597 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
598 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
599 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
600 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
601 |
< |
threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
597 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
598 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
599 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
600 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
601 |
> |
assertTrue(s.tryAcquire(SHORT_DELAY_MS, MILLISECONDS)); |
602 |
|
}}); |
603 |
|
|
604 |
|
t.start(); |
618 |
|
final Semaphore s = new Semaphore(2, true); |
619 |
|
Thread t = new Thread(new CheckedRunnable() { |
620 |
|
public void realRun() throws InterruptedException { |
621 |
< |
threadAssertTrue(s.tryAcquire(2, SHORT_DELAY_MS, MILLISECONDS)); |
621 |
> |
assertTrue(s.tryAcquire(2, SHORT_DELAY_MS, MILLISECONDS)); |
622 |
|
s.release(2); |
623 |
< |
threadAssertTrue(s.tryAcquire(2, SHORT_DELAY_MS, MILLISECONDS)); |
623 |
> |
assertTrue(s.tryAcquire(2, SHORT_DELAY_MS, MILLISECONDS)); |
624 |
|
s.release(2); |
625 |
|
}}); |
626 |
|
|