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

Comparing jsr166/src/test/tck/AtomicIntegerArrayTest.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 02:37:16 2009 UTC

# Line 37 | Line 37 | public class AtomicIntegerArrayTest exte
37          try {
38              int[] a = null;
39              AtomicIntegerArray ai = new AtomicIntegerArray(a);
40 <        } catch (NullPointerException success) {
41 <        } catch (Exception ex) {
42 <            unexpectedException();
43 <        }
40 >            shouldThrow();
41 >        } catch (NullPointerException success) {}
42      }
43  
44      /**
# Line 61 | Line 59 | public class AtomicIntegerArrayTest exte
59          AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
60          try {
61              ai.get(SIZE);
62 +            shouldThrow();
63          } catch (IndexOutOfBoundsException success) {
64          }
65          try {
66              ai.get(-1);
67 +            shouldThrow();
68          } catch (IndexOutOfBoundsException success) {
69          }
70          try {
71              ai.set(SIZE, 0);
72 +            shouldThrow();
73          } catch (IndexOutOfBoundsException success) {
74          }
75          try {
76              ai.set(-1, 0);
77 +            shouldThrow();
78          } catch (IndexOutOfBoundsException success) {
79          }
80      }
# Line 128 | Line 130 | public class AtomicIntegerArrayTest exte
130       * compareAndSet in one thread enables another waiting for value
131       * to succeed
132       */
133 <    public void testCompareAndSetInMultipleThreads() {
133 >    public void testCompareAndSetInMultipleThreads() throws Exception {
134          final AtomicIntegerArray a = new AtomicIntegerArray(1);
135          a.set(0, 1);
136          Thread t = new Thread(new Runnable() {
137                  public void run() {
138                      while (!a.compareAndSet(0, 2, 3)) Thread.yield();
139                  }});
140 <        try {
141 <            t.start();
142 <            assertTrue(a.compareAndSet(0, 1, 2));
143 <            t.join(LONG_DELAY_MS);
144 <            assertFalse(t.isAlive());
145 <            assertEquals(a.get(0), 3);
144 <        }
145 <        catch (Exception e) {
146 <            unexpectedException();
147 <        }
140 >
141 >        t.start();
142 >        assertTrue(a.compareAndSet(0, 1, 2));
143 >        t.join(LONG_DELAY_MS);
144 >        assertFalse(t.isAlive());
145 >        assertEquals(a.get(0), 3);
146      }
147  
148      /**
# Line 293 | Line 291 | public class AtomicIntegerArrayTest exte
291       * Multiple threads using same array of counters successfully
292       * update a number of times equal to total count
293       */
294 <    public void testCountingInMultipleThreads() {
295 <        try {
296 <            final AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
297 <            for (int i = 0; i < SIZE; ++i)
298 <                ai.set(i, COUNTDOWN);
299 <            Counter c1 = new Counter(ai);
300 <            Counter c2 = new Counter(ai);
301 <            Thread t1 = new Thread(c1);
302 <            Thread t2 = new Thread(c2);
303 <            t1.start();
304 <            t2.start();
305 <            t1.join();
306 <            t2.join();
309 <            assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
310 <        }
311 <        catch (InterruptedException ie) {
312 <            unexpectedException();
313 <        }
294 >    public void testCountingInMultipleThreads() throws InterruptedException {
295 >        final AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
296 >        for (int i = 0; i < SIZE; ++i)
297 >            ai.set(i, COUNTDOWN);
298 >        Counter c1 = new Counter(ai);
299 >        Counter c2 = new Counter(ai);
300 >        Thread t1 = new Thread(c1);
301 >        Thread t2 = new Thread(c2);
302 >        t1.start();
303 >        t2.start();
304 >        t1.join();
305 >        t2.join();
306 >        assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
307      }
308  
309  
310      /**
311       * a deserialized serialized array holds same values
312       */
313 <    public void testSerialization() {
313 >    public void testSerialization() throws Exception {
314          AtomicIntegerArray l = new AtomicIntegerArray(SIZE);
315          for (int i = 0; i < SIZE; ++i)
316              l.set(i, -i);
317  
318 <        try {
319 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
320 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
321 <            out.writeObject(l);
322 <            out.close();
323 <
324 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
325 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
326 <            AtomicIntegerArray r = (AtomicIntegerArray) in.readObject();
327 <            for (int i = 0; i < SIZE; ++i) {
335 <                assertEquals(l.get(i), r.get(i));
336 <            }
337 <        } catch (Exception e) {
338 <            e.printStackTrace();
339 <            unexpectedException();
318 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
319 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
320 >        out.writeObject(l);
321 >        out.close();
322 >
323 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
324 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
325 >        AtomicIntegerArray r = (AtomicIntegerArray) in.readObject();
326 >        for (int i = 0; i < SIZE; ++i) {
327 >            assertEquals(l.get(i), r.get(i));
328          }
329      }
330  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines