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

Comparing jsr166/src/test/tck/AtomicLongFieldUpdaterTest.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 26 | Line 26 | public class AtomicLongFieldUpdaterTest
26       * Construction with non-existent field throws RuntimeException
27       */
28      public void testConstructor(){
29 <        try{
30 <            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
29 >        try {
30 >            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
31                  a = AtomicLongFieldUpdater.newUpdater
32                  (AtomicLongFieldUpdaterTest.class, "y");
33              shouldThrow();
# Line 39 | Line 39 | public class AtomicLongFieldUpdaterTest
39       * construction with field not of given type throws RuntimeException
40       */
41      public void testConstructor2(){
42 <        try{
43 <            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
42 >        try {
43 >            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
44                  a = AtomicLongFieldUpdater.newUpdater
45                  (AtomicLongFieldUpdaterTest.class, "z");
46              shouldThrow();
# Line 52 | Line 52 | public class AtomicLongFieldUpdaterTest
52       * construction with non-volatile field throws RuntimeException
53       */
54      public void testConstructor3(){
55 <        try{
56 <            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
55 >        try {
56 >            AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
57                  a = AtomicLongFieldUpdater.newUpdater
58                  (AtomicLongFieldUpdaterTest.class, "w");
59              shouldThrow();
# Line 78 | Line 78 | public class AtomicLongFieldUpdaterTest
78          assertEquals(2,a.get(this));
79          a.set(this,-3);
80          assertEquals(-3,a.get(this));
81        
81      }
82 +
83 +    /**
84 +     *  get returns the last value lazySet by same thread
85 +     */
86 +    public void testGetLazySet(){
87 +        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
88 +        try {
89 +            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
90 +        } catch (RuntimeException ok) {
91 +            return;
92 +        }
93 +        x = 1;
94 +        assertEquals(1,a.get(this));
95 +        a.lazySet(this,2);
96 +        assertEquals(2,a.get(this));
97 +        a.lazySet(this,-3);
98 +        assertEquals(-3,a.get(this));
99 +    }
100 +
101 +
102      /**
103       * compareAndSet succeeds in changing value if equal to expected else fails
104       */
# Line 116 | Line 135 | public class AtomicLongFieldUpdaterTest
135  
136          Thread t = new Thread(new Runnable() {
137                  public void run() {
138 <                    while(!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3)) Thread.yield();
138 >                    while (!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3)) Thread.yield();
139                  }});
140          try {
141              t.start();
# Line 125 | Line 144 | public class AtomicLongFieldUpdaterTest
144              assertFalse(t.isAlive());
145              assertEquals(a.get(this), 3);
146          }
147 <        catch(Exception e) {
147 >        catch (Exception e) {
148              unexpectedException();
149          }
150      }
151  
152      /**
153       * repeated weakCompareAndSet succeeds in changing value when equal
154 <     * to expected
154 >     * to expected
155       */
156      public void testWeakCompareAndSet(){
157          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
# Line 142 | Line 161 | public class AtomicLongFieldUpdaterTest
161              return;
162          }
163          x = 1;
164 <        while(!a.weakCompareAndSet(this,1,2));
165 <        while(!a.weakCompareAndSet(this,2,-4));
164 >        while (!a.weakCompareAndSet(this,1,2));
165 >        while (!a.weakCompareAndSet(this,2,-4));
166          assertEquals(-4,a.get(this));
167 <        while(!a.weakCompareAndSet(this,-4,7));
167 >        while (!a.weakCompareAndSet(this,-4,7));
168          assertEquals(7,a.get(this));
169      }
170  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines