@Test public void can_not_submit_tasks_after_shutdown() throws InterruptedException { // given final ExecutorService service = Executors.newSingleThreadExecutor(); service.submit(this::sleep); // when this.executorServiceUtils.gracefulShutdown(service, Duration.ofMillis(1)); final Throwable thrown = catchThrowable(() -> service.submit(this::sleep)); // then assertThat(thrown).isInstanceOf(RejectedExecutionException.class); }
private void assertGetUploadedFileOfCleanedVersion(final int project, final int version) { final Throwable thrown = catchThrowable(() -> this.loader.getUploadedFile(project, version)); assertThat(thrown).isInstanceOf(ProjectManagerException.class); assertThat(thrown).hasMessageStartingWith(String.format("Got numChunks=0 for version %s of " + "project %s - seems like this version has been cleaned up", version, project)); }
@Test public void login_cant_be_empty() { Throwable thrown = catchThrowable(() -> new Credentials("", "bar")); assertThat(thrown) .isInstanceOf(IllegalArgumentException.class) .hasMessage("login must not be null nor empty"); thrown = catchThrowable(() -> new Credentials(null, "bar")); assertThat(thrown) .isInstanceOf(IllegalArgumentException.class) .hasMessage("login must not be null nor empty"); Credentials underTest = new Credentials("foo", "bar"); assertThat(underTest.getLogin()).isEqualTo("foo"); }
@Test public void testLocalExecutorScenario() { this.props.put(ConfigurationKeys.EXECUTOR_PORT, 12345); final Throwable thrown = catchThrowable(() -> createExecutorManager()); assertThat(thrown).isInstanceOf(IllegalArgumentException.class); assertThat(thrown.getMessage()).isEqualTo( "azkaban.use.multiple.executors must be true. Single executor mode is not supported any more."); }
@Test public void createAlertListenerMessage_requiresInternalDistributedMember() { member = mock(DistributedMember.class); Throwable thrown = catchThrowable( () -> alertListenerMessageFactory.createAlertListenerMessage(member, AlertLevel.WARNING, new Date(), "connectionName", "threadName", "formattedMessage", null)); assertThat(thrown).isNotNull().isInstanceOf(IllegalArgumentException.class); } }
@Test public void execute_reachedMaxAttempts() throws Exception { final HelloService.Iface client = helloClient(retryAlways, 2); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); final Throwable thrown = catchThrowable(() -> client.hello("hello")); assertThat(thrown).isInstanceOf(TApplicationException.class); assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR); verify(serviceHandler, times(2)).hello("hello"); }
@Test public void fromJsonWithWhiteSpaceStringThrowsIllegalArgumentException() { // given: white space string String whiteSpaceString = " "; // when: passed to fromJson Throwable thrown = catchThrowable(() -> fromJson(whiteSpaceString)); // then: throws IllegalArgumentException with cause of GfJsonException assertThat(thrown).isInstanceOf(IllegalArgumentException.class) .hasCauseInstanceOf(GfJsonException.class); assertThat(thrown.getCause()).isInstanceOf(GfJsonException.class).hasNoCause(); }
@Test public void testFailedCompletedFuture() throws Exception { final ThriftCompletableFuture<String> future = failedCompletedFuture(new IllegalStateException()); assertThat(catchThrowable(future::get)).hasCauseInstanceOf(IllegalStateException.class); }
@Test public void hasCauseTypeOfNullClassShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseType(new Exception(), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void propagateLastResponseWhenNextRetryIsAfterTimeout() throws Exception { final RetryStrategyWithContent<RpcResponse> strategy = (ctx, response) -> CompletableFuture.completedFuture(Backoff.fixed(10000000)); final HelloService.Iface client = helloClient(strategy, 100); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); final Throwable thrown = catchThrowable(() -> client.hello("hello")); assertThat(thrown).isInstanceOf(TApplicationException.class); assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR); verify(serviceHandler, only()).hello("hello"); }
@Test public void build_wrongScheme() throws Exception { final Throwable thrown = catchThrowable( () -> new ArmeriaRetrofitBuilder().baseUrl("foo://example.com:8080").build()); assertThat(thrown).isInstanceOf(IllegalArgumentException.class) .hasMessage("baseUrl must have an HTTP scheme: foo://example.com:8080"); }
@Test public void build_withNonRootPathNonSlashEnd() throws Exception { final Throwable thrown = catchThrowable( () -> new ArmeriaRetrofitBuilder().baseUrl("http://example.com:8080/a/b/c").build()); assertThat(thrown).isInstanceOf(IllegalArgumentException.class) .hasMessage("baseUrl must end with /: http://example.com:8080/a/b/c"); }
@Test public void loadConfigWhenWebSecurityConfigurersHaveSameOrderThenThrowBeanCreationException() throws Exception { Throwable thrown = catchThrowable(() -> this.spring.register(DuplicateOrderConfig.class).autowire()); assertThat(thrown).isInstanceOf(BeanCreationException.class) .hasMessageContaining("@Order on WebSecurityConfigurers must be unique") .hasMessageContaining(DuplicateOrderConfig.WebConfigurer1.class.getName()) .hasMessageContaining(DuplicateOrderConfig.WebConfigurer2.class.getName()); }
@Test public void overMaxAllocationFails() { setUpSingleSlabManager(); OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class); when(this.ma.getOutOfOffHeapMemoryListener()).thenReturn(ooohml); Throwable thrown = catchThrowable(() -> this.freeListManager.allocate(DEFAULT_SLAB_SIZE - 7)); verify(ooohml).outOfOffHeapMemory((OutOfOffHeapMemoryException) thrown); }
@Test public void hasCauseMessageForNullShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(null, "message")); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void testFailedListenableFuture() throws Exception { assumeUnshadedGuava(); final ThriftListenableFuture<String> future = failedListenableFuture(new IllegalStateException()); assertThat(catchThrowable(future::get)).hasCauseInstanceOf(IllegalStateException.class); }
@Test public void tooLargeRequest_uncompressed() throws Exception { final SimpleRequest request = newLargeRequest(); final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.staticUnaryCall(request)); assertThat(t.getStatus().getCode()).isEqualTo(Code.CANCELLED); checkRequestLogStatus(grpcStatus -> { assertThat(grpcStatus.getCode()).isEqualTo(Code.RESOURCE_EXHAUSTED); }); }
@Test public void hasCauseMessageForNullMessageShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException((String) null), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void tooLargeRequest_compressed() throws Exception { final SimpleRequest request = newLargeRequest(); final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.withCompression("gzip").staticUnaryCall(request)); assertThat(t.getStatus().getCode()).isEqualTo(Code.CANCELLED); checkRequestLogStatus(grpcStatus -> { assertThat(grpcStatus.getCode()).isEqualTo(Code.RESOURCE_EXHAUSTED); }); }
@Test public void fail_throws_exception_if_task_is_pending() { CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12))); CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get(); Throwable thrown = catchThrowable(() -> underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout")); assertThat(thrown) .isInstanceOf(IllegalStateException.class) .hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]"); }