Updates the TaskRepository createTaskExecution to support TaskExecution param
resolves #223 Updated to use TaskExecution when creating new executions for test.
This commit is contained in:
@@ -204,8 +204,13 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
this.taskNameResolver.getTaskName(), new Date(), args, taskProperties.getExternalExecutionId());
|
||||
}
|
||||
else {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(this.taskNameResolver.getTaskName());
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setArguments(args);
|
||||
taskExecution.setExternalExecutionId(taskProperties.getExternalExecutionId());
|
||||
this.taskExecution = this.taskRepository.createTaskExecution(
|
||||
this.taskNameResolver.getTaskName(), new Date(), args, taskProperties.getExternalExecutionId());
|
||||
taskExecution);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -59,15 +59,16 @@ public interface TaskRepository {
|
||||
/**
|
||||
* Notifies the repository that a taskExecution needs to be created.
|
||||
*
|
||||
* @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}
|
||||
* @param taskExecution a TaskExecution instance containing the startTime,
|
||||
* arguments and externalExecutionId that will be stored in the repository.
|
||||
* Only the values enumerated above will be stored for this
|
||||
* TaskExecution.
|
||||
* @return the {@link TaskExecution} that was stored in the repository. The
|
||||
* TaskExecution's taskExecutionId will also contain the id that was used
|
||||
* to store the TaskExecution.
|
||||
*/
|
||||
@Transactional
|
||||
TaskExecution createTaskExecution(String taskName,
|
||||
Date startTime,List<String> arguments, String externalExecutionId);
|
||||
TaskExecution createTaskExecution(TaskExecution taskExecution);
|
||||
|
||||
/**
|
||||
* Creates an empty TaskExecution with just an id provided. This is intended to be
|
||||
|
||||
@@ -101,14 +101,17 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName,
|
||||
Date startTime,List<String> arguments, String externalExecutionId) {
|
||||
public TaskExecution createTaskExecution(TaskExecution taskExecution) {
|
||||
initialize();
|
||||
validateCreateInformation(startTime, taskName);
|
||||
TaskExecution taskExecution =
|
||||
taskExecutionDao.createTaskExecution(taskName, startTime, arguments, externalExecutionId);
|
||||
validateCreateInformation(taskExecution);
|
||||
TaskExecution daoTaskExecution =
|
||||
taskExecutionDao.createTaskExecution(
|
||||
taskExecution.getTaskName(),
|
||||
taskExecution.getStartTime(),
|
||||
taskExecution.getArguments(),
|
||||
taskExecution.getExternalExecutionId());
|
||||
logger.debug("Creating: " + taskExecution.toString());
|
||||
return taskExecution;
|
||||
return daoTaskExecution;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,11 +158,11 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
/**
|
||||
* Validate startTime and taskName are valid.
|
||||
*/
|
||||
private void validateCreateInformation(Date startTime, String taskName) {
|
||||
Assert.notNull(startTime, "TaskExecution start time cannot be null.");
|
||||
private void validateCreateInformation(TaskExecution taskExecution) {
|
||||
Assert.notNull(taskExecution.getStartTime(), "TaskExecution start time cannot be null.");
|
||||
|
||||
if (taskName != null &&
|
||||
taskName.length() > this.maxTaskNameSize) {
|
||||
if (taskExecution.getTaskName() != null &&
|
||||
taskExecution.getTaskName().length() > this.maxTaskNameSize) {
|
||||
throw new IllegalArgumentException("TaskName length exceeds "
|
||||
+ this.maxTaskNameSize + " characters");
|
||||
}
|
||||
|
||||
@@ -177,20 +177,23 @@ public class JdbcTaskExecutionDaoTests {
|
||||
}
|
||||
|
||||
private void initializeRepository() {
|
||||
repository.createTaskExecution("FOO3",
|
||||
new Date(),new ArrayList<String>(0), "externalA");
|
||||
repository.createTaskExecution("FOO2",
|
||||
new Date(),new ArrayList<String>(0), "externalB");
|
||||
repository.createTaskExecution("FOO1",
|
||||
new Date(),new ArrayList<String>(0), "externalC");
|
||||
repository.createTaskExecution(getTaskExecution("FOO3", "externalA"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO2", "externalB"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
}
|
||||
|
||||
private void initializeRepositoryNotInOrder() {
|
||||
repository.createTaskExecution("FOO1",
|
||||
new Date(), new ArrayList<String>(0), "externalC");
|
||||
repository.createTaskExecution("FOO2",
|
||||
new Date(), new ArrayList<String>(0), "externalA");
|
||||
repository.createTaskExecution("FOO3",
|
||||
new Date(), new ArrayList<String>(0), "externalB");
|
||||
repository.createTaskExecution(getTaskExecution("FOO1", "externalC"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO2", "externalA"));
|
||||
repository.createTaskExecution(getTaskExecution("FOO3", "externalB"));
|
||||
}
|
||||
|
||||
private TaskExecution getTaskExecution(String taskName,
|
||||
String externalExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(taskName);
|
||||
taskExecution.setExternalExecutionId(externalExecutionId);
|
||||
taskExecution.setStartTime(new Date());
|
||||
return taskExecution;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ import org.springframework.data.domain.Pageable;
|
||||
@RunWith(Parameterized.class)
|
||||
public class SimpleTaskExplorerTests {
|
||||
|
||||
private final static String TASK_NAME = "FOOBAR";
|
||||
|
||||
private final static String EXTERNAL_EXECUTION_ID = "123ABC";
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
@@ -154,8 +158,6 @@ public class SimpleTaskExplorerTests {
|
||||
public void findRunningTasks() {
|
||||
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,8 +167,8 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
for (; i < (COMPLETE_COUNT + TEST_COUNT); i++) {
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(
|
||||
TASK_NAME, new Date(), new ArrayList<String>(), EXTERNAL_EXECUTION_ID);
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.
|
||||
createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
|
||||
}
|
||||
Pageable pageable = new PageRequest(0, 10);
|
||||
@@ -190,8 +192,6 @@ public class SimpleTaskExplorerTests {
|
||||
public void findTasksByName() {
|
||||
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<>();
|
||||
@@ -201,8 +201,8 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
for (int i = 0; i < TEST_COUNT; i++) {
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.createTaskExecution(
|
||||
TASK_NAME, new Date(), new ArrayList<String>(), EXTERNAL_EXECUTION_ID);
|
||||
TaskExecution expectedTaskExecution = this.taskRepository.
|
||||
createTaskExecution(getSimpleTaskExecution());
|
||||
expectedResults.put(expectedTaskExecution.getExecutionId(), expectedTaskExecution);
|
||||
}
|
||||
|
||||
@@ -319,8 +319,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.getExternalExecutionId());
|
||||
taskExecution = this.taskRepository.createTaskExecution(taskExecution);
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
@@ -379,6 +378,14 @@ public class SimpleTaskExplorerTests {
|
||||
});
|
||||
}
|
||||
|
||||
private TaskExecution getSimpleTaskExecution() {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(TASK_NAME);
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setExternalExecutionId(EXTERNAL_EXECUTION_ID);
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
private enum DaoType{jdbc, map}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -193,9 +193,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
MAX_ERROR_MESSAGE_SIZE);
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1]));
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -204,9 +202,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), null, null, null);
|
||||
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.getExternalExecutionId());
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,9 +226,11 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxTaskName(){
|
||||
taskRepository.createTaskExecution(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE+1]),
|
||||
new Date(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE+1]));
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskRepository.createTaskExecution(taskExecution);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
|
||||
@@ -48,9 +48,7 @@ public class TaskExecutionCreator {
|
||||
*/
|
||||
public static TaskExecution createAndStoreTaskExecutionNoParams(TaskRepository taskRepository) {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution = taskRepository.createTaskExecution();
|
||||
return expectedTaskExecution;
|
||||
}
|
||||
|
||||
@@ -66,9 +64,7 @@ public class TaskExecutionCreator {
|
||||
params.add(UUID.randomUUID().toString());
|
||||
params.add(UUID.randomUUID().toString());
|
||||
expectedTaskExecution.setArguments(params);
|
||||
expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution.getTaskName(),
|
||||
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution);
|
||||
return expectedTaskExecution;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user