public void testRunWithTimeout_goodRunnableWithNotEnoughTime() throws Exception { try { service.runWithTimeout(GOOD_RUNNABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testRunWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testRunWithTimeout_returnsWithoutException() throws Exception { timeLimiter.runWithTimeout(Runnables.doNothing(), DELAY_MS, TimeUnit.MILLISECONDS); }
public void testRunWithTimeout_badRunnableWithEnoughTime() throws Exception { try { service.runWithTimeout(BAD_RUNNABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (UncheckedExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleRuntimeException.class); } }
public void testRunWithTimeout_wrapsUncheckedException() throws Exception { RuntimeException exception = new RuntimeException("test"); try { timeLimiter.runWithTimeout(runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected UncheckedExecutionException"); } catch (UncheckedExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }
public void testRunWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testRunWithTimeout_goodRunnableWithNotEnoughTime() throws Exception { try { service.runWithTimeout(GOOD_RUNNABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testRunWithTimeout_returnsWithoutException() throws Exception { timeLimiter.runWithTimeout(Runnables.doNothing(), DELAY_MS, TimeUnit.MILLISECONDS); }
public void testRunWithTimeout_badRunnableWithEnoughTime() throws Exception { try { service.runWithTimeout(BAD_RUNNABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (UncheckedExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleRuntimeException.class); } }
public void testRunWithTimeout_wrapsUncheckedException() throws Exception { RuntimeException exception = new RuntimeException("test"); try { timeLimiter.runWithTimeout(runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected UncheckedExecutionException"); } catch (UncheckedExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }