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; |
698 |
< |
long t0 = System.nanoTime(); |
697 |
> |
long startTime = System.nanoTime(); |
698 |
|
for (;;) { |
699 |
|
Thread.State s = thread.getState(); |
700 |
|
if (s == Thread.State.BLOCKED || |
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 |
|
} |
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; |