Disable scheduled tasks during unit tests
This commit is contained in:
parent
81e8f77232
commit
738abc415c
|
@ -6,7 +6,13 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
|
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 {
|
public class UnregisterScheduledProcessor implements BeanFactoryPostProcessor {
|
||||||
|
|
||||||
private final Environment myEnvironment;
|
private final Environment myEnvironment;
|
||||||
|
@ -22,6 +28,12 @@ public class UnregisterScheduledProcessor implements BeanFactoryPostProcessor {
|
||||||
for (String beanName : beanFactory.getBeanNamesForType(ScheduledAnnotationBeanPostProcessor.class)) {
|
for (String beanName : beanFactory.getBeanNamesForType(ScheduledAnnotationBeanPostProcessor.class)) {
|
||||||
((DefaultListableBeanFactory) beanFactory).removeBeanDefinition(beanName);
|
((DefaultListableBeanFactory) beanFactory).removeBeanDefinition(beanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String beanName : beanFactory.getBeanNamesForType(ExecutorConfigurationSupport.class)) {
|
||||||
|
ExecutorConfigurationSupport executorConfigSupport = ((DefaultListableBeanFactory) beanFactory).getBean(beanName, ExecutorConfigurationSupport.class);
|
||||||
|
executorConfigSupport.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue