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

Comparing jsr166/src/test/tck/AtomicReferenceTest.java (file contents):
Revision 1.17 by jsr166, Tue Mar 15 19:47:06 2011 UTC vs.
Revision 1.20 by jsr166, Fri Jun 10 20:17:11 2011 UTC

# Line 7 | Line 7
7   */
8  
9   import junit.framework.*;
10 < import java.util.concurrent.atomic.*;
11 < import java.io.*;
10 > import java.util.concurrent.atomic.AtomicReference;
11  
12   public class AtomicReferenceTest extends JSR166TestCase {
13      public static void main(String[] args) {
# Line 23 | Line 22 | public class AtomicReferenceTest extends
22       */
23      public void testConstructor() {
24          AtomicReference ai = new AtomicReference(one);
25 <        assertSame(one,ai.get());
25 >        assertSame(one, ai.get());
26      }
27  
28      /**
# Line 39 | Line 38 | public class AtomicReferenceTest extends
38       */
39      public void testGetSet() {
40          AtomicReference ai = new AtomicReference(one);
41 <        assertSame(one,ai.get());
41 >        assertSame(one, ai.get());
42          ai.set(two);
43 <        assertSame(two,ai.get());
43 >        assertSame(two, ai.get());
44          ai.set(m3);
45 <        assertSame(m3,ai.get());
45 >        assertSame(m3, ai.get());
46      }
47  
48      /**
# Line 51 | Line 50 | public class AtomicReferenceTest extends
50       */
51      public void testGetLazySet() {
52          AtomicReference ai = new AtomicReference(one);
53 <        assertSame(one,ai.get());
53 >        assertSame(one, ai.get());
54          ai.lazySet(two);
55 <        assertSame(two,ai.get());
55 >        assertSame(two, ai.get());
56          ai.lazySet(m3);
57 <        assertSame(m3,ai.get());
57 >        assertSame(m3, ai.get());
58      }
59  
60      /**
# Line 63 | Line 62 | public class AtomicReferenceTest extends
62       */
63      public void testCompareAndSet() {
64          AtomicReference ai = new AtomicReference(one);
65 <        assertTrue(ai.compareAndSet(one,two));
66 <        assertTrue(ai.compareAndSet(two,m4));
67 <        assertSame(m4,ai.get());
68 <        assertFalse(ai.compareAndSet(m5,seven));
69 <        assertSame(m4,ai.get());
70 <        assertTrue(ai.compareAndSet(m4,seven));
71 <        assertSame(seven,ai.get());
65 >        assertTrue(ai.compareAndSet(one, two));
66 >        assertTrue(ai.compareAndSet(two, m4));
67 >        assertSame(m4, ai.get());
68 >        assertFalse(ai.compareAndSet(m5, seven));
69 >        assertSame(m4, ai.get());
70 >        assertTrue(ai.compareAndSet(m4, seven));
71 >        assertSame(seven, ai.get());
72      }
73  
74      /**
# Line 88 | Line 87 | public class AtomicReferenceTest extends
87          assertTrue(ai.compareAndSet(one, two));
88          t.join(LONG_DELAY_MS);
89          assertFalse(t.isAlive());
90 <        assertSame(ai.get(), three);
90 >        assertSame(three, ai.get());
91      }
92  
93      /**
# Line 97 | Line 96 | public class AtomicReferenceTest extends
96       */
97      public void testWeakCompareAndSet() {
98          AtomicReference ai = new AtomicReference(one);
99 <        while (!ai.weakCompareAndSet(one,two));
100 <        while (!ai.weakCompareAndSet(two,m4));
101 <        assertSame(m4,ai.get());
102 <        while (!ai.weakCompareAndSet(m4,seven));
103 <        assertSame(seven,ai.get());
99 >        while (!ai.weakCompareAndSet(one, two));
100 >        while (!ai.weakCompareAndSet(two, m4));
101 >        assertSame(m4, ai.get());
102 >        while (!ai.weakCompareAndSet(m4, seven));
103 >        assertSame(seven, ai.get());
104      }
105  
106      /**
# Line 109 | Line 108 | public class AtomicReferenceTest extends
108       */
109      public void testGetAndSet() {
110          AtomicReference ai = new AtomicReference(one);
111 <        assertSame(one,ai.getAndSet(zero));
112 <        assertSame(zero,ai.getAndSet(m10));
113 <        assertSame(m10,ai.getAndSet(one));
111 >        assertSame(one, ai.getAndSet(zero));
112 >        assertSame(zero, ai.getAndSet(m10));
113 >        assertSame(m10, ai.getAndSet(one));
114      }
115  
116      /**
117       * a deserialized serialized atomic holds same value
118       */
119      public void testSerialization() throws Exception {
120 <        AtomicReference l = new AtomicReference();
121 <
122 <        l.set(one);
123 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
124 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
125 <        out.writeObject(l);
126 <        out.close();
127 <
129 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
130 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
131 <        AtomicReference r = (AtomicReference) in.readObject();
132 <        assertEquals(l.get(), r.get());
120 >        AtomicReference x = new AtomicReference();
121 >        AtomicReference y = serialClone(x);
122 >        assertTrue(x != y);
123 >        x.set(one);
124 >        AtomicReference z = serialClone(x);
125 >        assertEquals(one, x.get());
126 >        assertEquals(null, y.get());
127 >        assertEquals(one, z.get());
128      }
129  
130      /**
# Line 137 | Line 132 | public class AtomicReferenceTest extends
132       */
133      public void testToString() {
134          AtomicReference<Integer> ai = new AtomicReference<Integer>(one);
135 <        assertEquals(ai.toString(), one.toString());
135 >        assertEquals(one.toString(), ai.toString());
136          ai.set(two);
137 <        assertEquals(ai.toString(), two.toString());
137 >        assertEquals(two.toString(), ai.toString());
138      }
139  
140   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines