< prev index next >

test/jdk/java/util/concurrent/tck/JSR166TestCase.java

Print this page
8207003: Miscellaneous changes imported from jsr166 CVS 2018-09
Reviewed-by: martin, chegar

*** 1413,1425 **** * Checks that timed f.get() returns the expected value, and does not * wait for the timeout to elapse before returning. */ <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) { long startTime = System.nanoTime(); try { ! assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS)); } catch (Throwable fail) { threadUnexpectedException(fail); } if (millisElapsedSince(startTime) > timeoutMillis/2) throw new AssertionError("timed get did not return promptly"); } <T> void checkTimedGet(Future<T> f, T expectedValue) { --- 1413,1427 ---- * Checks that timed f.get() returns the expected value, and does not * wait for the timeout to elapse before returning. */ <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) { long startTime = System.nanoTime(); + T actual = null; try { ! actual = f.get(timeoutMillis, MILLISECONDS); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertEquals(expectedValue, actual); if (millisElapsedSince(startTime) > timeoutMillis/2) throw new AssertionError("timed get did not return promptly"); } <T> void checkTimedGet(Future<T> f, T expectedValue) {
*** 1594,1624 **** public LatchAwaiter awaiter(CountDownLatch latch) { return new LatchAwaiter(latch); } public void await(CountDownLatch latch, long timeoutMillis) { try { ! if (!latch.await(timeoutMillis, MILLISECONDS)) ! fail("timed out waiting for CountDownLatch for " ! + (timeoutMillis/1000) + " sec"); } catch (Throwable fail) { threadUnexpectedException(fail); } } public void await(CountDownLatch latch) { await(latch, LONG_DELAY_MS); } public void await(Semaphore semaphore) { try { ! if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)) ! fail("timed out waiting for Semaphore for " ! + (LONG_DELAY_MS/1000) + " sec"); } catch (Throwable fail) { threadUnexpectedException(fail); } } public void await(CyclicBarrier barrier) { try { barrier.await(LONG_DELAY_MS, MILLISECONDS); --- 1596,1630 ---- public LatchAwaiter awaiter(CountDownLatch latch) { return new LatchAwaiter(latch); } public void await(CountDownLatch latch, long timeoutMillis) { + boolean timedOut = false; try { ! timedOut = !latch.await(timeoutMillis, MILLISECONDS); } catch (Throwable fail) { threadUnexpectedException(fail); } + if (timedOut) + fail("timed out waiting for CountDownLatch for " + + (timeoutMillis/1000) + " sec"); } public void await(CountDownLatch latch) { await(latch, LONG_DELAY_MS); } public void await(Semaphore semaphore) { + boolean timedOut = false; try { ! timedOut = !semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS); } catch (Throwable fail) { threadUnexpectedException(fail); } + if (timedOut) + fail("timed out waiting for Semaphore for " + + (LONG_DELAY_MS/1000) + " sec"); } public void await(CyclicBarrier barrier) { try { barrier.await(LONG_DELAY_MS, MILLISECONDS);
*** 1800,1820 **** } } @SuppressWarnings("unchecked") <T> T serialClone(T o) { try { ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream(serialBytes(o))); ! T clone = (T) ois.readObject(); ! if (o == clone) assertImmutable(o); ! assertSame(o.getClass(), clone.getClass()); ! return clone; } catch (Throwable fail) { threadUnexpectedException(fail); - return null; } } /** * A version of serialClone that leaves error handling (for * e.g. NotSerializableException) up to the caller. --- 1806,1826 ---- } } @SuppressWarnings("unchecked") <T> T serialClone(T o) { + T clone = null; try { ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream(serialBytes(o))); ! clone = (T) ois.readObject(); } catch (Throwable fail) { threadUnexpectedException(fail); } + if (o == clone) assertImmutable(o); + else assertSame(o.getClass(), clone.getClass()); + return clone; } /** * A version of serialClone that leaves error handling (for * e.g. NotSerializableException) up to the caller.
*** 1829,1839 **** oos.close(); ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream(bos.toByteArray())); T clone = (T) ois.readObject(); if (o == clone) assertImmutable(o); ! assertSame(o.getClass(), clone.getClass()); return clone; } /** * If o implements Cloneable and has a public clone method, --- 1835,1845 ---- oos.close(); ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream(bos.toByteArray())); T clone = (T) ois.readObject(); if (o == clone) assertImmutable(o); ! else assertSame(o.getClass(), clone.getClass()); return clone; } /** * If o implements Cloneable and has a public clone method,
< prev index next >