From b81c41134d2b7dcedc7863c83b895437205639f1 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Wed, 31 Jul 2024 09:19:02 +0200 Subject: [PATCH] OZG-6280 change thread configuration --- .../ozgcloud/alfa/AlfaServerApplication.java | 31 ++++++++++++++++--- .../alfa/vorgang/GrpcFormDataMapperTest.java | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/AlfaServerApplication.java b/alfa-service/src/test/java/de/ozgcloud/alfa/AlfaServerApplication.java index 29c015f4bb..a27afe909e 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/AlfaServerApplication.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/AlfaServerApplication.java @@ -28,10 +28,14 @@ import java.util.TimeZone; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.task.ThreadPoolTaskExecutorBuilder; +import org.springframework.boot.task.ThreadPoolTaskExecutorCustomizer; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Primary; +import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.security.concurrent.DelegatingSecurityContextRunnable; @@ -49,14 +53,31 @@ public class AlfaServerApplication { } @Bean - public FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() { + ThreadPoolTaskExecutorCustomizer addSecurityContextCustomizer() { + return customizer -> customizer.setTaskDecorator(DelegatingSecurityContextRunnable::new); + + } + + @Bean + ThreadPoolTaskExecutorCustomizer setThreadName() { + return customizer -> customizer.setThreadNamePrefix("ozgtask-"); + } + + @Bean("taskExecutor") + @Primary + TaskExecutor taskExecutor(ThreadPoolTaskExecutorBuilder builder) { + return builder.build(); + } + +// @Bean + FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() { FilterRegistrationBean<ForwardedHeaderFilter> bean = new FilterRegistrationBean<>(); bean.setFilter(new ForwardedHeaderFilter()); return bean; } - @Bean - public ThreadPoolTaskExecutor threadPoolTaskExecutor() { +// @Bean + ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setThreadNamePrefix("async-"); @@ -65,12 +86,12 @@ public class AlfaServerApplication { } @Bean - public CallScope callScope() { + CallScope callScope() { return new CallScope(); } @Bean - public BeanFactoryPostProcessor beanFactoryPostProcessor(CallScope callScope) { + BeanFactoryPostProcessor beanFactoryPostProcessor(CallScope callScope) { return new CallBeanFactoryPostProcessor(callScope); } } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/GrpcFormDataMapperTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/GrpcFormDataMapperTest.java index cf777c35a3..8aaabf86e9 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/GrpcFormDataMapperTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/vorgang/GrpcFormDataMapperTest.java @@ -84,6 +84,7 @@ class GrpcFormDataMapperTest { assertThat(formData.getField(0).getName()).isEqualTo("key"); assertThat(formData.getField(0).getValue()).isEqualTo("value"); } + } @Nested -- GitLab