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.83 by jsr166, Fri May 27 19:29:59 2011 UTC vs.
Revision 1.88 by jsr166, Tue May 31 15:01:24 2011 UTC

# Line 283 | Line 283 | public class JSR166TestCase extends Test
283       * milliseconds in the future.
284       */
285      Date delayedDate(long delayMillis) {
286 <        return new Date(new Date().getTime() + delayMillis);
286 >        return new Date(System.currentTimeMillis() + delayMillis);
287      }
288  
289      /**
# Line 307 | Line 307 | public class JSR166TestCase extends Test
307      }
308  
309      /**
310 +     * Extra checks that get done for all test cases.
311 +     *
312       * Triggers test case failure if any thread assertions have failed,
313       * by rethrowing, in the test harness thread, any exception recorded
314       * earlier by threadRecordFailure.
315 +     *
316 +     * Triggers test case failure if interrupt status is set in the main thread.
317       */
318      public void tearDown() throws Exception {
319          Throwable t = threadFailure.getAndSet(null);
# Line 327 | Line 331 | public class JSR166TestCase extends Test
331                  throw afe;
332              }
333          }
334 +
335 +        if (Thread.interrupted())
336 +            throw new AssertionFailedError("interrupt status set in main thread");
337      }
338  
339      /**
# Line 683 | Line 690 | public class JSR166TestCase extends Test
690      }
691  
692      /**
693 <     * Waits up to the specified number of milliseconds for the given
693 >     * Spin-waits up to the specified number of milliseconds for the given
694       * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
695       */
696      void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) {
697 <        long timeoutNanos = timeoutMillis * 1000L * 1000L;
691 <        long t0 = System.nanoTime();
697 >        long startTime = System.nanoTime();
698          for (;;) {
699              Thread.State s = thread.getState();
700              if (s == Thread.State.BLOCKED ||
# Line 697 | Line 703 | public class JSR166TestCase extends Test
703                  return;
704              else if (s == Thread.State.TERMINATED)
705                  fail("Unexpected thread termination");
706 <            else if (System.nanoTime() - t0 > timeoutNanos) {
706 >            else if (millisElapsedSince(startTime) > timeoutMillis) {
707                  threadAssertTrue(thread.isAlive());
708                  return;
709              }
# Line 1119 | Line 1125 | public class JSR166TestCase extends Test
1125      }
1126  
1127      /**
1128 <     * A CyclicBarrier that fails with AssertionFailedErrors instead
1129 <     * of throwing checked exceptions.
1128 >     * A CyclicBarrier that uses timed await and fails with
1129 >     * AssertionFailedErrors instead of throwing checked exceptions.
1130       */
1131      public class CheckedBarrier extends CyclicBarrier {
1132          public CheckedBarrier(int parties) { super(parties); }
1133  
1134          public int await() {
1135              try {
1136 <                return super.await();
1136 >                return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
1137 >            } catch (TimeoutException e) {
1138 >                throw new AssertionFailedError("timed out");
1139              } catch (Exception e) {
1140                  AssertionFailedError afe =
1141                      new AssertionFailedError("Unexpected exception: " + e);
# Line 1172 | Line 1180 | public class JSR166TestCase extends Test
1180              oos.writeObject(o);
1181              oos.flush();
1182              oos.close();
1183 <            ByteArrayInputStream bin =
1184 <                new ByteArrayInputStream(bos.toByteArray());
1185 <            ObjectInputStream ois = new ObjectInputStream(bin);
1186 <            return (T) ois.readObject();
1183 >            ObjectInputStream ois = new ObjectInputStream
1184 >                (new ByteArrayInputStream(bos.toByteArray()));
1185 >            T clone = (T) ois.readObject();
1186 >            assertSame(o.getClass(), clone.getClass());
1187 >            return clone;
1188          } catch (Throwable t) {
1189              threadUnexpectedException(t);
1190              return null;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines