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

Comparing jsr166/src/test/tck/AtomicReferenceFieldUpdaterTest.java (file contents):
Revision 1.14 by jsr166, Tue Nov 17 03:12:51 2009 UTC vs.
Revision 1.24 by jsr166, Fri Jun 10 20:01:21 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import java.util.concurrent.atomic.*;
9   import junit.framework.*;
10 < import java.util.*;
10 > import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
11  
12   public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase {
13      volatile Integer x = null;
# Line 31 | Line 30 | public class AtomicReferenceFieldUpdater
30                  a = AtomicReferenceFieldUpdater.newUpdater
31                  (AtomicReferenceFieldUpdaterTest.class, Integer.class, "y");
32              shouldThrow();
33 <        }
35 <        catch (RuntimeException rt) {}
33 >        } catch (RuntimeException success) {}
34      }
35  
38
36      /**
37       * construction with field not of given type throws RuntimeException
38       */
# Line 45 | Line 42 | public class AtomicReferenceFieldUpdater
42                  a = AtomicReferenceFieldUpdater.newUpdater
43                  (AtomicReferenceFieldUpdaterTest.class, Integer.class, "z");
44              shouldThrow();
45 <        }
49 <        catch (RuntimeException rt) {}
45 >        } catch (RuntimeException success) {}
46      }
47  
48      /**
# Line 58 | Line 54 | public class AtomicReferenceFieldUpdater
54                  a = AtomicReferenceFieldUpdater.newUpdater
55                  (AtomicReferenceFieldUpdaterTest.class, Integer.class, "w");
56              shouldThrow();
57 <        }
62 <        catch (RuntimeException rt) {}
57 >        } catch (RuntimeException success) {}
58      }
59  
60      /**
61 <     *  get returns the last value set or assigned
61 >     * get returns the last value set or assigned
62       */
63      public void testGetSet() {
64          AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
# Line 73 | Line 68 | public class AtomicReferenceFieldUpdater
68              return;
69          }
70          x = one;
71 <        assertEquals(one,a.get(this));
72 <        a.set(this,two);
73 <        assertEquals(two,a.get(this));
74 <        a.set(this,m3);
75 <        assertEquals(m3,a.get(this));
71 >        assertSame(one, a.get(this));
72 >        a.set(this, two);
73 >        assertSame(two, a.get(this));
74 >        a.set(this, m3);
75 >        assertSame(m3, a.get(this));
76      }
77  
78      /**
79 <     *  get returns the last value lazySet by same thread
79 >     * get returns the last value lazySet by same thread
80       */
81      public void testGetLazySet() {
82          AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
# Line 91 | Line 86 | public class AtomicReferenceFieldUpdater
86              return;
87          }
88          x = one;
89 <        assertEquals(one,a.get(this));
90 <        a.lazySet(this,two);
91 <        assertEquals(two,a.get(this));
92 <        a.lazySet(this,m3);
93 <        assertEquals(m3,a.get(this));
89 >        assertSame(one, a.get(this));
90 >        a.lazySet(this, two);
91 >        assertSame(two, a.get(this));
92 >        a.lazySet(this, m3);
93 >        assertSame(m3, a.get(this));
94      }
95  
96      /**
# Line 109 | Line 104 | public class AtomicReferenceFieldUpdater
104              return;
105          }
106          x = one;
107 <        assertTrue(a.compareAndSet(this,one,two));
108 <        assertTrue(a.compareAndSet(this,two,m4));
109 <        assertEquals(m4,a.get(this));
110 <        assertFalse(a.compareAndSet(this,m5,seven));
111 <        assertFalse((seven == a.get(this)));
112 <        assertTrue(a.compareAndSet(this,m4,seven));
113 <        assertEquals(seven,a.get(this));
107 >        assertTrue(a.compareAndSet(this, one, two));
108 >        assertTrue(a.compareAndSet(this, two, m4));
109 >        assertSame(m4, a.get(this));
110 >        assertFalse(a.compareAndSet(this, m5, seven));
111 >        assertFalse(seven == a.get(this));
112 >        assertTrue(a.compareAndSet(this, m4, seven));
113 >        assertSame(seven, a.get(this));
114      }
115  
116      /**
# Line 131 | Line 126 | public class AtomicReferenceFieldUpdater
126              return;
127          }
128  
129 <        Thread t = new Thread(new Runnable() {
130 <                public void run() {
131 <                    while (!a.compareAndSet(AtomicReferenceFieldUpdaterTest.this, two, three)) Thread.yield();
132 <                }});
129 >        Thread t = new Thread(new CheckedRunnable() {
130 >            public void realRun() {
131 >                while (!a.compareAndSet(AtomicReferenceFieldUpdaterTest.this, two, three))
132 >                    Thread.yield();
133 >            }});
134  
135          t.start();
136          assertTrue(a.compareAndSet(this, one, two));
137          t.join(LONG_DELAY_MS);
138          assertFalse(t.isAlive());
139 <        assertEquals(a.get(this), three);
139 >        assertSame(a.get(this), three);
140      }
141  
142      /**
# Line 155 | Line 151 | public class AtomicReferenceFieldUpdater
151              return;
152          }
153          x = one;
154 <        while (!a.weakCompareAndSet(this,one,two));
155 <        while (!a.weakCompareAndSet(this,two,m4));
156 <        assertEquals(m4,a.get(this));
157 <        while (!a.weakCompareAndSet(this,m4,seven));
158 <        assertEquals(seven,a.get(this));
154 >        while (!a.weakCompareAndSet(this, one, two));
155 >        while (!a.weakCompareAndSet(this, two, m4));
156 >        assertSame(m4, a.get(this));
157 >        while (!a.weakCompareAndSet(this, m4, seven));
158 >        assertSame(seven, a.get(this));
159      }
160  
161      /**
# Line 173 | Line 169 | public class AtomicReferenceFieldUpdater
169              return;
170          }
171          x = one;
172 <        assertEquals(one,a.getAndSet(this, zero));
173 <        assertEquals(zero,a.getAndSet(this,m10));
174 <        assertEquals(m10,a.getAndSet(this,1));
172 >        assertSame(one, a.getAndSet(this, zero));
173 >        assertSame(zero, a.getAndSet(this, m10));
174 >        assertSame(m10, a.getAndSet(this, 1));
175      }
176  
177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines