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

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

# Line 17 | Line 17 | public class AtomicStampedReferenceTest
17      }
18      
19      /**
20 <     *
20 >     * constructeor initializes to given reference and stamp
21       */
22      public void testConstructor(){
23          AtomicStampedReference ai = new AtomicStampedReference(one, 0);
# Line 30 | Line 30 | public class AtomicStampedReferenceTest
30      }
31  
32      /**
33 <     *
33 >     *  get returns the last values of reference and stamp set
34       */
35      public void testGetSet(){
36          int[] mark = new int[1];
# Line 52 | Line 52 | public class AtomicStampedReferenceTest
52      }
53  
54      /**
55 <     *
55 >     *  attemptStamp succeeds in single thread
56       */
57      public void testAttemptStamp(){
58          int[] mark = new int[1];
# Line 65 | Line 65 | public class AtomicStampedReferenceTest
65      }
66  
67      /**
68 <     *
68 >     * compareAndSet succeeds in changing values if equal to expected reference
69 >     * and stamp else fails
70       */
71      public void testCompareAndSet(){
72          int[] mark = new int[1];
# Line 88 | Line 89 | public class AtomicStampedReferenceTest
89      }
90  
91      /**
92 <     *
92 >     * compareAndSet in one thread enables another waiting for reference value
93 >     * to succeed
94 >     */
95 >    public void testCompareAndSetInMultipleThreads() {
96 >        final AtomicStampedReference ai = new AtomicStampedReference(one, 0);
97 >        Thread t = new Thread(new Runnable() {
98 >                public void run() {
99 >                    while(!ai.compareAndSet(two, three, 0, 0)) Thread.yield();
100 >                }});
101 >        try {
102 >            t.start();
103 >            assertTrue(ai.compareAndSet(one, two, 0, 0));
104 >            t.join(LONG_DELAY_MS);
105 >            assertFalse(t.isAlive());
106 >            assertEquals(ai.getReference(), three);
107 >            assertEquals(ai.getStamp(), 0);
108 >        }
109 >        catch(Exception e) {
110 >            unexpectedException();
111 >        }
112 >    }
113 >
114 >    /**
115 >     * compareAndSet in one thread enables another waiting for stamp value
116 >     * to succeed
117 >     */
118 >    public void testCompareAndSetInMultipleThreads2() {
119 >        final AtomicStampedReference ai = new AtomicStampedReference(one, 0);
120 >        Thread t = new Thread(new Runnable() {
121 >                public void run() {
122 >                    while(!ai.compareAndSet(one, one, 1, 2)) Thread.yield();
123 >                }});
124 >        try {
125 >            t.start();
126 >            assertTrue(ai.compareAndSet(one, one, 0, 1));
127 >            t.join(LONG_DELAY_MS);
128 >            assertFalse(t.isAlive());
129 >            assertEquals(ai.getReference(), one);
130 >            assertEquals(ai.getStamp(), 2);
131 >        }
132 >        catch(Exception e) {
133 >            unexpectedException();
134 >        }
135 >    }
136 >
137 >    /**
138 >     * repeated weakCompareAndSet succeeds in changing values when equal
139 >     * to expected
140       */
141      public void testWeakCompareAndSet(){
142          int[] mark = new int[1];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines