Checks for invalid ExecutionId in the TaskLifeCycleListener

resolves #115
* Fixes bug where if the user set the environment variable and commandline args a unique constraint would fire.
* Updated docs
* Removed deprecation
* Fixed version number for integration test.

Added integration tests for externally generated task executions

Add externalExecutionId

resolves #80
This commit is contained in:
Michael Minella
2016-08-22 12:55:31 -05:00
parent 2bfc4780c7
commit 17e4250586
40 changed files with 307 additions and 114 deletions

View File

@@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
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.repository.TaskExplorer;
@@ -49,6 +50,7 @@ import org.springframework.util.CollectionUtils;
*/
@Configuration
@EnableTransactionManagement
@EnableConfigurationProperties(TaskProperties.class)
public class SimpleTaskConfiguration {
protected static final Log logger = LogFactory.getLog(SimpleTaskConfiguration.class);
@@ -62,6 +64,9 @@ public class SimpleTaskConfiguration {
@Autowired(required = false)
private ApplicationArguments applicationArguments;
@Autowired
private TaskProperties taskProperties;
private boolean initialized = false;
private TaskRepository taskRepository;
@@ -137,7 +142,7 @@ public class SimpleTaskConfiguration {
this.taskExplorer = taskConfigurer.getTaskExplorer();
this.taskLifecycleListener = new TaskLifecycleListener(this.taskRepository, taskNameResolver(),
this.applicationArguments, taskExplorer);
this.applicationArguments, taskExplorer, taskProperties);
initialized = true;
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright 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.configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties available to configure the task.
*
* @author Glenn Renfro
*/
@ConfigurationProperties(prefix = "spring.cloud.task")
public class TaskProperties {
/**
* An id that can be associated with a task.
*/
private String externalExecutionId;
/**
* An id that will be used by the task when updating the task execution.
*/
private Integer executionid;
/**
* When set to true the context is closed at the end of the task. Else
* the context remains open.
*/
private Boolean closecontextEnable = true;
public String getExternalExecutionId() {
return externalExecutionId;
}
public void setExternalExecutionId(String externalExecutionId) {
this.externalExecutionId = externalExecutionId;
}
public Integer getExecutionid() {
return executionid;
}
public void setExecutionid(Integer executionid) {
this.executionid = executionid;
}
public Boolean getClosecontextEnable() {
return closecontextEnable;
}
public void setClosecontextEnable(Boolean closecontextEnable) {
this.closecontextEnable = closecontextEnable;
}
}

View File

@@ -34,6 +34,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ExitCodeEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.task.configuration.TaskProperties;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.cloud.task.repository.TaskExplorer;
import org.springframework.cloud.task.repository.TaskNameResolver;
@@ -80,6 +81,8 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
private TaskExecution taskExecution;
private TaskProperties taskProperties;
private boolean started = false;
private boolean finished = false;
@@ -92,26 +95,23 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
private ExitCodeEvent exitCodeEvent;
@Value("${spring.cloud.task.closecontext.enable:true}")
private Boolean closeContext;
@Value("${spring.cloud.task.executionid:}")
private Integer taskExecutionId;
/**
* @param taskRepository The repository to record executions in.
*/
public TaskLifecycleListener(TaskRepository taskRepository,
TaskNameResolver taskNameResolver,
ApplicationArguments applicationArguments, TaskExplorer taskExplorer) {
ApplicationArguments applicationArguments, TaskExplorer taskExplorer,
TaskProperties taskProperties) {
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");
this.taskRepository = taskRepository;
this.taskNameResolver = taskNameResolver;
this.applicationArguments = applicationArguments;
this.taskExplorer = taskExplorer;
this.taskProperties = taskProperties;
}
/**
@@ -176,7 +176,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
this.finished = true;
if(this.closeContext && this.context.isActive()) {
if(taskProperties.getClosecontextEnable() && this.context.isActive()) {
this.context.close();
}
@@ -195,17 +195,17 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
if(this.applicationArguments != null) {
args = Arrays.asList(this.applicationArguments.getSourceArgs());
}
if(this.taskExecutionId != null) {
TaskExecution taskExecution = taskExplorer.getTaskExecution(this.taskExecutionId);
Assert.notNull(taskExecution, String.format("Invalid TaskExecution, ID %s not found", this.taskExecutionId));
if(taskProperties.getExecutionid() != null) {
TaskExecution taskExecution = taskExplorer.getTaskExecution(taskProperties.getExecutionid());
Assert.notNull(taskExecution, String.format("Invalid TaskExecution, ID %s not found", taskProperties.getExecutionid()));
Assert.isNull(taskExecution.getEndTime(), String.format(
"Invalid TaskExecution, ID %s task is already complete", this.taskExecutionId));
this.taskExecution = this.taskRepository.startTaskExecution(this.taskExecutionId,
this.taskNameResolver.getTaskName(), new Date(), args);
"Invalid TaskExecution, ID %s task is already complete", taskProperties.getExecutionid()));
this.taskExecution = this.taskRepository.startTaskExecution(taskProperties.getExecutionid(),
this.taskNameResolver.getTaskName(), new Date(), args, taskProperties.getExternalExecutionId());
}
else {
this.taskExecution = this.taskRepository.createTaskExecution(
this.taskNameResolver.getTaskName(), new Date(), args);
this.taskNameResolver.getTaskName(), new Date(), args, taskProperties.getExternalExecutionId());
}
}
else {
@@ -254,7 +254,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
taskExecution.getExitCode(), taskExecution.getTaskName(), startTime,
endTime,taskExecution.getExitMessage(),
Collections.unmodifiableList(taskExecution.getArguments()),
taskExecution.getErrorMessage());
taskExecution.getErrorMessage(), taskExecution.getExternalExecutionId());
}
@Override

View File

@@ -21,6 +21,7 @@ import java.util.Date;
import java.util.List;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Represents the state of the Task for each execution.
@@ -60,6 +61,13 @@ public class TaskExecution {
*/
private String exitMessage;
/**
* Id assigned to the task by the platform.
*
* @since 1.1.0
*/
private String externalExecutionId;
/**
* Error information available upon the failure of a task
*
@@ -79,7 +87,7 @@ public class TaskExecution {
public TaskExecution(long executionId, Integer exitCode, String taskName,
Date startTime, Date endTime,
String exitMessage, List<String> arguments,
String errorMessage) {
String errorMessage, String externalExecutionId) {
Assert.notNull(arguments, "arguments must not be null");
this.executionId = executionId;
@@ -90,6 +98,7 @@ public class TaskExecution {
this.startTime = (startTime != null) ? (Date)startTime.clone() : null;
this.endTime = (endTime != null) ? (Date)endTime.clone() : null;
this.errorMessage = errorMessage;
this.externalExecutionId = externalExecutionId;
}
public long getExecutionId() {
@@ -152,6 +161,14 @@ public class TaskExecution {
this.errorMessage = errorMessage;
}
public String getExternalExecutionId() {
return externalExecutionId;
}
public void setExternalExecutionId(String externalExecutionId) {
this.externalExecutionId = externalExecutionId;
}
@Override
public String toString() {
return "TaskExecution{" +

View File

@@ -62,11 +62,12 @@ public interface TaskRepository {
* @param taskName the name that associated with the task execution.
* @param startTime the time task began.
* @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform.
* @return the initial {@link TaskExecution}
*/
@Transactional
TaskExecution createTaskExecution(String taskName,
Date startTime,List<String> arguments);
Date startTime,List<String> arguments, String externalExecutionId);
/**
* Creates an empty TaskExecution with just an id provided. This is intended to be
@@ -85,9 +86,11 @@ public interface TaskRepository {
* @param taskName the name that associated with the task execution.
* @param startTime the time task began.
* @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform.
* @return
*/
@Transactional
TaskExecution startTaskExecution(long executionid, String taskName,
Date startTime,List<String> arguments);
Date startTime,List<String> arguments, String externalExecutionId);
}

