public void testCallUninterruptiblyWithTimeout_goodCallableWithNotEnoughTime() throws Exception { try { service.callUninterruptiblyWithTimeout(GOOD_CALLABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testCallUninterruptiblyWithTimeout_goodCallableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); String result = service.callUninterruptiblyWithTimeout(GOOD_CALLABLE, ENOUGH_MS, MILLISECONDS); assertThat(result).isEqualTo(GOOD_CALLABLE_RESULT); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testCallUninterruptiblyWithTimeout_badCallableWithEnoughTime() throws Exception { try { service.callUninterruptiblyWithTimeout(BAD_CALLABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleException.class); } }
public void testCallUninterruptiblyWithTimeout_propagatesReturnValue() throws Exception { String result = timeLimiter.callUninterruptiblyWithTimeout( Callables.returning(RETURN_VALUE), DELAY_MS, TimeUnit.MILLISECONDS); assertThat(result).isEqualTo(RETURN_VALUE); }
public void testCallUninterruptiblyWithTimeout_goodCallableWithNotEnoughTime() throws Exception { try { service.callUninterruptiblyWithTimeout(GOOD_CALLABLE, NOT_ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (TimeoutException expected) { } }
public void testCallUninterruptiblyWithTimeout_goodCallableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); String result = service.callUninterruptiblyWithTimeout(GOOD_CALLABLE, ENOUGH_MS, MILLISECONDS); assertThat(result).isEqualTo(GOOD_CALLABLE_RESULT); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testCallUninterruptiblyWithTimeout_badCallableWithEnoughTime() throws Exception { try { service.callUninterruptiblyWithTimeout(BAD_CALLABLE, ENOUGH_MS, MILLISECONDS); fail("no exception thrown"); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(SampleException.class); } }
public void testCallUninterruptiblyWithTimeout_propagatesReturnValue() throws Exception { String result = timeLimiter.callUninterruptiblyWithTimeout( Callables.returning(RETURN_VALUE), DELAY_MS, TimeUnit.MILLISECONDS); assertThat(result).isEqualTo(RETURN_VALUE); }