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

Comparing jsr166/src/test/tck/AtomicBooleanTest.java (file contents):
Revision 1.4 by dl, Sat Sep 20 18:20:07 2003 UTC vs.
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 18 | Line 18 | public class AtomicBooleanTest extends J
18      }
19  
20      /**
21 <     *
21 >     * constructor initializes to given value
22       */
23      public void testConstructor() {
24          AtomicBoolean ai = new AtomicBoolean(true);
# Line 26 | Line 26 | public class AtomicBooleanTest extends J
26      }
27  
28      /**
29 <     *
29 >     * default constructed intializes to false
30       */
31      public void testConstructor2() {
32          AtomicBoolean ai = new AtomicBoolean();
# Line 34 | Line 34 | public class AtomicBooleanTest extends J
34      }
35  
36      /**
37 <     *
37 >     * get returns the last value set
38       */
39      public void testGetSet() {
40          AtomicBoolean ai = new AtomicBoolean(true);
# Line 45 | Line 45 | public class AtomicBooleanTest extends J
45          assertEquals(true,ai.get());
46          
47      }
48 +
49      /**
50 <     *
50 >     * compareAndSet succeeds in changing value if equal to expected else fails
51       */
52      public void testCompareAndSet() {
53          AtomicBoolean ai = new AtomicBoolean(true);
# Line 61 | Line 62 | public class AtomicBooleanTest extends J
62      }
63  
64      /**
65 <     *
65 >     * compareAndSet in one thread enables another waiting for value
66 >     * to succeed
67 >     */
68 >    public void testCompareAndSetInMultipleThreads() {
69 >        final AtomicBoolean ai = new AtomicBoolean(true);
70 >        Thread t = new Thread(new Runnable() {
71 >                public void run() {
72 >                    while(!ai.compareAndSet(false, true)) Thread.yield();
73 >                }});
74 >        try {
75 >            t.start();
76 >            assertTrue(ai.compareAndSet(true, false));
77 >            t.join(LONG_DELAY_MS);
78 >            assertFalse(t.isAlive());
79 >        }
80 >        catch(Exception e) {
81 >            unexpectedException();
82 >        }
83 >    }
84 >
85 >    /**
86 >     * repeated weakCompareAndSet succeeds in changing value when equal
87 >     * to expected
88       */
89      public void testWeakCompareAndSet() {
90          AtomicBoolean ai = new AtomicBoolean(true);
# Line 74 | Line 97 | public class AtomicBooleanTest extends J
97      }
98  
99      /**
100 <     *
100 >     * getAndSet returns previous value and sets to given value
101       */
102      public void testGetAndSet() {
103          AtomicBoolean ai = new AtomicBoolean(true);
# Line 85 | Line 108 | public class AtomicBooleanTest extends J
108      }
109  
110      /**
111 <     *
111 >     * a deserialized serialized atomic holds same value
112       */
113      public void testSerialization() {
114          AtomicBoolean l = new AtomicBoolean();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines