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

The following examples show how to use org.springframework.cloud.task.repository.TaskExecution#setTaskName() . 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: MapTaskExecutionDaoTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartTaskExecution() {
	TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
			new ArrayList<>(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(),
			expectedTaskExecution.getExternalExecutionId());
	Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
			.getTaskExecutions();
	assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
			taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
}
 
Example 3
Source File: JdbcTaskExecutionDaoTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void testStartTaskExecution() {
	TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
			new ArrayList<>(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(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
			TestDBUtils.getTaskExecutionFromDB(this.dataSource,
					expectedTaskExecution.getExecutionId()));
}
 
Example 4
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void startTaskExecutionWithParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 5
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void startTaskExecutionWithNoParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 6
Source File: SimpleTaskRepositoryMapTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void startTaskExecutionWithParent() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
	expectedTaskExecution.setParentExecutionId(12345L);

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 7
Source File: SimpleTaskRepositoryMapTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void startTaskExecutionWithNoParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 8
Source File: SimpleTaskRepositoryMapTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void startTaskExecutionWithParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId(),
			expectedTaskExecution.getParentExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 9
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testMaxTaskNameSizeForConstructor() {
	final int MAX_EXIT_MESSAGE_SIZE = 10;
	final int MAX_ERROR_MESSAGE_SIZE = 20;
	final int MAX_TASK_NAME_SIZE = 30;
	SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
			new TaskExecutionDaoFactoryBean(this.dataSource), MAX_EXIT_MESSAGE_SIZE,
			MAX_TASK_NAME_SIZE, MAX_ERROR_MESSAGE_SIZE);
	TaskExecution expectedTaskExecution = TestVerifierUtils
			.createSampleTaskExecutionNoArg();
	expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1]));
	simpleTaskRepository.createTaskExecution(expectedTaskExecution);
}
 
Example 10
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testDefaultMaxTaskNameSizeForConstructor() {
	SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
			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);
}
 
Example 11
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 testCreateTaskExecutionNoParamMaxTaskName() {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName(
			new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
	taskExecution.setStartTime(new Date());
	this.taskRepository.createTaskExecution(taskExecution);
}
 
Example 12
Source File: SimpleTaskExplorerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private TaskExecution getSimpleTaskExecution() {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName(TASK_NAME);
	taskExecution.setStartTime(new Date());
	taskExecution.setExternalExecutionId(EXTERNAL_EXECUTION_ID);
	return taskExecution;
}
 
Example 13
Source File: BaseTaskExecutionDaoTestCases.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
protected TaskExecution getTaskExecution(String taskName,
		String externalExecutionId) {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName(taskName);
	taskExecution.setExternalExecutionId(externalExecutionId);
	taskExecution.setStartTime(new Date());
	return taskExecution;
}
 
Example 14
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testSinglePartition() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish = getStepExecutionFinish(
			workerStepExecutionStart, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();
	stepExecutions.add(workerStepExecutionStart);
	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);

	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);

	verify(this.taskLauncher)
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();

	assertThat(request.getResource()).isEqualTo(this.resource);
	assertThat(request.getDeploymentProperties().size()).isEqualTo(0);

	AppDefinition appDefinition = request.getDefinition();

	assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
	assertThat(request.getCommandlineArguments()
			.contains(formatArgs("spring.cloud.task.executionid", "2"))).isTrue();

	assertThat(results.size()).isEqualTo(1);
	StepExecution resultStepExecution = results.iterator().next();
	assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
	assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
 
Example 15
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreePartitionsTwoWorkers() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
			workerStepExecutionStart1, BatchStatus.COMPLETED);

	StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
	StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
			workerStepExecutionStart2, BatchStatus.COMPLETED);

	StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
	StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
			workerStepExecutionStart3, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);
	handler.setMaxWorkers(2);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();

	stepExecutions.add(workerStepExecutionStart1);
	stepExecutions.add(workerStepExecutionStart2);
	stepExecutions.add(workerStepExecutionStart3);

	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish1);
	when(this.jobExplorer.getStepExecution(1L, 5L))
			.thenReturn(workerStepExecutionFinish2);
	when(this.jobExplorer.getStepExecution(1L, 6L))
			.thenReturn(workerStepExecutionFinish3);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);
	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);

	verify(this.taskLauncher, times(3))
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
			.getAllValues();

	validateAppDeploymentRequests(allValues, 3);

	validateStepExecutionResults(results);
}
 
Example 16
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testFailedWorker() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
			workerStepExecutionStart1, BatchStatus.COMPLETED);

	StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
	StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
			workerStepExecutionStart2, BatchStatus.FAILED);

	StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
	StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
			workerStepExecutionStart3, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);
	handler.setMaxWorkers(2);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();

	stepExecutions.add(workerStepExecutionStart1);
	stepExecutions.add(workerStepExecutionStart2);
	stepExecutions.add(workerStepExecutionStart3);

	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish1);
	when(this.jobExplorer.getStepExecution(1L, 5L))
			.thenReturn(workerStepExecutionFinish2);
	when(this.jobExplorer.getStepExecution(1L, 6L))
			.thenReturn(workerStepExecutionFinish3);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);
	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);

	verify(this.taskLauncher, times(3))
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
			.getAllValues();

	validateAppDeploymentRequests(allValues, 3);

	Iterator<StepExecution> resultsIterator = results.iterator();
	Set<String> names = new HashSet<>(results.size());

	while (resultsIterator.hasNext()) {
		StepExecution curResult = resultsIterator.next();

		if (curResult.getStepName().equals("step1:partition2")) {
			assertThat(curResult.getStatus()).isEqualTo(BatchStatus.FAILED);
		}
		else {
			assertThat(curResult.getStatus()).isEqualTo(BatchStatus.COMPLETED);
		}

		assertThat(!names.contains(curResult.getStepName())).isTrue();
		names.add(curResult.getStepName());
	}
}
 
