Java Code Examples for org.springframework.batch.core.StepExecution#getJobExecution()
The following examples show how to use
org.springframework.batch.core.StepExecution#getJobExecution() .
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: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Test public void testParentExecutionId() 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(55, null, null, null, null, null, new ArrayList<>(), null, null); 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); handler.handle(this.splitter, masterStepExecution); verify(this.taskLauncher) .launch(this.appDeploymentRequestArgumentCaptor.capture()); AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue(); assertThat(request.getCommandlineArguments().contains(formatArgs( DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))) .isTrue(); }
Example 2
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart, BatchStatus status) { StepExecution workerStepExecutionFinish = new StepExecution( stepExecutionStart.getStepName(), stepExecutionStart.getJobExecution()); workerStepExecutionFinish.setId(stepExecutionStart.getId()); workerStepExecutionFinish.setStatus(status); return workerStepExecutionFinish; }
Example 3
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 4
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Test public void testSinglePartitionAsEnvVars() 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); handler.setDefaultArgsAsEnvironmentVars(true); TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null, new ArrayList<>(), null, null); 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().isEmpty()).isTrue(); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)) .isEqualTo("1"); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) .isEqualTo("4"); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)) .isEqualTo("step1"); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME)) .isEqualTo("partitionedJobTask_partitionedJob_step1:partition1"); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)) .isEqualTo("55"); assertThat(request.getDefinition().getProperties() .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID)) .isEqualTo("2"); assertThat(results.size()).isEqualTo(1); StepExecution resultStepExecution = results.iterator().next(); assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED); assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1"); }
Example 5
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Test public void testThreePartitions() 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); 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 6
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 7
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 8
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Test public void testPassingEnvironmentProperties() 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); 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(2); assertThat(request.getDefinition().getProperties().get("foo")).isEqualTo("bar"); assertThat(request.getDefinition().getProperties().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"); }
Example 9
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 10
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 11
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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 12
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Test public void testGridSize() 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.setGridSize(2); TaskExecution taskExecution = new TaskExecution(); taskExecution.setTaskName("partitionedJobTask"); Set<StepExecution> stepExecutions = new HashSet<>(); stepExecutions.add(workerStepExecutionStart1); stepExecutions.add(workerStepExecutionStart2); when(this.splitter.split(masterStepExecution, 2)).thenReturn(stepExecutions); when(this.jobExplorer.getStepExecution(1L, 4L)) .thenReturn(workerStepExecutionFinish1); when(this.jobExplorer.getStepExecution(1L, 5L)) .thenReturn(workerStepExecutionFinish2); handler.afterPropertiesSet(); handler.beforeTask(taskExecution); Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution); verify(this.taskLauncher, times(2)) .launch(this.appDeploymentRequestArgumentCaptor.capture()); List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor .getAllValues(); validateAppDeploymentRequests(allRequests, 2); validateStepExecutionResults(results); }
Example 13
Source File: DeployerPartitionHandlerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@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"); }