public void testRunUninterruptiblyWithTimeout_goodRunnableWithNotEnoughTime() throws Exception { try { service.runUninterruptiblyWithTimeout(GOOD_RUNNABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testRunUninterruptiblyWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runUninterruptiblyWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testRunUninterruptiblyWithTimeout_badRunnableWithEnoughTime() throws Exception { try { service.runUninterruptiblyWithTimeout(BAD_RUNNABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (UncheckedExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleRuntimeException.class); } }
public void testRunUninterruptiblyWithTimeout_wrapsUncheckedException() throws Exception { RuntimeException exception = new RuntimeException("test"); try { timeLimiter.runUninterruptiblyWithTimeout( runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected UncheckedExecutionException"); } catch (UncheckedExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }
public void testRunUninterruptiblyWithTimeout_goodRunnableWithNotEnoughTime() throws Exception { try { service.runUninterruptiblyWithTimeout(GOOD_RUNNABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testRunUninterruptiblyWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runUninterruptiblyWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testRunUninterruptiblyWithTimeout_badRunnableWithEnoughTime() throws Exception { try { service.runUninterruptiblyWithTimeout(BAD_RUNNABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (UncheckedExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleRuntimeException.class); } }
public void testRunUninterruptiblyWithTimeout_wrapsUncheckedException() throws Exception { RuntimeException exception = new RuntimeException("test"); try { timeLimiter.runUninterruptiblyWithTimeout( runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected UncheckedExecutionException"); } catch (UncheckedExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }