use of org.springframework.core.task.TaskDecorator in project spring-boot by spring-projects.
the class TaskExecutorBuilderTests method customizersShouldBeAppliedLast.
@Test
void customizersShouldBeAppliedLast() {
TaskDecorator taskDecorator = mock(TaskDecorator.class);
ThreadPoolTaskExecutor executor = spy(new ThreadPoolTaskExecutor());
this.builder.queueCapacity(10).corePoolSize(4).maxPoolSize(8).allowCoreThreadTimeOut(true).keepAlive(Duration.ofMinutes(1)).awaitTermination(true).awaitTerminationPeriod(Duration.ofSeconds(30)).threadNamePrefix("test-").taskDecorator(taskDecorator).additionalCustomizers((taskExecutor) -> {
then(taskExecutor).should().setQueueCapacity(10);
then(taskExecutor).should().setCorePoolSize(4);
then(taskExecutor).should().setMaxPoolSize(8);
then(taskExecutor).should().setAllowCoreThreadTimeOut(true);
then(taskExecutor).should().setKeepAliveSeconds(60);
then(taskExecutor).should().setWaitForTasksToCompleteOnShutdown(true);
then(taskExecutor).should().setAwaitTerminationSeconds(30);
then(taskExecutor).should().setThreadNamePrefix("test-");
then(taskExecutor).should().setTaskDecorator(taskDecorator);
});
this.builder.configure(executor);
}
use of org.springframework.core.task.TaskDecorator in project spring-boot by spring-projects.
the class TaskExecutorBuilderTests method taskDecoratorShouldApply.
@Test
void taskDecoratorShouldApply() {
TaskDecorator taskDecorator = mock(TaskDecorator.class);
ThreadPoolTaskExecutor executor = this.builder.taskDecorator(taskDecorator).build();
assertThat(executor).extracting("taskDecorator").isSameAs(taskDecorator);
}
use of org.springframework.core.task.TaskDecorator in project spring-boot by spring-projects.
the class TaskExecutionAutoConfigurationTests method taskExecutorBuilderShouldUseTaskDecorator.
@Test
void taskExecutorBuilderShouldUseTaskDecorator() {
this.contextRunner.withUserConfiguration(TaskDecoratorConfig.class).run((context) -> {
assertThat(context).hasSingleBean(TaskExecutorBuilder.class);
ThreadPoolTaskExecutor executor = context.getBean(TaskExecutorBuilder.class).build();
assertThat(executor).extracting("taskDecorator").isSameAs(context.getBean(TaskDecorator.class));
});
}
use of org.springframework.core.task.TaskDecorator in project pinpoint by naver.
the class ChainedTaskDecoratorTest method chainedDecoratorsShouldBeCalled.
@Test
public void chainedDecoratorsShouldBeCalled() throws InterruptedException {
// Given
final int testCount = 100;
final CountDownLatch completeLatch = new CountDownLatch(testCount);
final CountingTaskDecorator decorator1 = new CountingTaskDecorator();
final CountingTaskDecorator decorator2 = new CountingTaskDecorator();
final CountingTaskDecorator decorator3 = new CountingTaskDecorator();
final List<TaskDecorator> decorators = Arrays.asList(decorator1, decorator2, decorator3);
final ChainedTaskDecorator chainedDecorator = new ChainedTaskDecorator(decorators);
executor.setTaskDecorator(chainedDecorator);
// When
for (int i = 0; i < testCount; i++) {
executor.execute(new TestWorker(completeLatch));
}
completeLatch.await(5L, TimeUnit.SECONDS);
// Then
Assert.assertEquals(testCount, decorator1.getCount());
Assert.assertEquals(testCount, decorator2.getCount());
Assert.assertEquals(testCount, decorator3.getCount());
}
Aggregations