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.11 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.13 by jsr166, Tue Nov 17 06:58:50 2009 UTC

# Line 76 | Line 76 | public class AtomicReferenceTest extends
76       * compareAndSet in one thread enables another waiting for value
77       * to succeed
78       */
79 <    public void testCompareAndSetInMultipleThreads() {
79 >    public void testCompareAndSetInMultipleThreads() throws Exception {
80          final AtomicReference ai = new AtomicReference(one);
81 <        Thread t = new Thread(new Runnable() {
82 <                public void run() {
83 <                    while (!ai.compareAndSet(two, three)) Thread.yield();
84 <                }});
85 <        try {
86 <            t.start();
87 <            assertTrue(ai.compareAndSet(one, two));
88 <            t.join(LONG_DELAY_MS);
89 <            assertFalse(t.isAlive());
90 <            assertEquals(ai.get(), three);
91 <        }
92 <        catch (Exception e) {
93 <            unexpectedException();
94 <        }
81 >        Thread t = new Thread(new CheckedRunnable() {
82 >            public void realRun() {
83 >                while (!ai.compareAndSet(two, three))
84 >                    Thread.yield();
85 >            }});
86 >
87 >        t.start();
88 >        assertTrue(ai.compareAndSet(one, two));
89 >        t.join(LONG_DELAY_MS);
90 >        assertFalse(t.isAlive());
91 >        assertEquals(ai.get(), three);
92      }
93  
94      /**
# Line 120 | Line 117 | public class AtomicReferenceTest extends
117      /**
118       * a deserialized serialized atomic holds same value
119       */
120 <    public void testSerialization() {
120 >    public void testSerialization() throws Exception {
121          AtomicReference l = new AtomicReference();
122  
123 <        try {
124 <            l.set(one);
125 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
126 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
127 <            out.writeObject(l);
128 <            out.close();
129 <
130 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
131 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
132 <            AtomicReference r = (AtomicReference) in.readObject();
136 <            assertEquals(l.get(), r.get());
137 <        } catch (Exception e) {
138 <            unexpectedException();
139 <        }
123 >        l.set(one);
124 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
125 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
126 >        out.writeObject(l);
127 >        out.close();
128 >
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());
133      }
134  
135      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines