SimpleTimeLimiterTest.java 文件源码

java
阅读 32 收藏 0 点赞 0 评论 0

项目:guava-mock 作者:
public void testNewProxy_goodMethodWithNotEnoughTime() throws Exception {
  SampleImpl target = new SampleImpl(9999);
  Sample proxy = service.newProxy(target, Sample.class, NOT_ENOUGH_MS, MILLISECONDS);
  Stopwatch stopwatch = Stopwatch.createStarted();

  try {
    proxy.sleepThenReturnInput("x");
    fail("no exception thrown");
  } catch (UncheckedTimeoutException expected) {
  }

  assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(NOT_ENOUGH_MS, DELAY_MS * 2));
  // Is it still computing away anyway?
  assertThat(target.finished).isFalse();
  MILLISECONDS.sleep(ENOUGH_MS);
  assertThat(target.finished).isFalse();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号