Search in sources :

Example 1 with TaskDecorator

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);
}
Also used : TaskDecorator(org.springframework.core.task.TaskDecorator) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 2 with TaskDecorator

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);
}
Also used : TaskDecorator(org.springframework.core.task.TaskDecorator) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 3 with 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));
    });
}
Also used : TaskDecorator(org.springframework.core.task.TaskDecorator) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutorBuilder(org.springframework.boot.task.TaskExecutorBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with TaskDecorator

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());
}
Also used : TaskDecorator(org.springframework.core.task.TaskDecorator) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

TaskDecorator (org.springframework.core.task.TaskDecorator)4 Test (org.junit.jupiter.api.Test)3 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 TaskExecutorBuilder (org.springframework.boot.task.TaskExecutorBuilder)1