View File

@@ -58,7 +58,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED ";
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID ";
public static final String FROM_CLAUSE = "%PREFIX%EXECUTION";
@@ -68,14 +68,14 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
public static final String TASK_NAME_WHERE_CLAUSE = "where TASK_NAME = ? ";
private static final String SAVE_TASK_EXECUTION = "INSERT into %PREFIX%EXECUTION"
+ "(TASK_EXECUTION_ID, START_TIME, TASK_NAME, LAST_UPDATED)"
+ "values (?, ?, ?, ?)";
+ "(TASK_EXECUTION_ID, START_TIME, TASK_NAME, LAST_UPDATED, EXTERNAL_EXECUTION_ID)"
+ "values (?, ?, ?, ?, ?)";
private static final String CREATE_TASK_ARGUMENT = "INSERT into "
+ "%PREFIX%EXECUTION_PARAMS(TASK_EXECUTION_ID, TASK_PARAM ) values (?, ?)";
private static final String START_TASK_EXECUTION = "UPDATE %PREFIX%EXECUTION set "
+ "START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ? where TASK_EXECUTION_ID = ?";
+ "START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?, EXTERNAL_EXECUTION_ID = ? where TASK_EXECUTION_ID = ?";
private static final String CHECK_TASK_EXECUTION_EXISTS = "SELECT COUNT(*) FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = ?";
@@ -86,7 +86,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, " +
"START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = ?";
private static final String FIND_ARGUMENT_FROM_ID = "SELECT TASK_EXECUTION_ID, "
@@ -129,31 +129,32 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public TaskExecution createTaskExecution(String taskName,
Date startTime, List<String> arguments) {
Date startTime, List<String> arguments, String externalExecutionId) {
long nextExecutionId = getNextExecutionId();
TaskExecution taskExecution = new TaskExecution(nextExecutionId, null, taskName,
startTime, null, null, arguments, null);
startTime, null, null, arguments, null, externalExecutionId);
Object[] queryParameters = new Object[]{ nextExecutionId, startTime, taskName, new Date()};
Object[] queryParameters = new Object[]{ nextExecutionId, startTime, taskName, new Date(), externalExecutionId};
jdbcTemplate.update(
getQuery(SAVE_TASK_EXECUTION),
queryParameters,
new int[]{ Types.BIGINT, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP });
new int[]{ Types.BIGINT, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR });
insertTaskArguments(nextExecutionId, arguments);
return taskExecution;
}
@Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments) {
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
String externalExecutionId) {
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
startTime, null, null, arguments, null);
startTime, null, null, arguments, null, externalExecutionId);
Object[] queryParameters = new Object[]{ startTime, taskName, new Date(), executionId};
Object[] queryParameters = new Object[]{ startTime, taskName, new Date(), externalExecutionId, executionId};
jdbcTemplate.update(
getQuery(START_TASK_EXECUTION),
queryParameters,
new int[]{ Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.BIGINT });
new int[]{ Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT });
insertTaskArguments(executionId, arguments);
return taskExecution;
}
@@ -399,7 +400,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
rs.getTimestamp("END_TIME"),
rs.getString("EXIT_MESSAGE"),
getTaskArguments(id),
rs.getString("ERROR_MESSAGE"));
rs.getString("ERROR_MESSAGE"),
rs.getString("EXTERNAL_EXECUTION_ID"));
}
private Integer getNullableExitCode(ResultSet rs) throws SQLException {

View File

@@ -53,21 +53,23 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public TaskExecution createTaskExecution(String taskName,
Date startTime, List<String> arguments) {
Date startTime, List<String> arguments, String externalExecutionId) {
long taskExecutionId = getNextExecutionId();
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
startTime, null, null, arguments, null);
startTime, null, null, arguments, null, externalExecutionId);
taskExecutions.put(taskExecutionId, taskExecution);
return taskExecution;
}
@Override
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments) {
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
String externalExecutionid) {
TaskExecution taskExecution= taskExecutions.get(executionId);
taskExecution.setTaskName(taskName);
taskExecution.setStartTime(startTime);
taskExecution.setArguments(arguments);
taskExecution.setExternalExecutionId(externalExecutionid);
return taskExecution;
}

