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

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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines