Java Code Examples for org.springframework.cloud.task.repository.TaskExecution#setEndTime()

The following examples show how to use org.springframework.cloud.task.repository.TaskExecution#setEndTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskLaunchNoManifest() throws Exception{
	final TaskExecution taskExecutionComplete = this.taskExecutionCreationService.createTaskExecution("myTask3");
	taskExecutionComplete.setTaskName("myTask3");
	taskExecutionComplete.setStartTime(new Date());
	taskExecutionComplete.setEndTime(new Date());
	taskExecutionComplete.setExitCode(0);
	when(taskExplorer.getLatestTaskExecutionForTaskName("myTask3")).thenReturn(taskExecutionComplete);
	when(taskExplorer.getTaskExecution(taskExecutionComplete.getExecutionId())).thenReturn(taskExecutionComplete);
	when(taskExplorer.getLatestTaskExecutionsByTaskNames(any()))
			.thenReturn(Arrays.asList(taskExecutionComplete, taskExecutionComplete));
	repository.save(new TaskDefinition("myTask3", "foo"));
	this.registry.save("foo", ApplicationType.task,
			"1.0.0", new URI("file:src/test/resources/apps/foo-task"), null);
	this.dataflowTaskExecutionMetadataDao.save(taskExecutionComplete, null);
	mockMvc.perform(get("/tasks/definitions/myTask3").param("manifest", "true").accept(MediaType.APPLICATION_JSON))
			.andDo(print()).andExpect(status().isOk());

}
 
Example 2
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTaskExecutionNoParamMaxExitMessageSize() {
	SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
			new TaskExecutionDaoFactoryBean(this.dataSource));
	simpleTaskRepository.setMaxExitMessageSize(5);

	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
	expectedTaskExecution.setExitMessage(
			new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			simpleTaskRepository);
	assertThat(actualTaskExecution.getExitMessage().length()).isEqualTo(5);
}
 
Example 3
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTaskExecutionNoParamMaxErrorMessageSize() {
	SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
			new TaskExecutionDaoFactoryBean(this.dataSource));
	simpleTaskRepository.setMaxErrorMessageSize(5);

	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
	expectedTaskExecution.setErrorMessage(
			new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			simpleTaskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
}
 
Example 4
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
private void verifyTaskRepositoryConstructor(Integer maxExitMessage,
		Integer maxErrorMessage, TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(taskRepository);
	expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1]));
	expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);

	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			taskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length())
			.isEqualTo(maxErrorMessage.intValue());
	assertThat(actualTaskExecution.getExitMessage().length())
			.isEqualTo(maxExitMessage.intValue());
}
 
Example 5
Source File: ComposedTaskStepExecutionListenerTests.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
private TaskExecution getDefaultTaskExecution (int exitCode,
		String exitMessage) {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setExitMessage(exitMessage);
	taskExecution.setExitCode(exitCode);
	taskExecution.setEndTime(new Date());
	return taskExecution;
}
 
Example 6
Source File: TaskExecutionResourceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
public void testTaskExecutionStatusWithSuccessfulTaskExecution()  {
	final TaskExecution taskExecution = new TaskExecution();
	taskExecution.setStartTime(new Date());
	taskExecution.setEndTime(new Date());
	taskExecution.setExitCode(0);
	final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
	assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
}
 
Example 7
Source File: TaskExecutionResourceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
public void testTaskExecutionStatusWithFailedTaskExecution()  {
	final TaskExecution taskExecution = new TaskExecution();
	taskExecution.setStartTime(new Date());
	taskExecution.setEndTime(new Date());
	taskExecution.setExitCode(123);
	final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
	assertEquals(TaskExecutionStatus.ERROR, taskExecutionResource.getTaskExecutionStatus());
}
 
Example 8
Source File: ComposedTaskStepExecutionListenerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private TaskExecution getDefaultTaskExecution (int exitCode,
		String exitMessage) {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setExitMessage(exitMessage);
	taskExecution.setExitCode(exitCode);
	taskExecution.setEndTime(new Date());
	return taskExecution;
}
 
Example 9
Source File: TaskControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Before
public void setupMockMVC() {
	this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
			.defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build();

	launcherRepository.save(new Launcher("default", "local", taskLauncher));
	when(taskLauncher.launch(any(AppDeploymentRequest.class))).thenReturn("testID");


	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put("app.test.key1", "value1");
	TaskManifest taskManifest = new TaskManifest();
	AppDeploymentRequest request = new AppDeploymentRequest(new AppDefinition("test", Collections.emptyMap()), new FileSystemResource(""), deploymentProperties, null);
	taskManifest.setTaskDeploymentRequest(request);
	taskManifest.setPlatformName("test");

	final TaskExecution taskExecutionRunning = this.taskExecutionCreationService.createTaskExecution("myTask");
	taskExecutionRunning.setStartTime(new Date());
	when(taskExplorer.getLatestTaskExecutionForTaskName("myTask")).thenReturn(taskExecutionRunning);
	when(taskExplorer.getTaskExecution(taskExecutionRunning.getExecutionId())).thenReturn(taskExecutionRunning);
	this.dataflowTaskExecutionMetadataDao.save(taskExecutionRunning, taskManifest);

	final TaskExecution taskExecutionComplete = this.taskExecutionCreationService.createTaskExecution("myTask2");
	taskExecutionComplete.setTaskName("myTask2");
	taskExecutionComplete.setStartTime(new Date());
	taskExecutionComplete.setEndTime(new Date());
	taskExecutionComplete.setExitCode(0);
	when(taskExplorer.getLatestTaskExecutionForTaskName("myTask2")).thenReturn(taskExecutionComplete);
	when(taskExplorer.getTaskExecution(taskExecutionComplete.getExecutionId())).thenReturn(taskExecutionComplete);
	when(taskExplorer.getLatestTaskExecutionsByTaskNames(any()))
			.thenReturn(Arrays.asList(taskExecutionRunning, taskExecutionComplete));
	this.dataflowTaskExecutionMetadataDao.save(taskExecutionComplete, taskManifest);
}
 
Example 10
Source File: MapTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
		String exitMessage, String errorMessage) {
	if (!this.taskExecutions.containsKey(executionId)) {
		throw new IllegalStateException(
				"Invalid TaskExecution, ID " + executionId + " not found.");
	}

	TaskExecution taskExecution = this.taskExecutions.get(executionId);
	taskExecution.setEndTime(endTime);
	taskExecution.setExitCode(exitCode);
	taskExecution.setExitMessage(exitMessage);
	taskExecution.setErrorMessage(errorMessage);
}
 
Example 11
Source File: SimpleTaskRepositoryMapTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteTaskExecution() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = TaskExecutionCreator
			.completeExecution(this.taskRepository, expectedTaskExecution);
	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 12
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext
public void testCompleteTaskExecution() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(77);
	expectedTaskExecution.setExitMessage(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = TaskExecutionCreator
			.completeExecution(this.taskRepository, expectedTaskExecution);
	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 13
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext
public void testCreateTaskExecutionNoParamMaxExitDefaultMessageSize() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setExitMessage(
			new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			this.taskRepository);
	assertThat(actualTaskExecution.getExitMessage().length())
			.isEqualTo(SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE);
}
 
Example 14
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setErrorMessage(
			new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			this.taskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length())
			.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
}
 
Example 15
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@DirtiesContext
public void testCreateTaskExecutionNegativeException() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(-1);

	TaskExecution actualTaskExecution = TaskExecutionCreator
			.completeExecution(this.taskRepository, expectedTaskExecution);
	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}