ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.31 by jsr166, Sat Nov 21 17:54:04 2009 UTC vs.
Revision 1.38 by jsr166, Tue Oct 19 00:43:49 2010 UTC

# Line 16 | Line 16 | import java.io.*;
16  
17   public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
18      public static void main(String[] args) {
19 <        junit.textui.TestRunner.run (suite());
19 >        junit.textui.TestRunner.run(suite());
20      }
21      public static Test suite() {
22          return new TestSuite(AbstractQueuedSynchronizerTest.class);
# Line 34 | Line 34 | public class AbstractQueuedSynchronizerT
34          public boolean isHeldExclusively() { return getState() == 1; }
35  
36          public boolean tryAcquire(int acquires) {
37 <            assertTrue(acquires == 1);
37 >            assertEquals(1, acquires);
38              return compareAndSetState(0, 1);
39          }
40  
# Line 44 | Line 44 | public class AbstractQueuedSynchronizerT
44              return true;
45          }
46  
47 <        public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); }
47 >        public AbstractQueuedSynchronizer.ConditionObject newCondition() {
48 >            return new AbstractQueuedSynchronizer.ConditionObject();
49 >        }
50  
51      }
52  
# Line 56 | Line 58 | public class AbstractQueuedSynchronizerT
58          public boolean isSignalled() { return getState() != 0; }
59  
60          public int tryAcquireShared(int ignore) {
61 <            return isSignalled()? 1 : -1;
61 >            return isSignalled() ? 1 : -1;
62          }
63  
64          public boolean tryReleaseShared(int ignore) {
# Line 327 | Line 329 | public class AbstractQueuedSynchronizerT
329          sync.acquire(1);
330          Thread t = new Thread(new CheckedInterruptedRunnable() {
331              public void realRun() throws InterruptedException {
332 <                sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
332 >                sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS));
333              }});
334  
335          t.start();
336 +        Thread.sleep(SHORT_DELAY_MS);
337          t.interrupt();
338          t.join();
339      }
# Line 344 | Line 347 | public class AbstractQueuedSynchronizerT
347          sync.acquire(1);
348          Thread t = new Thread(new CheckedRunnable() {
349              public void realRun() {
350 <                threadAssertFalse(sync.tryAcquire(1));
350 >                assertFalse(sync.tryAcquire(1));
351              }});
352  
353          t.start();
# Line 360 | Line 363 | public class AbstractQueuedSynchronizerT
363          sync.acquire(1);
364          Thread t = new Thread(new CheckedRunnable() {
365              public void realRun() throws InterruptedException {
366 <                threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
366 >                long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS);
367 >                assertFalse(sync.tryAcquireNanos(1, nanos));
368              }});
369  
370          t.start();
# Line 417 | Line 421 | public class AbstractQueuedSynchronizerT
421          sync.acquireInterruptibly(1);
422          Thread t = new Thread(new InterruptedSyncRunnable(sync));
423          t.start();
424 +        Thread.sleep(SHORT_DELAY_MS);
425          t.interrupt();
426          assertTrue(sync.isHeldExclusively());
427          t.join();
# Line 470 | Line 475 | public class AbstractQueuedSynchronizerT
475      }
476  
477      /**
478 <     *  Timed await without a signal times out
478 >     * Timed await without a signal times out
479       */
480      public void testAwait_Timeout() throws InterruptedException {
481          final Mutex sync = new Mutex();
# Line 639 | Line 644 | public class AbstractQueuedSynchronizerT
644          Thread t = new Thread(new CheckedRunnable() {
645              public void realRun() throws InterruptedException {
646                  sync.acquire(1);
647 <                threadAssertFalse(sync.hasWaiters(c));
648 <                threadAssertEquals(0, sync.getWaitQueueLength(c));
647 >                assertFalse(sync.hasWaiters(c));
648 >                assertEquals(0, sync.getWaitQueueLength(c));
649                  c.await();
650                  sync.release(1);
651              }});
# Line 670 | Line 675 | public class AbstractQueuedSynchronizerT
675          Thread t1 = new Thread(new CheckedRunnable() {
676              public void realRun() throws InterruptedException {
677                  sync.acquire(1);
678 <                threadAssertFalse(sync.hasWaiters(c));
679 <                threadAssertEquals(0, sync.getWaitQueueLength(c));
678 >                assertFalse(sync.hasWaiters(c));
679 >                assertEquals(0, sync.getWaitQueueLength(c));
680                  c.await();
681                  sync.release(1);
682              }});
# Line 679 | Line 684 | public class AbstractQueuedSynchronizerT
684          Thread t2 = new Thread(new CheckedRunnable() {
685              public void realRun() throws InterruptedException {
686                  sync.acquire(1);
687 <                threadAssertTrue(sync.hasWaiters(c));
688 <                threadAssertEquals(1, sync.getWaitQueueLength(c));
687 >                assertTrue(sync.hasWaiters(c));
688 >                assertEquals(1, sync.getWaitQueueLength(c));
689                  c.await();
690                  sync.release(1);
691              }});
# Line 714 | Line 719 | public class AbstractQueuedSynchronizerT
719          Thread t1 = new Thread(new CheckedRunnable() {
720              public void realRun() throws InterruptedException {
721                  sync.acquire(1);
722 <                threadAssertTrue(sync.getWaitingThreads(c).isEmpty());
722 >                assertTrue(sync.getWaitingThreads(c).isEmpty());
723                  c.await();
724                  sync.release(1);
725              }});
# Line 722 | Line 727 | public class AbstractQueuedSynchronizerT
727          Thread t2 = new Thread(new CheckedRunnable() {
728              public void realRun() throws InterruptedException {
729                  sync.acquire(1);
730 <                threadAssertFalse(sync.getWaitingThreads(c).isEmpty());
730 >                assertFalse(sync.getWaitingThreads(c).isEmpty());
731                  c.await();
732                  sync.release(1);
733              }});
# Line 804 | Line 809 | public class AbstractQueuedSynchronizerT
809          Thread t = new Thread(new CheckedInterruptedRunnable() {
810              public void realRun() throws InterruptedException {
811                  sync.acquire(1);
812 <                c.awaitNanos(1000 * 1000 * 1000); // 1 sec
812 >                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
813              }});
814  
815          t.start();
# Line 929 | Line 934 | public class AbstractQueuedSynchronizerT
934  
935          Thread t = new Thread(new CheckedRunnable() {
936              public void realRun() throws InterruptedException {
937 <                threadAssertFalse(l.isSignalled());
937 >                assertFalse(l.isSignalled());
938                  l.acquireSharedInterruptibly(0);
939 <                threadAssertTrue(l.isSignalled());
939 >                assertTrue(l.isSignalled());
940              }});
941  
942          t.start();
# Line 946 | Line 951 | public class AbstractQueuedSynchronizerT
951      /**
952       * acquireSharedTimed returns after release
953       */
954 <    public void testAsquireSharedTimed() throws InterruptedException {
954 >    public void testAcquireSharedTimed() throws InterruptedException {
955          final BooleanLatch l = new BooleanLatch();
956  
957          Thread t = new Thread(new CheckedRunnable() {
958              public void realRun() throws InterruptedException {
959 <                threadAssertFalse(l.isSignalled());
960 <                threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
961 <                threadAssertTrue(l.isSignalled());
959 >                assertFalse(l.isSignalled());
960 >                long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS);
961 >                assertTrue(l.tryAcquireSharedNanos(0, nanos));
962 >                assertTrue(l.isSignalled());
963              }});
964  
965          t.start();
# Line 971 | Line 977 | public class AbstractQueuedSynchronizerT
977          final BooleanLatch l = new BooleanLatch();
978          Thread t = new Thread(new CheckedInterruptedRunnable() {
979              public void realRun() throws InterruptedException {
980 <                threadAssertFalse(l.isSignalled());
980 >                assertFalse(l.isSignalled());
981                  l.acquireSharedInterruptibly(0);
982              }});
983  
# Line 988 | Line 994 | public class AbstractQueuedSynchronizerT
994          final BooleanLatch l = new BooleanLatch();
995          Thread t = new Thread(new CheckedInterruptedRunnable() {
996              public void realRun() throws InterruptedException {
997 <                threadAssertFalse(l.isSignalled());
998 <                l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
997 >                assertFalse(l.isSignalled());
998 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
999 >                l.tryAcquireSharedNanos(0, nanos);
1000              }});
1001  
1002          t.start();
# Line 1006 | Line 1013 | public class AbstractQueuedSynchronizerT
1013          final BooleanLatch l = new BooleanLatch();
1014          Thread t = new Thread(new CheckedRunnable() {
1015              public void realRun() throws InterruptedException {
1016 <                threadAssertFalse(l.isSignalled());
1017 <                threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1016 >                assertFalse(l.isSignalled());
1017 >                long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS);
1018 >                assertFalse(l.tryAcquireSharedNanos(0, nanos));
1019              }});
1020  
1021          t.start();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines