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.11 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.14 by jsr166, Tue Nov 17 06:58:50 2009 UTC

# Line 15 | Line 15 | public class AtomicLongFieldUpdaterTest
15      int z;
16      long w;
17  
18 <    public static void main(String[] args){
18 >    public static void main(String[] args) {
19          junit.textui.TestRunner.run(suite());
20      }
21      public static Test suite() {
# Line 25 | Line 25 | public class AtomicLongFieldUpdaterTest
25      /**
26       * Construction with non-existent field throws RuntimeException
27       */
28 <    public void testConstructor(){
28 >    public void testConstructor() {
29          try {
30              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
31                  a = AtomicLongFieldUpdater.newUpdater
# Line 38 | Line 38 | public class AtomicLongFieldUpdaterTest
38      /**
39       * construction with field not of given type throws RuntimeException
40       */
41 <    public void testConstructor2(){
41 >    public void testConstructor2() {
42          try {
43              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
44                  a = AtomicLongFieldUpdater.newUpdater
# Line 51 | Line 51 | public class AtomicLongFieldUpdaterTest
51      /**
52       * construction with non-volatile field throws RuntimeException
53       */
54 <    public void testConstructor3(){
54 >    public void testConstructor3() {
55          try {
56              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
57                  a = AtomicLongFieldUpdater.newUpdater
# Line 65 | Line 65 | public class AtomicLongFieldUpdaterTest
65      /**
66       *  get returns the last value set or assigned
67       */
68 <    public void testGetSet(){
68 >    public void testGetSet() {
69          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
70          try {
71              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 83 | Line 83 | public class AtomicLongFieldUpdaterTest
83      /**
84       *  get returns the last value lazySet by same thread
85       */
86 <    public void testGetLazySet(){
86 >    public void testGetLazySet() {
87          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
88          try {
89              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 102 | Line 102 | public class AtomicLongFieldUpdaterTest
102      /**
103       * compareAndSet succeeds in changing value if equal to expected else fails
104       */
105 <    public void testCompareAndSet(){
105 >    public void testCompareAndSet() {
106          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
107          try {
108              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 124 | Line 124 | public class AtomicLongFieldUpdaterTest
124       * compareAndSet in one thread enables another waiting for value
125       * to succeed
126       */
127 <    public void testCompareAndSetInMultipleThreads() {
127 >    public void testCompareAndSetInMultipleThreads() throws Exception {
128          x = 1;
129          final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a;
130          try {
# Line 133 | Line 133 | public class AtomicLongFieldUpdaterTest
133              return;
134          }
135  
136 <        Thread t = new Thread(new Runnable() {
137 <                public void run() {
138 <                    while (!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3)) Thread.yield();
139 <                }});
140 <        try {
141 <            t.start();
142 <            assertTrue(a.compareAndSet(this, 1, 2));
143 <            t.join(LONG_DELAY_MS);
144 <            assertFalse(t.isAlive());
145 <            assertEquals(a.get(this), 3);
146 <        }
147 <        catch (Exception e) {
148 <            unexpectedException();
149 <        }
136 >        Thread t = new Thread(new CheckedRunnable() {
137 >            public void realRun() {
138 >                while (!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3))
139 >                    Thread.yield();
140 >            }});
141 >
142 >        t.start();
143 >        assertTrue(a.compareAndSet(this, 1, 2));
144 >        t.join(LONG_DELAY_MS);
145 >        assertFalse(t.isAlive());
146 >        assertEquals(a.get(this), 3);
147      }
148  
149      /**
150       * repeated weakCompareAndSet succeeds in changing value when equal
151       * to expected
152       */
153 <    public void testWeakCompareAndSet(){
153 >    public void testWeakCompareAndSet() {
154          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
155          try {
156              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 171 | Line 168 | public class AtomicLongFieldUpdaterTest
168      /**
169       *  getAndSet returns previous value and sets to given value
170       */
171 <    public void testGetAndSet(){
171 >    public void testGetAndSet() {
172          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
173          try {
174              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 187 | Line 184 | public class AtomicLongFieldUpdaterTest
184      /**
185       * getAndAdd returns previous value and adds given value
186       */
187 <    public void testGetAndAdd(){
187 >    public void testGetAndAdd() {
188          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
189          try {
190              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 204 | Line 201 | public class AtomicLongFieldUpdaterTest
201      /**
202       * getAndDecrement returns previous value and decrements
203       */
204 <    public void testGetAndDecrement(){
204 >    public void testGetAndDecrement() {
205          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
206          try {
207              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 220 | Line 217 | public class AtomicLongFieldUpdaterTest
217      /**
218       * getAndIncrement returns previous value and increments
219       */
220 <    public void testGetAndIncrement(){
220 >    public void testGetAndIncrement() {
221          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
222          try {
223              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 240 | Line 237 | public class AtomicLongFieldUpdaterTest
237      /**
238       * addAndGet adds given value to current, and returns current value
239       */
240 <    public void testAddAndGet(){
240 >    public void testAddAndGet() {
241          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
242          try {
243              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 257 | Line 254 | public class AtomicLongFieldUpdaterTest
254      /**
255       *  decrementAndGet decrements and returns current value
256       */
257 <    public void testDecrementAndGet(){
257 >    public void testDecrementAndGet() {
258          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
259          try {
260              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
# Line 274 | Line 271 | public class AtomicLongFieldUpdaterTest
271      /**
272       * incrementAndGet increments and returns current value
273       */
274 <    public void testIncrementAndGet(){
274 >    public void testIncrementAndGet() {
275          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
276          try {
277              a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines