1210
1211 /**
1212 * Checks that future.get times out, with the default timeout of
1213 * {@code timeoutMillis()}.
1214 */
1215 void assertFutureTimesOut(Future future) {
1216 assertFutureTimesOut(future, timeoutMillis());
1217 }
1218
1219 /**
1220 * Checks that future.get times out, with the given millisecond timeout.
1221 */
1222 void assertFutureTimesOut(Future future, long timeoutMillis) {
1223 long startTime = System.nanoTime();
1224 try {
1225 future.get(timeoutMillis, MILLISECONDS);
1226 shouldThrow();
1227 } catch (TimeoutException success) {
1228 } catch (Exception fail) {
1229 threadUnexpectedException(fail);
1230 } finally { future.cancel(true); }
1231 assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
1232 }
1233
1234 /**
1235 * Fails with message "should throw exception".
1236 */
1237 public void shouldThrow() {
1238 fail("Should throw exception");
1239 }
1240
1241 /**
1242 * Fails with message "should throw " + exceptionName.
1243 */
1244 public void shouldThrow(String exceptionName) {
1245 fail("Should throw " + exceptionName);
1246 }
1247
1248 /**
1249 * The maximum number of consecutive spurious wakeups we should
1250 * tolerate (from APIs like LockSupport.park) before failing a test.
1251 */
|
1210
1211 /**
1212 * Checks that future.get times out, with the default timeout of
1213 * {@code timeoutMillis()}.
1214 */
1215 void assertFutureTimesOut(Future future) {
1216 assertFutureTimesOut(future, timeoutMillis());
1217 }
1218
1219 /**
1220 * Checks that future.get times out, with the given millisecond timeout.
1221 */
1222 void assertFutureTimesOut(Future future, long timeoutMillis) {
1223 long startTime = System.nanoTime();
1224 try {
1225 future.get(timeoutMillis, MILLISECONDS);
1226 shouldThrow();
1227 } catch (TimeoutException success) {
1228 } catch (Exception fail) {
1229 threadUnexpectedException(fail);
1230 }
1231 assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
1232 assertFalse(future.isDone());
1233 }
1234
1235 /**
1236 * Fails with message "should throw exception".
1237 */
1238 public void shouldThrow() {
1239 fail("Should throw exception");
1240 }
1241
1242 /**
1243 * Fails with message "should throw " + exceptionName.
1244 */
1245 public void shouldThrow(String exceptionName) {
1246 fail("Should throw " + exceptionName);
1247 }
1248
1249 /**
1250 * The maximum number of consecutive spurious wakeups we should
1251 * tolerate (from APIs like LockSupport.park) before failing a test.
1252 */
|