View File

@@ -37,10 +37,11 @@ public interface TaskExecutionDao {
* @param taskName the name that associated with the task execution.
* @param startTime the time task began.
* @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform
* @return A fully qualified {@link TaskExecution} instance.
*/
TaskExecution createTaskExecution( String taskName,
Date startTime, List<String> arguments);
Date startTime, List<String> arguments, String externalExecutionId);
/**
* Update and existing {@link TaskExecution} to mark it as started.
@@ -49,10 +50,11 @@ public interface TaskExecutionDao {
* @param taskName the name that associated with the task execution.
* @param startTime the time task began.
* @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform
* @since 1.1.0
*/
TaskExecution startTaskExecution(long executionId, String taskName,
Date startTime, List<String> arguments);
Date startTime, List<String> arguments, String externalExecutionId);
/**
* Update and existing {@link TaskExecution} to mark it as completed.

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.task.repository.support;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -101,11 +102,11 @@ public class SimpleTaskRepository implements TaskRepository {
@Override
public TaskExecution createTaskExecution(String taskName,
Date startTime,List<String> arguments) {
Date startTime,List<String> arguments, String externalExecutionId) {
initialize();
validateCreateInformation(startTime, taskName);
TaskExecution taskExecution =
taskExecutionDao.createTaskExecution(taskName, startTime, arguments);
taskExecutionDao.createTaskExecution(taskName, startTime, arguments, externalExecutionId);
logger.debug("Creating: " + taskExecution.toString());
return taskExecution;
}
@@ -114,16 +115,18 @@ public class SimpleTaskRepository implements TaskRepository {
public TaskExecution createTaskExecution() {
initialize();
TaskExecution taskExecution =
taskExecutionDao.createTaskExecution(null, null, new ArrayList<String>(0));
taskExecutionDao.createTaskExecution(null, null,
Collections.<String>emptyList(), null);
logger.debug("Creating: " + taskExecution.toString());
return taskExecution;
}
@Override
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments) {
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
String externalExecutionId) {
initialize();
TaskExecution taskExecution =
taskExecutionDao.startTaskExecution(executionid, taskName, startTime, arguments);
taskExecutionDao.startTaskExecution(executionid, taskName, startTime, arguments, externalExecutionId);
logger.debug("Starting: " + taskExecution.toString());
return taskExecution;
}

View File

@@ -1 +1,2 @@
alter table task_execution add ERROR_MESSAGE VARCHAR(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID VARCHAR(255);

View File

@@ -1 +1,2 @@
alter table task_execution add column ERROR_MESSAGE VARCHAR(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID VARCHAR(255);

View File

@@ -1 +1,3 @@
alter table task_execution add column ERROR_MESSAGE VARCHAR(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID VARCHAR(255);

View File

@@ -1 +1,3 @@
alter table task_execution add ERROR_MESSAGE varchar2(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID varchar2(255);

View File

@@ -1 +1,2 @@
alter table task_execution add column ERROR_MESSAGE VARCHAR(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID VARCHAR(255);

View File

@@ -1 +1,2 @@
alter table task_execution add ERROR_MESSAGE VARCHAR(2500);
alter table task_execution add EXTERNAL_EXECUTION_ID VARCHAR(255);

View File

@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP
LAST_UPDATED TIMESTAMP,
EXTERNAL_EXECUTION_ID VARCHAR(255)
);
CREATE TABLE TASK_EXECUTION_PARAMS (

View File

@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP
LAST_UPDATED TIMESTAMP,
EXTERNAL_EXECUTION_ID VARCHAR(255)
);
CREATE TABLE TASK_EXECUTION_PARAMS (

View File

@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP
LAST_UPDATED TIMESTAMP,
EXTERNAL_EXECUTION_ID VARCHAR(255)
) ENGINE=InnoDB;
CREATE TABLE TASK_EXECUTION_PARAMS (
@@ -18,8 +19,8 @@ CREATE TABLE TASK_EXECUTION_PARAMS (
) ENGINE=InnoDB;
CREATE TABLE TASK_TASK_BATCH (
TASK_EXECUTION_ID BIGINT NOT NULL ,
JOB_EXECUTION_ID BIGINT NOT NULL ,
TASK_EXECUTION_ID BIGINT NOT NULL ,
JOB_EXECUTION_ID BIGINT NOT NULL ,
constraint TASK_EXEC_BATCH_FK foreign key (TASK_EXECUTION_ID)
references TASK_EXECUTION(TASK_EXECUTION_ID)
) ENGINE=InnoDB;

View File

@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR2(2500) ,
ERROR_MESSAGE VARCHAR2(2500) ,
LAST_UPDATED TIMESTAMP
LAST_UPDATED TIMESTAMP,
EXTERNAL_EXECUTION_ID VARCHAR2(255)
);
CREATE TABLE TASK_EXECUTION_PARAMS (

View File

@@ -7,7 +7,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP
LAST_UPDATED TIMESTAMP ,
EXTERNAL_EXECUTION_ID VARCHAR(255)
);
CREATE TABLE TASK_EXECUTION_PARAMS (

View File

@@ -6,7 +6,8 @@ CREATE TABLE TASK_EXECUTION (
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED DATETIME
LAST_UPDATED DATETIME ,
EXTERNAL_EXECUTION_ID VARCHAR(255)
);
CREATE TABLE TASK_EXECUTION_PARAMS (

View File

@@ -71,7 +71,7 @@ public class TaskExecutionListenerTests {
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
new Date(), new Date(), null, new ArrayList<String>(), null);
new Date(), new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, false, false, taskExecution,taskExecutionListener);
}
@@ -87,7 +87,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
new Date(), new Date(), null, new ArrayList<String>(), null);
new Date(), new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, true, false, taskExecution,taskExecutionListener);
}
@@ -106,7 +106,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<String>(), null);
new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, true, true, taskExecution,taskExecutionListener);
}
@@ -120,7 +120,7 @@ public class TaskExecutionListenerTests {
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
new Date(), new Date(), null, new ArrayList<String>(), null);
new Date(), new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, false, false, taskExecution,annotatedListener);
}
@@ -136,7 +136,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
new Date(), new Date(), null, new ArrayList<String>(), null);
new Date(), new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, true, false, taskExecution,annotatedListener);
}
@@ -155,7 +155,7 @@ public class TaskExecutionListenerTests {
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
new Date(), null, new ArrayList<String>(), null);
new Date(), null, new ArrayList<String>(), null, null);
verifyListenerResults(true, true, true, taskExecution,annotatedListener);
}
@@ -184,6 +184,7 @@ public class TaskExecutionListenerTests {
assertEquals(taskExecution.getExecutionId(), actualListener.getTaskExecution().getExecutionId());
assertEquals(taskExecution.getExitCode(), actualListener.getTaskExecution().getExitCode());
assertEquals(taskExecution.getExternalExecutionId(), actualListener.getTaskExecution().getExternalExecutionId());
}
private void setupContextForTaskExecutionListener(){

View File

@@ -84,7 +84,7 @@ public class TaskLifecycleListenerTests {
public void testTaskCreate() {
context.refresh();
this.taskExplorer = context.getBean(TaskExplorer.class);
verifyTaskExecution(0, false, 0, null);
verifyTaskExecution(0, false);
}
@Test
@@ -92,7 +92,7 @@ public class TaskLifecycleListenerTests {
context.register(ArgsConfiguration.class);
context.refresh();
this.taskExplorer = context.getBean(TaskExplorer.class);
verifyTaskExecution(2, false, 0, null);
verifyTaskExecution(2, false);
}
@Test
@@ -102,7 +102,7 @@ public class TaskLifecycleListenerTests {
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
verifyTaskExecution(0, true, 0, null);
verifyTaskExecution(0, true);
}
@Test
@@ -114,7 +114,7 @@ public class TaskLifecycleListenerTests {
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
verifyTaskExecution(0, true, 1, exception);
verifyTaskExecution(0, true, 1, exception, null);
}
@Test
@@ -128,13 +128,13 @@ public class TaskLifecycleListenerTests {
context.publishEvent(new ApplicationFailedEvent(application, new String[0], context, exception));
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
verifyTaskExecution(0, true, exitCode, exception);
verifyTaskExecution(0, true, exitCode, exception, null);
}
@Test
public void testNoClosingOfContext() {
ConfigurableApplicationContext applicationContext = SpringApplication.run(new Object[] {TestDefaultConfiguration.class, PropertyPlaceholderAutoConfiguration.class},
new String[] {"--spring.cloud.task.closecontext.enable=false"});
new String[] {"--spring.cloud.task.closecontext_enable=false"});
try {
assertTrue(applicationContext.isActive());
@@ -155,7 +155,27 @@ public class TaskLifecycleListenerTests {
context.refresh();
}
private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode, Throwable exception) {
@Test
public void testExternalExecutionId() {
ConfigurableEnvironment environment = new StandardEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
Map myMap = new HashMap();
myMap.put("spring.cloud.task.external-execution-id", "myid");
propertySources.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
context.setEnvironment(environment);
context.refresh();
this.taskExplorer = context.getBean(TaskExplorer.class);
verifyTaskExecution(0, false, 0, null, "myid");
}
private void verifyTaskExecution(int numberOfParams, boolean update) {
verifyTaskExecution(numberOfParams, update, 0, null, null);
}
private void verifyTaskExecution(int numberOfParams, boolean update,
Integer exitCode, Throwable exception, String externalExecutionId) {
Sort sort = new Sort("id");
@@ -168,6 +188,7 @@ public class TaskLifecycleListenerTests {
assertEquals(numberOfParams, taskExecution.getArguments().size());
assertEquals(exitCode, taskExecution.getExitCode());
assertEquals(externalExecutionId, taskExecution.getExternalExecutionId());
if(exception != null) {
assertTrue(taskExecution.getErrorMessage().length() > exception.getStackTrace().length);

View File

@@ -63,14 +63,15 @@ public class JdbcTaskExecutionDaoTests {
@DirtiesContext
public void testStartTaskExecution() {
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
new ArrayList<String>(0));
new ArrayList<String>(0), null);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
@@ -81,7 +82,7 @@ public class JdbcTaskExecutionDaoTests {
public void createTaskExecution() {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution = dao.createTaskExecution(expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments());
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
@@ -91,7 +92,7 @@ public class JdbcTaskExecutionDaoTests {
@DirtiesContext
public void createEmptyTaskExecution() {
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
new ArrayList<String>(0));
new ArrayList<String>(0), null);
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
TestDBUtils.getTaskExecutionFromDB(dataSource, expectedTaskExecution.getExecutionId()));
@@ -102,7 +103,8 @@ public class JdbcTaskExecutionDaoTests {
public void completeTaskExecution() {
TaskExecution expectedTaskExecution = TestVerifierUtils.endSampleTaskExecutionNoArg();
expectedTaskExecution = dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
expectedTaskExecution.getExitMessage());

View File

@@ -45,13 +45,15 @@ public class MapTaskExecutionDaoTests {
@Test
public void testStartTaskExecution() {
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<String>(0));
TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null, new ArrayList<String>(0), null);
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
expectedTaskExecution.setStartTime(new Date());
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(), expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
Map<Long, TaskExecution> taskExecutionMap = this.dao.getTaskExecutions();
assertNotNull("taskExecutionMap must not be null", taskExecutionMap);
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
@@ -61,7 +63,7 @@ public class MapTaskExecutionDaoTests {
@Test
public void createEmptyTaskExecution() {
TaskExecution expectedTaskExecution = dao.createTaskExecution(null, null,
new ArrayList<String>(0));
new ArrayList<String>(0), null);
Map<Long, TaskExecution> taskExecutionMap = this.dao.getTaskExecutions();
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
@@ -80,7 +82,8 @@ public class MapTaskExecutionDaoTests {
public void saveTaskExecution(){
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
Map<Long, TaskExecution> taskExecutionMap = this.dao.getTaskExecutions();
assertNotNull("taskExecutionMap must not be null", taskExecutionMap);
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
@@ -91,7 +94,8 @@ public class MapTaskExecutionDaoTests {
public void completeTaskExecution(){
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
expectedTaskExecution.getExitMessage());

View File

@@ -43,30 +43,30 @@ public class FindAllPagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "ERROR_MESSAGE, LAST_UPDATED FROM %PREFIX%EXECUTION ORDER BY "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "%PREFIX%EXECUTION ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION) TASK_EXECUTION_PAGE "
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, "

View File

@@ -44,34 +44,34 @@ public class WhereClausePagingQueryProviderTests {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROWNUM as "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROWNUM as "
+ "TMP_ROW_NUM FROM (SELECT TASK_EXECUTION_ID, START_TIME, "
+ "END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, "
+ "LAST_UPDATED FROM %PREFIX%EXECUTION "
+ "LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC)) WHERE TMP_ROW_NUM >= 1 AND "
+ "TMP_ROW_NUM < 11"},
{"HSQL Database Engine","SELECT LIMIT 0 10 TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, EXIT_MESSAGE, "
+ "ERROR_MESSAGE, LAST_UPDATED FROM %PREFIX%EXECUTION "
+ "ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM %PREFIX%EXECUTION "
+ "WHERE TASK_EXECUTION_ID = '0000' ORDER BY "
+ "START_TIME DESC, TASK_EXECUTION_ID DESC"},
{"PostgreSQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID "
+ "FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 10 OFFSET 0"},
{"MySQL","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = '0000' "
+ "ORDER BY START_TIME DESC, "
+ "TASK_EXECUTION_ID DESC LIMIT 0, 10"},
{"Microsoft SQL Server","SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED FROM "
+ "TASK_NAME, EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID FROM "
+ "(SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, ROW_NUMBER() "
+ "EXIT_CODE, EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, ROW_NUMBER() "
+ "OVER (ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC) AS "
+ "TMP_ROW_NUM FROM %PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = "
+ "'0000') TASK_EXECUTION_PAGE WHERE TMP_ROW_NUM >= 1 "

View File

@@ -155,6 +155,7 @@ public class SimpleTaskExplorerTests {
final int TEST_COUNT = 2;
final int COMPLETE_COUNT = 5;
final String TASK_NAME = "FOOBAR";
final String EXTERNAL_EXECUTION_ID = "123ABC";
Map<Long, TaskExecution> expectedResults = new HashMap<>();
//Store completed jobs
@@ -165,7 +166,7 @@ public class SimpleTaskExplorerTests {
for (; i < (COMPLETE_COUNT + TEST_COUNT); i++) {
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(
TASK_NAME, new Date(), new ArrayList<String>());
TASK_NAME, new Date(), new ArrayList<String>(), EXTERNAL_EXECUTION_ID);
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
}
Pageable pageable = new PageRequest(0, 10);
@@ -190,6 +191,7 @@ public class SimpleTaskExplorerTests {
final int TEST_COUNT = 5;
final int COMPLETE_COUNT = 7;
final String TASK_NAME = "FOOBAR";
final String EXTERNAL_EXECUTION_ID = "123ABC";
Random randomGenerator = new Random();
Map<Long, TaskExecution> expectedResults = new HashMap<>();
@@ -200,7 +202,7 @@ public class SimpleTaskExplorerTests {
for (int i = 0; i < TEST_COUNT; i++) {
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(
TASK_NAME, new Date(), new ArrayList<String>());
TASK_NAME, new Date(), new ArrayList<String>(), EXTERNAL_EXECUTION_ID);
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
}
@@ -318,7 +320,7 @@ public class SimpleTaskExplorerTests {
private TaskExecution createAndSaveTaskExecution(int i) {
TaskExecution taskExecution = TestVerifierUtils.createSampleTaskExecution(i);
taskExecution = this.taskRepository.createTaskExecution(taskExecution.getTaskName(),
taskExecution.getStartTime(), taskExecution.getArguments());
taskExecution.getStartTime(), taskExecution.getArguments(), taskExecution.getExternalExecutionId());
return taskExecution;
}

View File

@@ -105,7 +105,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments());
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@@ -121,7 +121,7 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments());
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@@ -194,7 +194,8 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1]));
simpleTaskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
}
@Test(expected = IllegalArgumentException.class)
@@ -204,7 +205,8 @@ public class SimpleTaskRepositoryJdbcTests {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution.setTaskName(new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
simpleTaskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
}
@Test
@@ -230,7 +232,7 @@ public class SimpleTaskRepositoryJdbcTests {
public void testCreateTaskExecutionNoParamMaxTaskName(){
taskRepository.createTaskExecution(
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE+1]),
new Date(), null);
new Date(), null, null);
}
@Test(expected=IllegalArgumentException.class)

View File

@@ -80,7 +80,7 @@ public class SimpleTaskRepositoryMapTests {
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments());
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
@@ -95,7 +95,7 @@ public class SimpleTaskRepositoryMapTests {
TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
expectedTaskExecution.getArguments());
expectedTaskExecution.getArguments(), expectedTaskExecution.getExternalExecutionId());
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}

View File

@@ -49,7 +49,8 @@ public class TaskExecutionCreator {
public static TaskExecution createAndStoreTaskExecutionNoParams(TaskRepository taskRepository) {
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
return expectedTaskExecution;
}
@@ -66,7 +67,8 @@ public class TaskExecutionCreator {
params.add(UUID.randomUUID().toString());
expectedTaskExecution.setArguments(params);
expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments());
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
return expectedTaskExecution;
}

View File

@@ -74,7 +74,8 @@ public class TestDBUtils {
rs.getTimestamp("END_TIME"),
rs.getString("EXIT_MESSAGE"),
new ArrayList<String>(0),
rs.getString("ERROR_MESSAGE"));
rs.getString("ERROR_MESSAGE"),
rs.getString("EXTERNAL_EXECUTION_ID"));
return taskExecution;
}
});

View File

@@ -21,6 +21,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
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.repository.TaskExplorer;
import org.springframework.cloud.task.repository.TaskNameResolver;
@@ -40,10 +42,14 @@ import org.springframework.context.annotation.Configuration;
* @author Michael Minella
*/
@Configuration
@EnableConfigurationProperties(TaskProperties.class)
public class TestDefaultConfiguration implements InitializingBean {
private TaskExecutionDaoFactoryBean factoryBean;
@Autowired
TaskProperties taskProperties;
@Autowired(required = false)
private ApplicationArguments applicationArguments;
@@ -70,7 +76,8 @@ public class TestDefaultConfiguration implements InitializingBean {
@Bean
public TaskLifecycleListener taskHandler(TaskExplorer taskExplorer){
return new TaskLifecycleListener(taskRepository(), taskNameResolver(), applicationArguments, taskExplorer);
return new TaskLifecycleListener(taskRepository(), taskNameResolver(),
applicationArguments, taskExplorer, taskProperties);
}
@Override

View File

@@ -90,7 +90,7 @@ public class TestVerifierUtils {
String taskName = UUID.randomUUID().toString();
return new TaskExecution(executionId, 0, taskName,
startTime, null, null, new ArrayList<String>(), null);
startTime, null, null, new ArrayList<String>(), null, null);
}
/**
@@ -108,7 +108,7 @@ public class TestVerifierUtils {
String exitMessage = UUID.randomUUID().toString();
return new TaskExecution(executionId, exitCode, taskName,
startTime, endTime, exitMessage, new ArrayList<String>(), null);
startTime, endTime, exitMessage, new ArrayList<String>(), null, null);
}
/**
@@ -119,12 +119,13 @@ public class TestVerifierUtils {
public static TaskExecution createSampleTaskExecution(long executionId) {
Date startTime = new Date();
String taskName = UUID.randomUUID().toString();
String externalExecutionId = UUID.randomUUID().toString();
List<String> args = new ArrayList<>(ARG_SIZE);
for (int i = 0; i < ARG_SIZE; i++){
args.add(UUID.randomUUID().toString());
}
return new TaskExecution(executionId, null, taskName,
startTime, null, null, args, null);
startTime, null, null, args, null, externalExecutionId);
}
/**