Update Task to BOOT 2.1.M1
Migrating to use ApplicationContextRunner or ImportAutoConfiguration with SpringApp.run, instead of SpringApplicationBuilder, because builder does not handle AutoConfiguration properly SimpleTaskAutoConfiguration now has an annotation AutoConfigureBefore the BatchTaskAutoConfig so that it is processed prior. THis is so that that BatchTaskAutoConfig can create the appropriate beans SimpleTaskAutoConfiguration has new annotations so that it is AutoConfigured after BindingServiceConfiguration and after SimpleTaskAutoConfiguration. This is so that it does not attempt to start emitting messages before stream is ready and it can create the appropriate beans after SimpleTaskAutoConfiguration has run. Renamed SimpleTaskConfiguration to SimpleTaskAutoConfiguration. Task version updated to 2.1.0 Added missing headers Updated documentation. Deprecated EnableTask Added ability to disable Task autoconfiguration. Removed @EnableTask from tests Resolves #439 Resolves #440 Resolves #448 Resolves #466
This commit is contained in:
committed by
Michael Minella
parent
d2c90c5256
commit
d2bc2530cc
@@ -1,6 +1,5 @@
|
||||
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,11 +53,15 @@ import org.springframework.context.annotation.Import;
|
||||
* </ul>
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*
|
||||
* @deprecated The EnableTask annotation is no longer be required to initialize
|
||||
* Spring Cloud Task. This will be handled by AutoConfiguration provided by Spring Cloud Task.
|
||||
*/
|
||||
@Deprecated
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ SimpleTaskConfiguration.class, SingleTaskConfiguration.class })
|
||||
@Import({ })
|
||||
public @interface EnableTask {
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.task.listener.TaskLifecycleListener;
|
||||
import org.springframework.cloud.task.listener.annotation.TaskListenerExecutorFactoryBean;
|
||||
import org.springframework.cloud.task.listener.TaskListenerExecutorObjectFactory;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskNameResolver;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
@@ -55,9 +57,10 @@ import org.springframework.util.CollectionUtils;
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@EnableConfigurationProperties(TaskProperties.class)
|
||||
public class SimpleTaskConfiguration {
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.autoconfiguration", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class SimpleTaskAutoConfiguration {
|
||||
|
||||
protected static final Log logger = LogFactory.getLog(SimpleTaskConfiguration.class);
|
||||
protected static final Log logger = LogFactory.getLog(SimpleTaskAutoConfiguration.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<DataSource> dataSources;
|
||||
@@ -77,8 +80,6 @@ public class SimpleTaskConfiguration {
|
||||
|
||||
private TaskLifecycleListener taskLifecycleListener;
|
||||
|
||||
private TaskListenerExecutorFactoryBean taskListenerExecutorFactoryBean;
|
||||
|
||||
private PlatformTransactionManager platformTransactionManager;
|
||||
|
||||
private TaskExplorer taskExplorer;
|
||||
@@ -94,12 +95,7 @@ public class SimpleTaskConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorFactoryBean taskListenerExecutor()
|
||||
throws Exception {
|
||||
return this.taskListenerExecutorFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
return this.platformTransactionManager;
|
||||
}
|
||||
@@ -140,12 +136,11 @@ public class SimpleTaskConfiguration {
|
||||
taskConfigurer.getClass().getName()));
|
||||
|
||||
this.taskRepository = taskConfigurer.getTaskRepository();
|
||||
this.taskListenerExecutorFactoryBean = new TaskListenerExecutorFactoryBean(context);
|
||||
this.platformTransactionManager = taskConfigurer.getTransactionManager();
|
||||
this.taskExplorer = taskConfigurer.getTaskExplorer();
|
||||
|
||||
this.taskLifecycleListener = new TaskLifecycleListener(this.taskRepository, taskNameResolver(),
|
||||
this.applicationArguments, taskExplorer, taskProperties);
|
||||
this.applicationArguments, taskExplorer, taskProperties, new TaskListenerExecutorObjectFactory(context));
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,6 +46,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -74,7 +75,9 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<TaskExecutionListener> taskExecutionListeners;
|
||||
private Collection<TaskExecutionListener> taskExecutionListenersFromContext;
|
||||
|
||||
private List<TaskExecutionListener> taskExecutionListeners;
|
||||
|
||||
private final static Log logger = LogFactory.getLog(TaskLifecycleListener.class);
|
||||
|
||||
@@ -82,6 +85,8 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
private final TaskExplorer taskExplorer;
|
||||
|
||||
private final TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory;
|
||||
|
||||
private TaskExecution taskExecution;
|
||||
|
||||
private TaskProperties taskProperties;
|
||||
@@ -108,17 +113,20 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
public TaskLifecycleListener(TaskRepository taskRepository,
|
||||
TaskNameResolver taskNameResolver,
|
||||
ApplicationArguments applicationArguments, TaskExplorer taskExplorer,
|
||||
TaskProperties taskProperties) {
|
||||
TaskProperties taskProperties,
|
||||
TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory) {
|
||||
Assert.notNull(taskRepository, "A taskRepository is required");
|
||||
Assert.notNull(taskNameResolver, "A taskNameResolver is required");
|
||||
Assert.notNull(taskExplorer, "A taskExplorer is required");
|
||||
Assert.notNull(taskProperties, "TaskProperties is required");
|
||||
Assert.notNull(taskListenerExecutorObjectFactory, "A TaskListenerExecutorObjectFactory is required");
|
||||
|
||||
this.taskRepository = taskRepository;
|
||||
this.taskNameResolver = taskNameResolver;
|
||||
this.applicationArguments = applicationArguments;
|
||||
this.taskExplorer = taskExplorer;
|
||||
this.taskProperties = taskProperties;
|
||||
this.taskListenerExecutorObjectFactory = taskListenerExecutorObjectFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,6 +231,13 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
private void doTaskStart() {
|
||||
|
||||
if(!this.started) {
|
||||
this.taskExecutionListeners = new ArrayList<>();
|
||||
this.taskListenerExecutorObjectFactory.getObject();
|
||||
if(!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
|
||||
this.taskExecutionListeners.addAll(this.taskExecutionListenersFromContext);
|
||||
}
|
||||
this.taskExecutionListeners.add(this.taskListenerExecutorObjectFactory.getObject());
|
||||
|
||||
List<String> args = new ArrayList<>(0);
|
||||
|
||||
if(this.applicationArguments != null) {
|
||||
@@ -258,11 +273,11 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
private TaskExecution invokeOnTaskStartup(TaskExecution taskExecution){
|
||||
TaskExecution listenerTaskExecution = getTaskExecutionCopy(taskExecution);
|
||||
if (this.taskExecutionListeners != null) {
|
||||
List<TaskExecutionListener> startupListenerList = new ArrayList<>(this.taskExecutionListeners);
|
||||
if (startupListenerList != null) {
|
||||
try {
|
||||
List<TaskExecutionListener> starterList = new ArrayList<>(taskExecutionListeners);
|
||||
Collections.reverse(starterList);
|
||||
for (TaskExecutionListener taskExecutionListener : starterList) {
|
||||
Collections.reverse(startupListenerList);
|
||||
for (TaskExecutionListener taskExecutionListener : startupListenerList) {
|
||||
taskExecutionListener.onTaskStartup(listenerTaskExecution);
|
||||
}
|
||||
}
|
||||
@@ -300,7 +315,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
private TaskExecution invokeOnTaskError(TaskExecution taskExecution, Throwable throwable){
|
||||
TaskExecution listenerTaskExecution = getTaskExecutionCopy(taskExecution);
|
||||
if (taskExecutionListeners != null) {
|
||||
if (this.taskExecutionListeners != null) {
|
||||
try {
|
||||
for (TaskExecutionListener taskExecutionListener : this.taskExecutionListeners) {
|
||||
taskExecutionListener.onTaskFailed(listenerTaskExecution, throwable);
|
||||
@@ -346,7 +361,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
@Override
|
||||
public void stop(Runnable callback) {
|
||||
Assert.notNull(callback, "A callback is required");
|
||||
|
||||
stop();
|
||||
callback.run();
|
||||
}
|
||||
|
||||
@@ -358,6 +373,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.doTaskEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -374,4 +390,5 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
public void destroy() throws Exception {
|
||||
this.doTaskEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener.annotation;
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -30,18 +30,27 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
|
||||
import org.springframework.aop.scope.ScopedObject;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.cloud.task.listener.TaskExecutionListener;
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
import org.springframework.cloud.task.listener.annotation.BeforeTask;
|
||||
import org.springframework.cloud.task.listener.annotation.FailedTask;
|
||||
import org.springframework.cloud.task.listener.annotation.TaskListenerExecutor;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
||||
/**
|
||||
* Initializes TaskListenerExecutor for a task.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class TaskListenerExecutorFactoryBean implements FactoryBean<TaskExecutionListener> {
|
||||
public class TaskListenerExecutorObjectFactory implements ObjectFactory<TaskExecutionListener> {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(TaskListenerExecutor.class);
|
||||
|
||||
@@ -56,29 +65,19 @@ public class TaskListenerExecutorFactoryBean implements FactoryBean<TaskExecutio
|
||||
|
||||
private Map<Method, Object> failedTaskInstances;
|
||||
|
||||
public TaskListenerExecutorFactoryBean(ConfigurableApplicationContext context){
|
||||
public TaskListenerExecutorObjectFactory(ConfigurableApplicationContext context){
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskListenerExecutor getObject() throws Exception {
|
||||
beforeTaskInstances = new HashMap<>();
|
||||
afterTaskInstances = new HashMap<>();
|
||||
failedTaskInstances = new HashMap<>();
|
||||
public TaskListenerExecutor getObject() {
|
||||
this.beforeTaskInstances = new HashMap<>();
|
||||
this.afterTaskInstances = new HashMap<>();
|
||||
this.failedTaskInstances = new HashMap<>();
|
||||
initializeExecutor();
|
||||
return new TaskListenerExecutor(beforeTaskInstances, afterTaskInstances, failedTaskInstances);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return TaskListenerExecutor.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initializeExecutor( ) {
|
||||
ConfigurableListableBeanFactory factory = context.getBeanFactory();
|
||||
for( String beanName : context.getBeanDefinitionNames()) {
|
||||
@@ -1 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.task.configuration.ResourceLoadingAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.task.configuration.SingleTaskConfiguration,\
|
||||
org.springframework.cloud.task.configuration.ResourceLoadingAutoConfiguration,\
|
||||
org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration\
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,17 +17,13 @@
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleInstanceTaskListener;
|
||||
import org.springframework.cloud.task.configuration.TaskProperties;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -39,24 +35,23 @@ import static org.junit.Assert.assertNotNull;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {TaskProperties.class, SimpleTaskConfiguration.class, SingleTaskConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"spring.cloud.task.single-instance-enabled=true",
|
||||
})
|
||||
public class SimpleSingleTaskAutoConfigurationTests {
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = this.context.getBean(SingleInstanceTaskListener.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class);
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class); });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,17 +17,14 @@
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleInstanceTaskListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -39,25 +36,24 @@ import static org.junit.Assert.assertNotNull;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {SimpleTaskConfiguration.class,
|
||||
SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class})
|
||||
@TestPropertySource(properties = {
|
||||
"spring.cloud.task.single-instance-enabled=true",
|
||||
})
|
||||
public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = this.context.getBean(SingleInstanceTaskListener.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
assertNotNull("singleInstanceTaskListener should not be null", singleInstanceTaskListener);
|
||||
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class);
|
||||
assertEquals(singleInstanceTaskListener.getClass(), SingleInstanceTaskListener.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Verifies that the beans created by the SimpleTaskAutoConfiguration.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository() throws Exception {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
TaskRepository taskRepository = context.getBean(TaskRepository.class);
|
||||
assertThat(taskRepository).isNotNull();
|
||||
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskRepository);
|
||||
assertThat(targetClass).isEqualTo(SimpleTaskRepository.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() throws Exception {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
context.getBean(TaskRepository.class);
|
||||
});
|
||||
};
|
||||
verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying " +
|
||||
"bean of type 'org.springframework.cloud.task.repository.TaskRepository' " +
|
||||
"available", executable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() throws Exception {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1l);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() throws Exception {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, "Failed to start " +
|
||||
"bean 'taskLifecycleListener'; nested exception is " +
|
||||
"org.springframework.dao.DataAccessResourceFailureException: " +
|
||||
"Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLException: " +
|
||||
"Syntax error in SQL statement \"SELECT FOOBARLESSSEQ.NEXTVAL FROM[*] DUAL \"; " +
|
||||
"expected \"identifier\"; SQL statement:\n" +
|
||||
"select foobarlessSEQ.nextval from dual [42001-197]", applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConfigurers() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleConfigurers.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class, "Error creating bean " +
|
||||
"with name 'simpleTaskAutoConfiguration': Invocation of init " +
|
||||
"method failed; nested exception is java.lang.IllegalStateException:" +
|
||||
" Expected one TaskConfigurer but found 2", applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDataSources() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleDataSources.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class, "Error creating bean " +
|
||||
"with name 'simpleTaskAutoConfiguration': Invocation of init method " +
|
||||
"failed; nested exception is java.lang.IllegalStateException: To use " +
|
||||
"the default TaskConfigurer the context must contain no more than " +
|
||||
"one DataSource, found 2", applicationContextRunner);
|
||||
|
||||
}
|
||||
|
||||
public void verifyExceptionThrownDefaultExecutable(Class classToCheck, String message,
|
||||
ApplicationContextRunner applicationContextRunner) {
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
Throwable expectedException = context.getStartupFailure();
|
||||
assertThat(expectedException).isNotNull();
|
||||
throw expectedException;
|
||||
});
|
||||
};
|
||||
verifyExceptionThrown(classToCheck, message, executable);
|
||||
}
|
||||
|
||||
public void verifyExceptionThrown(Class classToCheck, String message, Executable executable) {
|
||||
Throwable exception = assertThrows(classToCheck, executable);
|
||||
assertThat(exception.getMessage()).isEqualTo(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the verifyEnvironment method skips DataSource Proxy Beans when determining
|
||||
* the number of available dataSources.
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(DataSourceProxyConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
assertThat(context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
|
||||
SimpleTaskAutoConfiguration taskConfiguration = context.getBean(SimpleTaskAutoConfiguration.class);
|
||||
assertThat(taskConfiguration).isNotNull();
|
||||
assertThat(taskConfiguration.taskExplorer()).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class MultipleConfigurers {
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer1() {
|
||||
return new DefaultTaskConfigurer((DataSource) null);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer2() {
|
||||
return new DefaultTaskConfigurer((DataSource) null);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class MultipleDataSources {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource2() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class DataSourceProxyConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Bean
|
||||
public BeanDefinitionHolder proxyDataSource() {
|
||||
GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
|
||||
proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(proxyBeanDefinition, "dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource, (BeanDefinitionRegistry) this.context.getBeanFactory(),
|
||||
true);
|
||||
return myDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.cloud.task.configuration.TaskProperties;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Verifies that the beans created by the SimpleTaskConfiguration.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class SimpleTaskConfigurationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if(this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(SimpleTaskConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
|
||||
TaskRepository taskRepository = this.context.getBean(TaskRepository.class);
|
||||
|
||||
assertThat(taskRepository).isNotNull();
|
||||
|
||||
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskRepository);
|
||||
|
||||
assertThat(targetClass).isEqualTo(SimpleTaskRepository.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(EmbeddedDataSourceConfiguration.class, SimpleTaskConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
|
||||
TaskExplorer taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() throws Exception {
|
||||
Properties properties = new Properties();
|
||||
|
||||
properties.put("spring.cloud.task.tablePrefix", "foobarless");
|
||||
PropertiesPropertySource propertiesSource = new PropertiesPropertySource("test", properties);
|
||||
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.getEnvironment().getPropertySources().addLast(propertiesSource);
|
||||
((AnnotationConfigApplicationContext)context).register(SimpleTaskConfiguration.class);
|
||||
((AnnotationConfigApplicationContext)context).register(PropertyPlaceholderAutoConfiguration.class);
|
||||
((AnnotationConfigApplicationContext)context).register(EmbeddedDataSourceConfiguration.class);
|
||||
boolean wasExceptionThrown = false;
|
||||
try {
|
||||
this.context.refresh();
|
||||
}
|
||||
catch (ApplicationContextException ex) {
|
||||
wasExceptionThrown = true;
|
||||
}
|
||||
assertThat( wasExceptionThrown).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleConfigurers() {
|
||||
this.context = new AnnotationConfigApplicationContext(MultipleConfigurers.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleDataSources() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
MultipleDataSources.class, SimpleTaskConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the verifyEnvironment method skips DataSource Proxy Beans
|
||||
* when determining the number of available dataSources.
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
this.context = new AnnotationConfigApplicationContext(EmbeddedDataSourceConfiguration.class, TaskProperties.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, DataSourceProxyConfiguration.class
|
||||
);
|
||||
|
||||
assertThat(this.context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
|
||||
SimpleTaskConfiguration taskConfiguration = this.context.getBean(SimpleTaskConfiguration.class);
|
||||
assertThat(taskConfiguration).isNotNull();
|
||||
assertThat(taskConfiguration.taskExplorer()).isNotNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
public static class MultipleConfigurers {
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer1() {
|
||||
return new DefaultTaskConfigurer((DataSource) null);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskConfigurer taskConfigurer2() {
|
||||
return new DefaultTaskConfigurer((DataSource) null);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class MultipleDataSources {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource2() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class DataSourceProxyConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Bean
|
||||
public SimpleTaskConfiguration simpleTaskConfiguration() {
|
||||
GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
|
||||
proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(proxyBeanDefinition,"dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource, (BeanDefinitionRegistry) this.context.getBeanFactory(), true);
|
||||
return new SimpleTaskConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -5,14 +21,15 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -48,11 +65,31 @@ public class TaskCoreTests {
|
||||
|
||||
@Test
|
||||
public void successfulTaskTest() {
|
||||
applicationContext = new SpringApplicationBuilder().sources(new Class[]{TaskConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class}).build().run(new String[]{
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false"});
|
||||
this.applicationContext = SpringApplication.run( TaskConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
output.contains(CREATE_TASK_MESSAGE));
|
||||
assertTrue("Test results do not show success message: " + output,
|
||||
output.contains(UPDATE_TASK_MESSAGE));
|
||||
assertTrue("Test results have incorrect exit code: " + output,
|
||||
output.contains(SUCCESS_EXIT_CODE_MESSAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to verify that deprecated annotation does not affect task execution.
|
||||
*/
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfigurationWithAnotation.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
@@ -67,11 +104,11 @@ public class TaskCoreTests {
|
||||
public void exceptionTaskTest() {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
applicationContext = new SpringApplicationBuilder().sources(TaskExceptionConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class).build().run(new String[]{
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false"});
|
||||
this.applicationContext = SpringApplication.run( TaskExceptionConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
@@ -95,8 +132,8 @@ public class TaskCoreTests {
|
||||
public void invalidExecutionId() {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
applicationContext = new SpringApplicationBuilder().sources(TaskExceptionConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class).build().run(new String[]{
|
||||
applicationContext = this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, new String[]{
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
@@ -112,8 +149,7 @@ public class TaskCoreTests {
|
||||
output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class})
|
||||
public static class TaskConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -126,8 +162,21 @@ public class TaskCoreTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class})
|
||||
public static class TaskConfigurationWithAnotation {
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner() {
|
||||
return new CommandLineRunner() {
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ImportAutoConfiguration({SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class})
|
||||
public static class TaskExceptionConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {SimpleTaskConfiguration.class,
|
||||
@ContextConfiguration(classes = {SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class})
|
||||
public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -43,7 +44,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = {SimpleTaskConfiguration.class,
|
||||
@ContextConfiguration(classes = {SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
DefaultTaskConfigurer.class})
|
||||
public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -7,10 +23,6 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.TaskExecutionDaoFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@@ -21,7 +33,7 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
TaskPropertiesTests.CloseContextEnabledTest.class,
|
||||
TaskPropertiesTests.CloseContextEnabledTest.class
|
||||
|
||||
})
|
||||
|
||||
@@ -36,21 +48,15 @@ public class TaskPropertiesTests {
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes={TaskPropertiesTests.Config.class}, properties = { "spring.cloud.task.closecontextEnabled=false" })
|
||||
@SpringBootTest(classes={TaskPropertiesTests.Config.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class},
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false" })
|
||||
@DirtiesContext
|
||||
public static class CloseContextEnabledTest extends TaskPropertiesTests {}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
public static class Config {
|
||||
@Bean
|
||||
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean() {
|
||||
return new TaskExecutionDaoFactoryBean();
|
||||
}
|
||||
@Bean
|
||||
public TaskRepository taskRepository(TaskExecutionDaoFactoryBean tefb) {
|
||||
return new SimpleTaskRepository(tefb);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,11 +29,9 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
import org.springframework.cloud.task.listener.annotation.BeforeTask;
|
||||
import org.springframework.cloud.task.listener.annotation.FailedTask;
|
||||
import org.springframework.cloud.task.listener.annotation.TaskListenerExecutorFactoryBean;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.util.TestDefaultConfiguration;
|
||||
import org.springframework.cloud.task.util.TestListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -290,12 +288,6 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorFactoryBean taskListenerExecutor(ConfigurableApplicationContext context) throws Exception
|
||||
{
|
||||
return new TaskListenerExecutorFactoryBean(context);
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener extends TestListener {
|
||||
|
||||
@BeforeTask
|
||||
@@ -331,12 +323,6 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorFactoryBean taskListenerExecutor(ConfigurableApplicationContext context) throws Exception
|
||||
{
|
||||
return new TaskListenerExecutorFactoryBean(context);
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener {
|
||||
|
||||
@BeforeTask
|
||||
@@ -365,11 +351,6 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorFactoryBean taskListenerExecutor(ConfigurableApplicationContext context) throws Exception
|
||||
{
|
||||
return new TaskListenerExecutorFactoryBean(context);
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener {
|
||||
|
||||
@@ -400,12 +381,6 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorFactoryBean taskListenerExecutor(ConfigurableApplicationContext context) throws Exception
|
||||
{
|
||||
return new TaskListenerExecutorFactoryBean(context);
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener extends TestListener{
|
||||
|
||||
@BeforeTask
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
import org.springframework.cloud.task.listener.annotation.BeforeTask;
|
||||
import org.springframework.cloud.task.listener.annotation.FailedTask;
|
||||
import org.springframework.cloud.task.listener.annotation.TaskListenerExecutor;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Verifies that the {@link TaskListenerExecutorObjectFactory} retrieves the
|
||||
* {@link TaskListenerExecutor}.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
public static final String BEFORE_LISTENER = "BEFORE LISTENER";
|
||||
|
||||
public static final String AFTER_LISTENER = "AFTER LISTENER";
|
||||
|
||||
public static final String FAIL_LISTENER = "FAIL LISTENER";
|
||||
|
||||
public static List<TaskExecution> taskExecutionListenerResults = new ArrayList<>(3);
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private TaskListenerExecutor taskListenerExecutor;
|
||||
|
||||
private TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
taskExecutionListenerResults.clear();
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(this.context);
|
||||
this.taskListenerExecutor = this.taskListenerExecutorObjectFactory.getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskStartupListener() {
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
validateSingleEntry(BEFORE_LISTENER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskFailedListener() {
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
validateSingleEntry(FAIL_LISTENER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskEndListener() {
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
validateSingleEntry(AFTER_LISTENER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyAllListener() {
|
||||
this.taskListenerExecutor.onTaskStartup(createSampleTaskExecution(BEFORE_LISTENER));
|
||||
this.taskListenerExecutor.onTaskFailed(createSampleTaskExecution(FAIL_LISTENER),
|
||||
new IllegalStateException("oops"));
|
||||
this.taskListenerExecutor.onTaskEnd(createSampleTaskExecution(AFTER_LISTENER));
|
||||
assertThat(taskExecutionListenerResults.size()).isEqualTo(3);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName()).isEqualTo(BEFORE_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(1).getTaskName()).isEqualTo(FAIL_LISTENER);
|
||||
assertThat(taskExecutionListenerResults.get(2).getTaskName()).isEqualTo(AFTER_LISTENER);
|
||||
}
|
||||
|
||||
private TaskExecution createSampleTaskExecution(String taskName) {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(taskName);
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
private void validateSingleEntry(String event) {
|
||||
assertThat(taskExecutionListenerResults.size()).isEqualTo(1);
|
||||
assertThat(taskExecutionListenerResults.get(0).getTaskName()).isEqualTo(event);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TaskExecutionListenerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskRunComponent taskRunComponent() {
|
||||
return new TaskRunComponent();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TaskRunComponent {
|
||||
|
||||
@BeforeTask
|
||||
public void initBeforeListener(TaskExecution taskExecution) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
|
||||
@AfterTask
|
||||
public void initAfterListener(TaskExecution taskExecution) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
|
||||
@FailedTask
|
||||
public void initFailedListener(TaskExecution taskExecution, Throwable exception) {
|
||||
TaskListenerExecutorObjectFactoryTests.taskExecutionListenerResults.add(taskExecution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
@@ -49,7 +49,7 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {EmbeddedDataSourceConfiguration.class,
|
||||
SimpleTaskConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class})
|
||||
public class SimpleTaskRepositoryJdbcTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TestConfiguration;
|
||||
import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -89,7 +89,7 @@ public class TaskDatabaseInitializerTests {
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleDataSourcesContext() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( SimpleTaskConfiguration.class,
|
||||
this.context.register( SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.task.configuration.TaskProperties;
|
||||
import org.springframework.cloud.task.listener.TaskLifecycleListener;
|
||||
import org.springframework.cloud.task.listener.TaskListenerExecutorObjectFactory;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskNameResolver;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
@@ -74,10 +75,15 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
return new SimpleTaskNameResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskListenerExecutorObjectFactory taskListenerExecutorObjectProvider(ConfigurableApplicationContext context) {
|
||||
return new TaskListenerExecutorObjectFactory(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskLifecycleListener taskHandler(TaskExplorer taskExplorer){
|
||||
return new TaskLifecycleListener(taskRepository(), taskNameResolver(),
|
||||
applicationArguments, taskExplorer, taskProperties);
|
||||
applicationArguments, taskExplorer, taskProperties, taskListenerExecutorObjectProvider(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user