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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines