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

Comparing jsr166/src/test/tck/AtomicIntegerFieldUpdaterTest.java (file contents):
Revision 1.8 by dl, Tue Jan 20 20:20:56 2004 UTC vs.
Revision 1.11 by jsr166, Mon Nov 16 04:57:10 2009 UTC

# Line 2 | Line 2
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
5 < * Other contributors include Andrew Wright, Jeffrey Hayes,
6 < * Pat Fisher, Mike Judd.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import java.util.concurrent.atomic.*;
# Line 25 | Line 25 | public class AtomicIntegerFieldUpdaterTe
25       * Construction with non-existent field throws RuntimeException
26       */
27      public void testConstructor() {
28 <        try{
29 <            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
28 >        try {
29 >            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
30                  a = AtomicIntegerFieldUpdater.newUpdater
31                  (AtomicIntegerFieldUpdaterTest.class, "y");
32              shouldThrow();
# Line 38 | Line 38 | public class AtomicIntegerFieldUpdaterTe
38       * construction with field not of given type throws RuntimeException
39       */
40      public void testConstructor2() {
41 <        try{
42 <            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
41 >        try {
42 >            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
43                  a = AtomicIntegerFieldUpdater.newUpdater
44                  (AtomicIntegerFieldUpdaterTest.class, "z");
45              shouldThrow();
# Line 51 | Line 51 | public class AtomicIntegerFieldUpdaterTe
51       * construction with non-volatile field throws RuntimeException
52       */
53      public void testConstructor3() {
54 <        try{
55 <            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
54 >        try {
55 >            AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>
56                  a = AtomicIntegerFieldUpdater.newUpdater
57                  (AtomicIntegerFieldUpdaterTest.class, "w");
58              shouldThrow();
# Line 76 | Line 76 | public class AtomicIntegerFieldUpdaterTe
76          assertEquals(2,a.get(this));
77          a.set(this,-3);
78          assertEquals(-3,a.get(this));
79 <        
79 >
80 >    }
81 >
82 >    /**
83 >     *  get returns the last value lazySet by same thread
84 >     */
85 >    public void testGetLazySet() {
86 >        AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a;
87 >        try {
88 >            a = AtomicIntegerFieldUpdater.newUpdater(AtomicIntegerFieldUpdaterTest.class, "x");
89 >        } catch (RuntimeException ok) {
90 >            return;
91 >        }
92 >        x = 1;
93 >        assertEquals(1,a.get(this));
94 >        a.lazySet(this,2);
95 >        assertEquals(2,a.get(this));
96 >        a.lazySet(this,-3);
97 >        assertEquals(-3,a.get(this));
98 >
99      }
100 +
101      /**
102       * compareAndSet succeeds in changing value if equal to expected else fails
103       */
# Line 114 | Line 134 | public class AtomicIntegerFieldUpdaterTe
134  
135          Thread t = new Thread(new Runnable() {
136                  public void run() {
137 <                    while(!a.compareAndSet(AtomicIntegerFieldUpdaterTest.this, 2, 3)) Thread.yield();
137 >                    while (!a.compareAndSet(AtomicIntegerFieldUpdaterTest.this, 2, 3)) Thread.yield();
138                  }});
139          try {
140              t.start();
# Line 123 | Line 143 | public class AtomicIntegerFieldUpdaterTe
143              assertFalse(t.isAlive());
144              assertEquals(a.get(this), 3);
145          }
146 <        catch(Exception e) {
146 >        catch (Exception e) {
147              unexpectedException();
148          }
149      }
150  
151      /**
152       * repeated weakCompareAndSet succeeds in changing value when equal
153 <     * to expected
153 >     * to expected
154       */
155      public void testWeakCompareAndSet() {
156          AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a;
# Line 140 | Line 160 | public class AtomicIntegerFieldUpdaterTe
160              return;
161          }
162          x = 1;
163 <        while(!a.weakCompareAndSet(this,1,2));
164 <        while(!a.weakCompareAndSet(this,2,-4));
163 >        while (!a.weakCompareAndSet(this,1,2));
164 >        while (!a.weakCompareAndSet(this,2,-4));
165          assertEquals(-4,a.get(this));
166 <        while(!a.weakCompareAndSet(this,-4,7));
166 >        while (!a.weakCompareAndSet(this,-4,7));
167          assertEquals(7,a.get(this));
168      }
169  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines