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

Comparing jsr166/src/test/tck/AtomicLongTest.java (file contents):
Revision 1.13 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.14 by jsr166, Tue Nov 17 03:12:51 2009 UTC

# Line 78 | Line 78 | public class AtomicLongTest extends JSR1
78       * compareAndSet in one thread enables another waiting for value
79       * to succeed
80       */
81 <    public void testCompareAndSetInMultipleThreads() {
81 >    public void testCompareAndSetInMultipleThreads() throws Exception {
82          final AtomicLong ai = new AtomicLong(1);
83          Thread t = new Thread(new Runnable() {
84                  public void run() {
85                      while (!ai.compareAndSet(2, 3)) Thread.yield();
86                  }});
87 <        try {
88 <            t.start();
89 <            assertTrue(ai.compareAndSet(1, 2));
90 <            t.join(LONG_DELAY_MS);
91 <            assertFalse(t.isAlive());
92 <            assertEquals(ai.get(), 3);
93 <        }
94 <        catch (Exception e) {
95 <            unexpectedException();
96 <        }
87 >
88 >        t.start();
89 >        assertTrue(ai.compareAndSet(1, 2));
90 >        t.join(LONG_DELAY_MS);
91 >        assertFalse(t.isAlive());
92 >        assertEquals(ai.get(), 3);
93      }
94  
95      /**
# Line 193 | Line 189 | public class AtomicLongTest extends JSR1
189      /**
190       * a deserialized serialized atomic holds same value
191       */
192 <    public void testSerialization() {
192 >    public void testSerialization() throws Exception {
193          AtomicLong l = new AtomicLong();
194  
195 <        try {
196 <            l.set(-22);
197 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
198 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
199 <            out.writeObject(l);
200 <            out.close();
201 <
202 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
203 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
204 <            AtomicLong r = (AtomicLong) in.readObject();
209 <            assertEquals(l.get(), r.get());
210 <        } catch (Exception e) {
211 <            unexpectedException();
212 <        }
195 >        l.set(-22);
196 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
197 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
198 >        out.writeObject(l);
199 >        out.close();
200 >
201 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
202 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
203 >        AtomicLong r = (AtomicLong) in.readObject();
204 >        assertEquals(l.get(), r.get());
205      }
206  
207      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines