public void testTrustedGetFailure_Failed() { SettableFuture<String> future = SettableFuture.create(); Throwable failure = new Throwable(); future.setException(failure); assertThat(future.tryInternalFastPathGetFailure()).isEqualTo(failure); }
public void testGetCheckedUntimed_ExecutionExceptionChecked() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
public void testGetCheckedTimed_ExecutionExceptionChecked() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
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 testGetCheckedUntimed_ExecutionExceptionUnchecked() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_UNCHECKED_EXCEPTION, TwoArgConstructorException.class); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(UNCHECKED_EXCEPTION); } }
public void testGetCheckedUntimed_ExecutionExceptionOtherThrowable() { try { getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE); } }
public void testGetCheckedTimed_ExecutionExceptionUnchecked() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_UNCHECKED_EXCEPTION, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(UNCHECKED_EXCEPTION); } }
public void testGetCheckedTimed_ExecutionExceptionError() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_ERROR, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isEqualTo(ERROR); } }
public void testGetCheckedUntimed_ExecutionExceptionError() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_ERROR, TwoArgConstructorException.class); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isEqualTo(ERROR); } }
public void testGetCheckedTimed_ExecutionExceptionOtherThrowable() { try { getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE); } }
public void testCallWithTimeout_wrapsCheckedException() throws Exception { Exception exception = new SampleCheckedException(); try { timeLimiter.callWithTimeout(callableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected ExecutionException"); } catch (ExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }
public void testCallWithTimeout_wrapsUncheckedException() throws Exception { Exception exception = new RuntimeException("test"); try { timeLimiter.callWithTimeout(callableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS); fail("Expected UncheckedExecutionException"); } catch (UncheckedExecutionException e) { assertThat(e.getCause()).isEqualTo(exception); } }
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 testFailed() { Exception failureCause = new Exception(); try { getDone(immediateFailedFuture(failureCause)); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(failureCause); } }
public void testGetCheckedUntimed_exceptionClassUsedInitCause() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithoutThrowableConstructor.class); fail(); } catch (ExceptionWithoutThrowableConstructor expected) { assertThat(expected).hasMessageThat().contains("mymessage"); assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
public void testFailingServiceStartAndWait() throws Exception { StartFailingService service = new StartFailingService(); RecordingListener listener = RecordingListener.record(service); try { service.startAsync().awaitRunning(); fail(); } catch (IllegalStateException e) { assertEquals(EXCEPTION, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(EXCEPTION); } assertEquals(ImmutableList.of(State.STARTING, State.FAILED), listener.getStateHistory()); }
public void testThrowingServiceStartAndWait() throws Exception { StartThrowingService service = new StartThrowingService(); RecordingListener listener = RecordingListener.record(service); try { service.startAsync().awaitRunning(); fail(); } catch (IllegalStateException e) { assertEquals(service.exception, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(service.exception); } assertEquals(ImmutableList.of(State.STARTING, State.FAILED), listener.getStateHistory()); }
public void testThrowingServiceStopAndWait_runThrowing() throws Exception { RunThrowingService service = new RunThrowingService(); RecordingListener listener = RecordingListener.record(service); service.startAsync(); try { service.awaitTerminated(); fail(); } catch (IllegalStateException e) { assertEquals(service.exception, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(service.exception); } assertEquals( ImmutableList.of(State.STARTING, State.RUNNING, State.FAILED), listener.getStateHistory()); }
public void testFailingServiceStopAndWait_runFailing() throws Exception { RunFailingService service = new RunFailingService(); RecordingListener listener = RecordingListener.record(service); service.startAsync(); try { service.awaitRunning(); fail(); } catch (IllegalStateException e) { assertEquals(EXCEPTION, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(EXCEPTION); } assertEquals( ImmutableList.of(State.STARTING, State.RUNNING, State.FAILED), listener.getStateHistory()); }
public void testServiceThrowOnRun() throws Exception { ThrowOnRunService service = new ThrowOnRunService(); service.startAsync(); try { service.awaitTerminated(); fail(); } catch (IllegalStateException expected) { executionThread.join(); assertThat(expected).hasCauseThat().isEqualTo(service.failureCause()); assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo("kaboom!"); } assertTrue(service.shutDownCalled); assertEquals(Service.State.FAILED, service.state()); }