--- jsr166/src/test/tck/JSR166TestCase.java 2011/05/31 15:01:24 1.88 +++ jsr166/src/test/tck/JSR166TestCase.java 2011/12/08 18:54:46 1.91 @@ -528,6 +528,28 @@ public class JSR166TestCase extends Test } /** + * Checks that the threads do not terminate within the default + * millisecond delay of {@code timeoutMillis()}. + */ + void assertThreadsStayAlive(Thread... threads) { + assertThreadsStayAlive(timeoutMillis(), threads); + } + + /** + * Checks that the threads do not terminate within the given millisecond delay. + */ + void assertThreadsStayAlive(long millis, Thread... threads) { + try { + // No need to optimize the failing case via Thread.join. + delay(millis); + for (Thread thread : threads) + assertTrue(thread.isAlive()); + } catch (InterruptedException ie) { + fail("Unexpected InterruptedException"); + } + } + + /** * Checks that future.get times out, with the default timeout of * {@code timeoutMillis()}. */ @@ -904,6 +926,14 @@ public class JSR166TestCase extends Test } } + public void await(Semaphore semaphore) { + try { + assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)); + } catch (Throwable t) { + threadUnexpectedException(t); + } + } + // /** // * Spin-waits up to LONG_DELAY_MS until flag becomes true. // */ @@ -1172,16 +1202,33 @@ public class JSR166TestCase extends Test } } - @SuppressWarnings("unchecked") - T serialClone(T o) { + void assertSerialEquals(Object x, Object y) { + assertTrue(Arrays.equals(serialBytes(x), serialBytes(y))); + } + + void assertNotSerialEquals(Object x, Object y) { + assertFalse(Arrays.equals(serialBytes(x), serialBytes(y))); + } + + byte[] serialBytes(Object o) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(o); oos.flush(); oos.close(); + return bos.toByteArray(); + } catch (Throwable t) { + threadUnexpectedException(t); + return new byte[0]; + } + } + + @SuppressWarnings("unchecked") + T serialClone(T o) { + try { ObjectInputStream ois = new ObjectInputStream - (new ByteArrayInputStream(bos.toByteArray())); + (new ByteArrayInputStream(serialBytes(o))); T clone = (T) ois.readObject(); assertSame(o.getClass(), clone.getClass()); return clone;