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

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.88 by jsr166, Tue May 31 15:01:24 2011 UTC vs.
Revision 1.92 by jsr166, Sun Nov 18 18:03:11 2012 UTC

# Line 69 | Line 69 | import java.security.SecurityPermission;
69   *
70   * </ol>
71   *
72 < * <p> <b>Other notes</b>
72 > * <p><b>Other notes</b>
73   * <ul>
74   *
75   * <li> Usually, there is one testcase method per JSR166 method
# Line 528 | Line 528 | public class JSR166TestCase extends Test
528      }
529  
530      /**
531 +     * Checks that the threads do not terminate within the default
532 +     * millisecond delay of {@code timeoutMillis()}.
533 +     */
534 +    void assertThreadsStayAlive(Thread... threads) {
535 +        assertThreadsStayAlive(timeoutMillis(), threads);
536 +    }
537 +
538 +    /**
539 +     * Checks that the threads do not terminate within the given millisecond delay.
540 +     */
541 +    void assertThreadsStayAlive(long millis, Thread... threads) {
542 +        try {
543 +            // No need to optimize the failing case via Thread.join.
544 +            delay(millis);
545 +            for (Thread thread : threads)
546 +                assertTrue(thread.isAlive());
547 +        } catch (InterruptedException ie) {
548 +            fail("Unexpected InterruptedException");
549 +        }
550 +    }
551 +
552 +    /**
553       * Checks that future.get times out, with the default timeout of
554       * {@code timeoutMillis()}.
555       */
# Line 904 | Line 926 | public class JSR166TestCase extends Test
926          }
927      }
928  
929 +    public void await(Semaphore semaphore) {
930 +        try {
931 +            assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
932 +        } catch (Throwable t) {
933 +            threadUnexpectedException(t);
934 +        }
935 +    }
936 +
937   //     /**
938   //      * Spin-waits up to LONG_DELAY_MS until flag becomes true.
939   //      */
# Line 1172 | Line 1202 | public class JSR166TestCase extends Test
1202          }
1203      }
1204  
1205 <    @SuppressWarnings("unchecked")
1206 <    <T> T serialClone(T o) {
1205 >    void assertSerialEquals(Object x, Object y) {
1206 >        assertTrue(Arrays.equals(serialBytes(x), serialBytes(y)));
1207 >    }
1208 >
1209 >    void assertNotSerialEquals(Object x, Object y) {
1210 >        assertFalse(Arrays.equals(serialBytes(x), serialBytes(y)));
1211 >    }
1212 >
1213 >    byte[] serialBytes(Object o) {
1214          try {
1215              ByteArrayOutputStream bos = new ByteArrayOutputStream();
1216              ObjectOutputStream oos = new ObjectOutputStream(bos);
1217              oos.writeObject(o);
1218              oos.flush();
1219              oos.close();
1220 +            return bos.toByteArray();
1221 +        } catch (Throwable t) {
1222 +            threadUnexpectedException(t);
1223 +            return new byte[0];
1224 +        }
1225 +    }
1226 +
1227 +    @SuppressWarnings("unchecked")
1228 +    <T> T serialClone(T o) {
1229 +        try {
1230              ObjectInputStream ois = new ObjectInputStream
1231 <                (new ByteArrayInputStream(bos.toByteArray()));
1231 >                (new ByteArrayInputStream(serialBytes(o)));
1232              T clone = (T) ois.readObject();
1233              assertSame(o.getClass(), clone.getClass());
1234              return clone;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines