Search in sources :

Example 46 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.

the class TaskExecutionAutoConfigurationTests method taskExecutorBuilderShouldApplyCustomizer.

@Test
void taskExecutorBuilderShouldApplyCustomizer() {
    this.contextRunner.withUserConfiguration(TaskExecutorCustomizerConfig.class).run((context) -> {
        TaskExecutorCustomizer customizer = context.getBean(TaskExecutorCustomizer.class);
        ThreadPoolTaskExecutor executor = context.getBean(TaskExecutorBuilder.class).build();
        then(customizer).should().customize(executor);
    });
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutorBuilder(org.springframework.boot.task.TaskExecutorBuilder) TaskExecutorCustomizer(org.springframework.boot.task.TaskExecutorCustomizer) Test(org.junit.jupiter.api.Test)

Example 47 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.

the class TaskExecutorBuilderTests method threadNamePrefixShouldApply.

@Test
void threadNamePrefixShouldApply() {
    ThreadPoolTaskExecutor executor = this.builder.threadNamePrefix("test-").build();
    assertThat(executor.getThreadNamePrefix()).isEqualTo("test-");
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 48 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor 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 49 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.

the class TaskExecutorBuilderTests method additionalCustomizersShouldAddToExisting.

@Test
void additionalCustomizersShouldAddToExisting() {
    TaskExecutorCustomizer customizer1 = mock(TaskExecutorCustomizer.class);
    TaskExecutorCustomizer customizer2 = mock(TaskExecutorCustomizer.class);
    ThreadPoolTaskExecutor executor = this.builder.customizers(customizer1).additionalCustomizers(customizer2).build();
    then(customizer1).should().customize(executor);
    then(customizer2).should().customize(executor);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 50 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.

the class TaskExecutorBuilderTests method awaitTerminationPeriodShouldApplyWithMillisecondPrecision.

@Test
void awaitTerminationPeriodShouldApplyWithMillisecondPrecision() {
    Duration period = Duration.ofMillis(50);
    ThreadPoolTaskExecutor executor = this.builder.awaitTerminationPeriod(period).build();
    assertThat(executor).hasFieldOrPropertyWithValue("awaitTerminationMillis", period.toMillis());
}
Also used : Duration(java.time.Duration) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)152 Bean (org.springframework.context.annotation.Bean)72 ExceptionHandlingAsyncTaskExecutor (io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor)19 Test (org.junit.jupiter.api.Test)19 BigInteger (java.math.BigInteger)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 RateLimiter (com.google.common.util.concurrent.RateLimiter)14 Test (org.junit.Test)14 Random (java.util.Random)12 ApplicationContext (org.springframework.context.ApplicationContext)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Service (org.fisco.bcos.channel.client.Service)9 Credentials (org.fisco.bcos.web3j.crypto.Credentials)9 Web3j (org.fisco.bcos.web3j.protocol.Web3j)9 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)9 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 MDCCleanerTaskDecorator (com.sequenceiq.cloudbreak.concurrent.MDCCleanerTaskDecorator)4