Example 17
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testOverridingEnvironmentProperties() throws Exception {

	((MockEnvironment) this.environment).setProperty("foo", "zoo");
	((MockEnvironment) this.environment).setProperty("task", "batch");

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish = getStepExecutionFinish(
			workerStepExecutionStart, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);

	Map<String, String> environmentParameters = new HashMap<>(2);
	environmentParameters.put("foo", "bar");
	environmentParameters.put("baz", "qux");

	SimpleEnvironmentVariablesProvider environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
			this.environment);
	environmentVariablesProvider.setEnvironmentProperties(environmentParameters);
	handler.setEnvironmentVariablesProvider(environmentVariablesProvider);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();
	stepExecutions.add(workerStepExecutionStart);
	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);
	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);

	verify(this.taskLauncher)
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();

	assertThat(request.getResource()).isEqualTo(this.resource);
	assertThat(request.getDefinition().getProperties().size()).isEqualTo(3);
	assertThat(request.getDefinition().getProperties().get("foo")).isEqualTo("bar");
	assertThat(request.getDefinition().getProperties().get("baz")).isEqualTo("qux");
	assertThat(request.getDefinition().getProperties().get("task"))
			.isEqualTo("batch");

	AppDefinition appDefinition = request.getDefinition();

	assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();

	assertThat(results.size()).isEqualTo(1);
	StepExecution resultStepExecution = results.iterator().next();
	assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
	assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
 
Example 18
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testPollInterval() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
			workerStepExecutionStart1, BatchStatus.COMPLETED);

	StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
	StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
			workerStepExecutionStart2, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);

	handler.setPollInterval(20000L);
	handler.setMaxWorkers(1);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();
	stepExecutions.add(workerStepExecutionStart1);
	stepExecutions.add(workerStepExecutionStart2);
	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish1);
	when(this.jobExplorer.getStepExecution(1L, 5L))
			.thenReturn(workerStepExecutionFinish2);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);

	Date startTime = new Date();
	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);
	Date endTime = new Date();
	verify(this.taskLauncher, times(2))
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor
			.getAllValues();

	validateAppDeploymentRequests(allRequests, 2);

	validateStepExecutionResults(results);

	assertThat(endTime.getTime() - startTime.getTime() >= 19999)
			.as("Time difference was too small: "
					+ (endTime.getTime() - startTime.getTime()))
			.isTrue();
}
 
Example 19
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test(expected = TimeoutException.class)
public void testTimeout() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
			workerStepExecutionStart1, BatchStatus.COMPLETED);

	StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
	StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
			workerStepExecutionStart2, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);

	handler.setPollInterval(20000L);
	handler.setMaxWorkers(1);
	handler.setTimeout(1000L);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();
	stepExecutions.add(workerStepExecutionStart1);
	stepExecutions.add(workerStepExecutionStart2);
	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish1);
	when(this.jobExplorer.getStepExecution(1L, 5L))
			.thenReturn(workerStepExecutionFinish2);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);

	handler.handle(this.splitter, masterStepExecution);
}
 
Example 20
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeployerProperties() throws Exception {

	StepExecution masterStepExecution = createMasterStepExecution();
	JobExecution jobExecution = masterStepExecution.getJobExecution();

	StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
	StepExecution workerStepExecutionFinish = getStepExecutionFinish(
			workerStepExecutionStart, BatchStatus.COMPLETED);

	DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
			this.jobExplorer, this.resource, "step1", this.taskRepository);
	handler.setEnvironment(this.environment);

	Map<String, String> deploymentProperties = new HashMap<>(2);
	deploymentProperties.put("foo", "bar");
	deploymentProperties.put("baz", "qux");

	handler.setDeploymentProperties(deploymentProperties);

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("partitionedJobTask");

	Set<StepExecution> stepExecutions = new HashSet<>();
	stepExecutions.add(workerStepExecutionStart);
	when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);

	when(this.jobExplorer.getStepExecution(1L, 4L))
			.thenReturn(workerStepExecutionFinish);

	handler.afterPropertiesSet();

	handler.beforeTask(taskExecution);
	Collection<StepExecution> results = handler.handle(this.splitter,
			masterStepExecution);

	verify(this.taskLauncher)
			.launch(this.appDeploymentRequestArgumentCaptor.capture());

	AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();

	assertThat(request.getResource()).isEqualTo(this.resource);
	assertThat(request.getDeploymentProperties().size()).isEqualTo(2);
	assertThat(request.getDeploymentProperties().get("foo")).isEqualTo("bar");
	assertThat(request.getDeploymentProperties().get("baz")).isEqualTo("qux");

	AppDefinition appDefinition = request.getDefinition();

	assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")))
					.isTrue();
	assertThat(request.getCommandlineArguments().contains(formatArgs(
			DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();

	assertThat(results.size()).isEqualTo(1);
	StepExecution resultStepExecution = results.iterator().next();
	assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
	assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}