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

Comparing jsr166/src/test/tck/AtomicMarkableReferenceTest.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 16 | Line 16 | public class AtomicMarkableReferenceTest
16          return new TestSuite(AtomicMarkableReferenceTest.class);
17      }
18      
19    static final Integer zero = new Integer(0);
20    static final Integer one = new Integer(1);
21    static final Integer two = new Integer(2);
22    static final Integer m3  = new Integer(-3);
23
19      /**
20 <     *
20 >     *  constructeor initializes to given reference and mark
21       */
22      public void testConstructor(){
23          AtomicMarkableReference ai = new AtomicMarkableReference(one, false);
# Line 35 | Line 30 | public class AtomicMarkableReferenceTest
30      }
31  
32      /**
33 <     *
33 >     *  get returns the last values of reference and mark set
34       */
35      public void testGetSet(){
36          boolean[] mark = new boolean[1];
# Line 57 | Line 52 | public class AtomicMarkableReferenceTest
52      }
53  
54      /**
55 <     *
55 >     * attemptMark succeeds in single thread
56       */
57      public void testAttemptMark(){
58          boolean[] mark = new boolean[1];
# Line 70 | Line 65 | public class AtomicMarkableReferenceTest
65      }
66  
67      /**
68 <     *
68 >     * compareAndSet succeeds in changing values if equal to expected reference
69 >     * and mark else fails
70       */
71      public void testCompareAndSet(){
72          boolean[] mark = new boolean[1];
# Line 93 | Line 89 | public class AtomicMarkableReferenceTest
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 AtomicMarkableReference ai = new AtomicMarkableReference(one, false);
97 >        Thread t = new Thread(new Runnable() {
98 >                public void run() {
99 >                    while(!ai.compareAndSet(two, three, false, false)) Thread.yield();
100 >                }});
101 >        try {
102 >            t.start();
103 >            assertTrue(ai.compareAndSet(one, two, false, false));
104 >            t.join(LONG_DELAY_MS);
105 >            assertFalse(t.isAlive());
106 >            assertEquals(ai.getReference(), three);
107 >            assertFalse(ai.isMarked());
108 >        }
109 >        catch(Exception e) {
110 >            unexpectedException();
111 >        }
112 >    }
113 >
114 >    /**
115 >     * compareAndSet in one thread enables another waiting for mark value
116 >     * to succeed
117 >     */
118 >    public void testCompareAndSetInMultipleThreads2() {
119 >        final AtomicMarkableReference ai = new AtomicMarkableReference(one, false);
120 >        Thread t = new Thread(new Runnable() {
121 >                public void run() {
122 >                    while(!ai.compareAndSet(one, one, true, false)) Thread.yield();
123 >                }});
124 >        try {
125 >            t.start();
126 >            assertTrue(ai.compareAndSet(one, one, false, true));
127 >            t.join(LONG_DELAY_MS);
128 >            assertFalse(t.isAlive());
129 >            assertEquals(ai.getReference(), one);
130 >            assertFalse(ai.isMarked());
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          boolean[] mark = new boolean[1];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines