From 738abc415cb17ea02bffebc8f69973fed8e1a896 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sat, 14 Jul 2018 13:24:51 -0400 Subject: [PATCH] Disable scheduled tasks during unit tests --- .../jpa/config/UnregisterScheduledProcessor.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/UnregisterScheduledProcessor.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/UnregisterScheduledProcessor.java index c821af78e40..cf5943b37d3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/UnregisterScheduledProcessor.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/UnregisterScheduledProcessor.java @@ -6,7 +6,13 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.env.Environment; import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor; +import org.springframework.scheduling.concurrent.ExecutorConfigurationSupport; +/** + * This bean postprocessor disables all scheduled tasks. It is intended + * only to be used in unit tests in circumstances where scheduled + * tasks cause issues. + */ public class UnregisterScheduledProcessor implements BeanFactoryPostProcessor { private final Environment myEnvironment; @@ -22,6 +28,12 @@ public class UnregisterScheduledProcessor implements BeanFactoryPostProcessor { for (String beanName : beanFactory.getBeanNamesForType(ScheduledAnnotationBeanPostProcessor.class)) { ((DefaultListableBeanFactory) beanFactory).removeBeanDefinition(beanName); } + + for (String beanName : beanFactory.getBeanNamesForType(ExecutorConfigurationSupport.class)) { + ExecutorConfigurationSupport executorConfigSupport = ((DefaultListableBeanFactory) beanFactory).getBean(beanName, ExecutorConfigurationSupport.class); + executorConfigSupport.shutdown(); + } } + } }