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

Comparing jsr166/src/test/tck/AtomicReferenceArrayTest.java (file contents):
Revision 1.13 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.16 by jsr166, Tue Nov 17 06:58:50 2009 UTC

# Line 36 | Line 36 | public class AtomicReferenceArrayTest ex
36          try {
37              Integer[] a = null;
38              AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
39 <        } catch (NullPointerException success) {
40 <        } catch (Exception ex) {
41 <            unexpectedException();
42 <        }
39 >            shouldThrow();
40 >        } catch (NullPointerException success) {}
41      }
42  
43      /**
# Line 61 | Line 59 | public class AtomicReferenceArrayTest ex
59          AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(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, null);
72 +            shouldThrow();
73          } catch (IndexOutOfBoundsException success) {
74          }
75          try {
76              ai.set(-1, null);
77 +            shouldThrow();
78          } catch (IndexOutOfBoundsException success) {
79          }
80      }
# Line 128 | Line 130 | public class AtomicReferenceArrayTest ex
130       * compareAndSet in one thread enables another waiting for value
131       * to succeed
132       */
133 <    public void testCompareAndSetInMultipleThreads() {
133 >    public void testCompareAndSetInMultipleThreads() throws InterruptedException {
134          final AtomicReferenceArray a = new AtomicReferenceArray(1);
135          a.set(0, one);
136 <        Thread t = new Thread(new Runnable() {
137 <                public void run() {
138 <                    while (!a.compareAndSet(0, two, three)) Thread.yield();
139 <                }});
140 <        try {
141 <            t.start();
142 <            assertTrue(a.compareAndSet(0, one, two));
143 <            t.join(LONG_DELAY_MS);
144 <            assertFalse(t.isAlive());
145 <            assertEquals(a.get(0), three);
146 <        }
145 <        catch (Exception e) {
146 <            unexpectedException();
147 <        }
136 >        Thread t = new Thread(new CheckedRunnable() {
137 >            public void realRun() {
138 >                while (!a.compareAndSet(0, two, three))
139 >                    Thread.yield();
140 >            }});
141 >
142 >        t.start();
143 >        assertTrue(a.compareAndSet(0, one, two));
144 >        t.join(LONG_DELAY_MS);
145 >        assertFalse(t.isAlive());
146 >        assertEquals(a.get(0), three);
147      }
148  
149      /**
# Line 179 | Line 178 | public class AtomicReferenceArrayTest ex
178      /**
179       * a deserialized serialized array holds same values
180       */
181 <    public void testSerialization() {
181 >    public void testSerialization() throws Exception {
182          AtomicReferenceArray l = new AtomicReferenceArray(SIZE);
183          for (int i = 0; i < SIZE; ++i) {
184              l.set(i, new Integer(-i));
185          }
186  
187 <        try {
188 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
189 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
190 <            out.writeObject(l);
191 <            out.close();
192 <
193 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
194 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
195 <            AtomicReferenceArray r = (AtomicReferenceArray) in.readObject();
196 <            assertEquals(l.length(), r.length());
197 <            for (int i = 0; i < SIZE; ++i) {
199 <                assertEquals(r.get(i), l.get(i));
200 <            }
201 <        } catch (Exception e) {
202 <            unexpectedException();
187 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
188 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
189 >        out.writeObject(l);
190 >        out.close();
191 >
192 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
193 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
194 >        AtomicReferenceArray r = (AtomicReferenceArray) in.readObject();
195 >        assertEquals(l.length(), r.length());
196 >        for (int i = 0; i < SIZE; ++i) {
197 >            assertEquals(r.get(i), l.get(i));
198          }
199      }
200  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines