Search in sources :

Example 1 with LazyInitializationBeanFactoryPostProcessor

use of org.springframework.boot.LazyInitializationBeanFactoryPostProcessor in project spring-boot by spring-projects.

the class JmxEndpointIntegrationTests method jmxEndpointsAreExposedWhenLazyInitializationIsEnabled.

@Test
void jmxEndpointsAreExposedWhenLazyInitializationIsEnabled() {
    this.contextRunner.withBean(LazyInitializationBeanFactoryPostProcessor.class, LazyInitializationBeanFactoryPostProcessor::new).run((context) -> {
        MBeanServer mBeanServer = context.getBean(MBeanServer.class);
        checkEndpointMBeans(mBeanServer, new String[] { "beans", "conditions", "configprops", "env", "health", "info", "mappings", "threaddump", "httptrace" }, new String[] { "shutdown" });
    });
}
Also used : LazyInitializationBeanFactoryPostProcessor(org.springframework.boot.LazyInitializationBeanFactoryPostProcessor) MBeanServer(javax.management.MBeanServer) Test(org.junit.jupiter.api.Test)

Example 2 with LazyInitializationBeanFactoryPostProcessor

use of org.springframework.boot.LazyInitializationBeanFactoryPostProcessor in project spring-boot by spring-projects.

the class TaskSchedulingAutoConfigurationTests method enableSchedulingWithLazyInitializationInvokeScheduledMethods.

@Test
void enableSchedulingWithLazyInitializationInvokeScheduledMethods() {
    List<String> threadNames = new ArrayList<>();
    new ApplicationContextRunner().withInitializer((context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor())).withPropertyValues("spring.task.scheduling.thread-name-prefix=scheduling-test-").withBean(LazyTestBean.class, () -> new LazyTestBean(threadNames)).withUserConfiguration(SchedulingConfiguration.class).withConfiguration(AutoConfigurations.of(TaskSchedulingAutoConfiguration.class)).run((context) -> {
        // No lazy lookup.
        Awaitility.waitAtMost(Duration.ofSeconds(3)).until(() -> !threadNames.isEmpty());
        assertThat(threadNames).allMatch((name) -> name.contains("scheduling-test-"));
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskSchedulerCustomizer(org.springframework.boot.task.TaskSchedulerCustomizer) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) SchedulingConfigurer(org.springframework.scheduling.annotation.SchedulingConfigurer) LazyInitializationBeanFactoryPostProcessor(org.springframework.boot.LazyInitializationBeanFactoryPostProcessor) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskExecutor(org.springframework.core.task.TaskExecutor) ScheduledTaskRegistrar(org.springframework.scheduling.config.ScheduledTaskRegistrar) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TaskScheduler(org.springframework.scheduling.TaskScheduler) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Bean(org.springframework.context.annotation.Bean) Awaitility(org.awaitility.Awaitility) LazyInitializationBeanFactoryPostProcessor(org.springframework.boot.LazyInitializationBeanFactoryPostProcessor) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 LazyInitializationBeanFactoryPostProcessor (org.springframework.boot.LazyInitializationBeanFactoryPostProcessor)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 MBeanServer (javax.management.MBeanServer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Awaitility (org.awaitility.Awaitility)1 AutoConfigurations (org.springframework.boot.autoconfigure.AutoConfigurations)1 TaskSchedulerCustomizer (org.springframework.boot.task.TaskSchedulerCustomizer)1 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1