@Test public void testCreateGenericArchive() throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, IOException { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); JobParameters jobParameters = new JobParameters(parameters); Job palmwebArchive = jobLocator.getJob("PalmWeb"); assertNotNull("Palmweb must not be null", palmwebArchive); JobExecution jobExecution = jobLauncher.run(palmwebArchive, jobParameters); assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { logger.info(stepExecution.getStepName() + " " + stepExecution.getReadCount() + " " + stepExecution.getFilterCount() + " " + stepExecution.getWriteCount() + " " + stepExecution.getCommitCount()); } }
@Test public void testSequentialAndSplit() { setupContextForGraph("AAA && <BBB||CCC||DDD> && EEE"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(5, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("DDD_0")); assertTrue(stepNames.contains("EEE_0")); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("EEE_0", sortedStepExecution.get(4).getStepName()); }
@Test public void testSequentialTransitionAndSplit() { setupContextForGraph("AAA && FFF 'FAILED' -> EEE && <BBB||CCC> && DDD"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(5, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("DDD_0")); assertTrue(stepNames.contains("FFF_0")); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("DDD_0", sortedStepExecution.get(4).getStepName()); }
@Test public void testSequentialAndSplitWithFlow() { setupContextForGraph("AAA && <BBB && FFF||CCC||DDD> && EEE"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(6, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("DDD_0")); assertTrue(stepNames.contains("EEE_0")); assertTrue(stepNames.contains("FFF_0")); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("EEE_0", sortedStepExecution.get(5).getStepName()); }
@Override public SimpleStep convert(StepExecution source, SimpleStep simpleStep) { SimpleStep target = simpleStep != null ? simpleStep : new SimpleStep(); target.stepName(source.getStepName()) .status(source.getStatus().toString()) .readCount(source.getReadCount()) .writeCount(source.getWriteCount()) .commitCount(source.getCommitCount()) .rollbackCount(source.getRollbackCount()) .readSkipCount(source.getReadSkipCount()) .processSkipCount(source.getProcessSkipCount()) .writeSkipCount(source.getWriteSkipCount()) .startTime(source.getStartTime()) .endTime(source.getEndTime()) .exitStatus(source.getExitStatus().toString()) .lastUpdated(source.getLastUpdated()) .exitStatus(source.getExitStatus().toString()); return target; }
private static void createSampleJob(String jobName, int jobExecutionCount) { JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters()); jobInstances.add(instance); TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<String>(), null); Map<String, JobParameter> jobParameterMap = new HashMap<>(); jobParameterMap.put("foo", new JobParameter("FOO", true)); jobParameterMap.put("bar", new JobParameter("BAR", false)); JobParameters jobParameters = new JobParameters(jobParameterMap); JobExecution jobExecution = null; for (int i = 0; i < jobExecutionCount; i++) { jobExecution = jobRepository.createJobExecution(instance, jobParameters, null); taskBatchDao.saveRelationship(taskExecution, jobExecution); StepExecution stepExecution = new StepExecution("foobar", jobExecution); jobRepository.add(stepExecution); } }
@Override public ExitStatus afterStep(StepExecution step) { List<Throwable> exceptions = step.getFailureExceptions(); if(exceptions != null && !exceptions.isEmpty()){ ExitStatus exitStatus = new ExitStatus("DELETE FAILED"); for(Throwable exception : exceptions){ if(ResourceIsNotDeletableException.class.isInstance(exception.getCause())){ String message = exception.getMessage(); if(message != null){ exitStatus.addExitDescription(message); logger.debug(exitStatus.toString()); return exitStatus; } }else{ exitStatus.addExitDescription("unknown failure - this resource could not be deleted"); logger.debug(exitStatus.toString()); return exitStatus; } } } logger.debug("READY FOR DELETE"); return new ExitStatus("READY FOR DELETE"); }
public void append(StepExecution stepExecution) { if (stepExecution.getEndTime() == null) { // ignore unfinished executions return; } Date startTime = stepExecution.getStartTime(); Date endTime = stepExecution.getEndTime(); long time = endTime.getTime() - startTime.getTime(); duration.append(time); if (stepExecution.getReadCount() > 0) { durationPerRead.append(time / stepExecution.getReadCount()); } count++; commitCount.append(stepExecution.getCommitCount()); rollbackCount.append(stepExecution.getRollbackCount()); readCount.append(stepExecution.getReadCount()); writeCount.append(stepExecution.getWriteCount()); filterCount.append(stepExecution.getFilterCount()); readSkipCount.append(stepExecution.getReadSkipCount()); writeSkipCount.append(stepExecution.getWriteSkipCount()); processSkipCount.append(stepExecution.getProcessSkipCount()); }
private void assertCorrectMixins(RestTemplate restTemplate) { boolean containsMappingJackson2HttpMessageConverter = false; for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) { if (converter instanceof MappingJackson2HttpMessageConverter) { containsMappingJackson2HttpMessageConverter = true; final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter; final ObjectMapper objectMapper = jacksonConverter.getObjectMapper(); assertNotNull(objectMapper.findMixInClassFor(JobExecution.class)); assertNotNull(objectMapper.findMixInClassFor(JobParameters.class)); assertNotNull(objectMapper.findMixInClassFor(JobParameter.class)); assertNotNull(objectMapper.findMixInClassFor(JobInstance.class)); assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class)); assertNotNull(objectMapper.findMixInClassFor(StepExecution.class)); assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class)); assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class)); } } if (!containsMappingJackson2HttpMessageConverter) { fail("Expected that the restTemplate's list of Message Converters contained a " + "MappingJackson2HttpMessageConverter"); } }
/** * Retrieves Pageable list of {@link JobExecution}s from the JobRepository and matches the * data with a task id. * * @param pageable enumerates the data to be returned. * @return List containing {@link TaskJobExecution}s. */ @Override public List<TaskJobExecution> listJobExecutions(Pageable pageable) throws NoSuchJobExecutionException { Assert.notNull(pageable, "pageable must not be null"); List<JobExecution> jobExecutions = new ArrayList<>( jobService.listJobExecutions(pageable.getOffset(), pageable.getPageSize())); for (JobExecution jobExecution : jobExecutions) { Collection<StepExecution> stepExecutions = jobService.getStepExecutions(jobExecution.getId()); List<StepExecution> validStepExecutions = new ArrayList<>(); for (StepExecution stepExecution : stepExecutions) { if (stepExecution.getId() != null) { validStepExecutions.add(stepExecution); } } jobExecution.addStepExecutions(validStepExecutions); } return getTaskJobExecutionsForList(jobExecutions); }
@Before public void setupMockMVC() { this.mockMvc = MockMvcBuilders.webAppContextSetup(wac) .defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build(); if (!initialized) { createStepExecution(JOB_NAME_ORIG, STEP_NAME_ORIG); createStepExecution(JOB_NAME_FOO, STEP_NAME_ORIG, STEP_NAME_FOO); createStepExecution(JOB_NAME_FOOBAR, STEP_NAME_ORIG, STEP_NAME_FOO, STEP_NAME_FOOBAR); initialized = true; } for (HttpMessageConverter<?> converter : adapter.getMessageConverters()) { if (converter instanceof MappingJackson2HttpMessageConverter) { final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter; jacksonConverter.getObjectMapper().addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class); jacksonConverter.getObjectMapper().addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class); jacksonConverter.getObjectMapper().setDateFormat(new ISO8601DateFormatWithMilliSeconds()); } } }
/** * Assert that by using the {@link ExecutionContextJacksonMixIn} Jackson renders the * Step Execution Context correctly. * * @throws JsonProcessingException if a Json generation error occurs. */ @Test public void testSerializationOfSingleStepExecution() throws JsonProcessingException { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class); objectMapper.addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class); final StepExecution stepExecution = getStepExecution(); final String result = objectMapper.writeValueAsString(stepExecution); assertThat(result, not(containsString("\"executionContext\":{\"dirty\":true,\"empty\":false}"))); assertThat(result, containsString("\"executionContext\":{\"dirty\":true,\"empty\":false,\"values\":[{")); assertThat(result, containsString("{\"counter\":1234}")); assertThat(result, containsString("{\"myDouble\":1.123456}")); assertThat(result, containsString("{\"Josh\":4444444444}")); assertThat(result, containsString("{\"awesomeString\":\"Yep\"}")); assertThat(result, containsString("{\"hello\":\"world\"")); assertThat(result, containsString("{\"counter2\":9999}")); }
public AdaptedStepExecution(StepExecution stepExec) { this.setId(stepExec.getId()); this.setJobInstanceId(stepExec.getJobExecution().getJobInstance().getId()); this.setStepName(stepExec.getStepName()); this.setStatus(stepExec.getStatus()); this.setReadSkipCount(stepExec.getReadSkipCount()); this.setWriteSkipCount(stepExec.getWriteSkipCount()); this.setProcessSkipCount(stepExec.getProcessSkipCount()); this.setRollbackCount(stepExec.getRollbackCount()); this.setJobExecutionId(stepExec.getJobExecutionId()); this.setReadCount(stepExec.getReadCount()); this.setWriteCount(stepExec.getWriteCount()); this.setFilterCount(stepExec.getFilterCount()); this.setVersion(stepExec.getVersion()); this.setExitStatus(stepExec.getExitStatus()); this.setVersion(stepExec.getVersion()); this.setJobName(stepExec.getJobExecution().getJobInstance().getJobName()); this.setStartTime(stepExec.getStartTime()); this.setEndTime(stepExec.getEndTime()); this.setLastUpdated(stepExec.getLastUpdated()); this.setExecutionContext(stepExec.getExecutionContext()); }
public ExitStatus afterStep(StepExecution stepExecution) { logger.debug("After Step " + currentStep.getStepName()); try { Url u = new Url(); u.setLastmod(ISODateTimeFormat.dateTime().print((ReadableInstant) null)); u.setLoc(new URL(portalBaseUrl +"/" + sitemapDir + "/" + currentFile.getFilename())); sitemapNames.add(u); } catch (MalformedURLException e) { logger.error("Unable create Url for sitemap", e); } //reset counts to nulls to support beforeStep() currentStep = null; currentFile = null; chunkOfFile = 0; commitSize = 0; return stepExecution.getExitStatus(); }
/** * Constructor for the StepExecution to initialize the DTO. * * @param original the StepExecution to build this DTO around. */ public JobExecutionEvent(JobExecution original) { this.jobParameters = new JobParametersEvent(original.getJobParameters().getParameters()); this.jobInstance = new JobInstanceEvent(original.getJobInstance().getId(), original.getJobInstance().getJobName()); for(StepExecution stepExecution : original.getStepExecutions()){ stepExecutions.add(new StepExecutionEvent(stepExecution)); } this.status = original.getStatus(); this.startTime = original.getStartTime(); this.createTime = original.getCreateTime(); this.endTime = original.getEndTime(); this.lastUpdated = original.getLastUpdated(); this.exitStatus = new ExitStatus(original.getExitStatus()); this.executionContext = original.getExecutionContext(); this.failureExceptions = original.getFailureExceptions(); this.jobConfigurationName = original.getJobConfigurationName(); this.setId(original.getId()); this.setVersion(original.getVersion()); }
@Test public final void testBatchReportWriter() throws Exception { JasperReport jasperReport = JasperCompileManager.compileReport( new ClassPathResource("org/emonocot/job/download/reports/name_report1.jrxml").getInputStream()); JRVerticalReportWriter writer = new JRVerticalReportWriter(jasperReport); writer.setDefaultOutputDir("target"); StepExecution se = new StepExecution("testStep", new JobExecution(1L)); writer.beforeStep(se); int chunkSize = 10; for (int i = 0; i <= (itemsToWrite.size()/chunkSize); i++) { List<Taxon> itemList = new ArrayList<Taxon>(); for (int j = 0; j < chunkSize; j++) { try { itemList.add(itemsToWrite.get(i*chunkSize+j)); } catch (IndexOutOfBoundsException e) { break; } } writer.write(itemList); } writer.afterStep(se); }
/** * * @throws IOException * if a temporary file cannot be created. * @throws NoSuchJobException * if SpeciesPageHarvestingJob cannot be located * @throws JobParametersInvalidException * if the job parameters are invalid * @throws JobInstanceAlreadyCompleteException * if the job has already completed * @throws JobRestartException * if the job cannot be restarted * @throws JobExecutionAlreadyRunningException * if the job is already running */ @Test public final void testNotModifiedResponse() throws IOException, NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query.string", new JobParameter("select i from Image i")); JobParameters jobParameters = new JobParameters(parameters); Job job = jobLocator.getJob("ImageProcessing"); assertNotNull("ImageProcessing must not be null", job); JobExecution jobExecution = jobLauncher.run(job, jobParameters); assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { logger.info(stepExecution.getStepName() + " " + stepExecution.getReadCount() + " " + stepExecution.getFilterCount() + " " + stepExecution.getWriteCount()); } }
public JobExecutionInfo(JobExecution jobExecution, String baseUrl) { resourceIdentifier = jobExecution.getJobInstance().getJobParameters().getString("resource.identifier"); DateTime sTime = new DateTime(jobExecution.getStartTime()); DateTime eTime = new DateTime(jobExecution.getEndTime()); duration = eTime.minus(sTime.getMillis()); startTime = sTime; exitDescription = jobExecution.getExitStatus().getExitDescription(); exitCode = jobExecution.getExitStatus().getExitCode(); id = jobExecution.getId(); jobInstance = baseUrl + "/jobs/" + jobExecution.getJobInstance().getJobName() + "/" + jobExecution.getJobInstance().getId(); resource = baseUrl + "/jobs/executions/" + jobExecution.getId(); this.baseUrl = baseUrl; status = jobExecution.getStatus(); Integer writeSkip = 0; for (StepExecution stepExecution : jobExecution.getStepExecutions()) { recordsRead += stepExecution.getReadCount(); readSkip += stepExecution.getReadSkipCount(); processSkip += stepExecution.getProcessSkipCount(); written += stepExecution.getWriteCount(); writeSkip += stepExecution.getWriteSkipCount(); } }
@Test public void testJobInterruptedException() throws Exception { StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] {"workerStep", "foo", "bar"}); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn("2"); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1"); when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step); doThrow(new JobInterruptedException("expected")).when(this.step).execute(workerStep); handler.run(); verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture()); assertEquals(BatchStatus.STOPPED, this.stepExecutionArgumentCaptor.getValue().getStatus()); }
@Test public void marshallStepExecutionTest() throws Exception { JobInstance jobInstance = new JobInstance(1234L, "test"); JobExecution jobExecution = new JobExecution(123L); jobExecution.setJobInstance(jobInstance); StepExecution step = new StepExecution("testStep", jobExecution); step.setLastUpdated(new Date(System.currentTimeMillis())); StepExecutionAdapter adapter = new StepExecutionAdapter(); AdaptedStepExecution adStep = adapter.marshal(step); jaxb2Marshaller.marshal(adStep, result); Fragment frag = new Fragment(new DOMBuilder().build(doc)); frag.setNamespaces(getNamespaceProvider().getNamespaces()); frag.prettyPrint(); frag.assertElementExists("/msb:stepExecution"); frag.assertElementExists("/msb:stepExecution/msb:lastUpdated"); frag.assertElementValue("/msb:stepExecution/msb:stepName", "testStep"); }
@Test public void testRuntimeException() throws Exception { StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn(true); when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] {"workerStep", "foo", "bar"}); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).thenReturn("2"); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1"); when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep); when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn("workerStep"); when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step); doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep); handler.run(); verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture()); assertEquals(BatchStatus.FAILED, this.stepExecutionArgumentCaptor.getValue().getStatus()); }
private ChunkContext chunkContext () { final long JOB_EXECUTION_ID = 123L; final String STEP_NAME = "myTestStep"; JobExecution jobExecution = new JobExecution(JOB_EXECUTION_ID); StepExecution stepExecution = new StepExecution(STEP_NAME, jobExecution); StepContext stepContext = new StepContext(stepExecution); return new ChunkContext(stepContext); }
@Test public void singleTest() { setupContextForGraph("AAA"); Collection<StepExecution> stepExecutions = getStepExecutions(); assertEquals(1, stepExecutions.size()); StepExecution stepExecution = stepExecutions.iterator().next(); assertEquals("AAA_0", stepExecution.getStepName()); }
@Test public void testFailedGraph() { setupContextForGraph("failedStep && AAA"); Collection<StepExecution> stepExecutions = getStepExecutions(); assertEquals(1, stepExecutions.size()); StepExecution stepExecution = stepExecutions.iterator().next(); assertEquals("failedStep_0", stepExecution.getStepName()); }
@Test public void testEmbeddedFailedGraph() { setupContextForGraph("AAA && failedStep && BBB"); Collection<StepExecution> stepExecutions = getStepExecutions(); assertEquals(2, stepExecutions.size()); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("failedStep_0", sortedStepExecution.get(1).getStepName()); }
@Ignore("Disabling till parser can support duplicate tasks") @Test public void duplicateTaskTest() { setupContextForGraph("AAA && AAA"); Collection<StepExecution> stepExecutions = getStepExecutions(); assertEquals(2, stepExecutions.size()); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_1", sortedStepExecution.get(0).getStepName()); assertEquals("AAA_0", sortedStepExecution.get(1).getStepName()); }
@Test public void testSequential() { setupContextForGraph("AAA && BBB && CCC"); List<StepExecution> stepExecutions = getSortedStepExecutions(getStepExecutions()); assertEquals(3, stepExecutions.size()); Iterator<StepExecution> iterator = stepExecutions.iterator(); StepExecution stepExecution = iterator.next(); assertEquals("AAA_0", stepExecution.getStepName()); stepExecution = iterator.next(); assertEquals("BBB_0", stepExecution.getStepName()); stepExecution = iterator.next(); assertEquals("CCC_0", stepExecution.getStepName()); }
@Test public void splitTest() { setupContextForGraph("<AAA||BBB||CCC>"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(3, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("CCC_0")); }
@Test public void twoSplitTest() { setupContextForGraph("<AAA||BBB||CCC> && <DDD||EEE>"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(5, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("DDD_0")); assertTrue(stepNames.contains("EEE_0")); }
@Test public void testSequentialTransitionAndSplitFailed() { setupContextForGraph("AAA && failedStep 'FAILED' -> EEE && FFF && <BBB||CCC> && DDD"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(3, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("failedStep_0")); assertTrue(stepNames.contains("EEE_0")); }
@Test public void testSequentialAndFailedSplit() { setupContextForGraph("AAA && <BBB||failedStep||DDD> && EEE"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(4, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("BBB_0")); assertTrue(stepNames.contains("DDD_0")); assertTrue(stepNames.contains("failedStep_0")); }
@Test public void testFailedBasicTransition() { setupContextForGraph("failedStep 'FAILED' -> AAA * -> BBB"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(2, stepExecutions.size()); assertTrue(stepNames.contains("failedStep_0")); assertTrue(stepNames.contains("AAA_0")); }
@Test public void testSuccessBasicTransition() { setupContextForGraph("AAA 'FAILED' -> BBB * -> CCC"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(2, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("CCC_0")); }
@Test public void testSuccessBasicTransitionWithTransition() { setupContextForGraph("AAA 'FAILED' -> BBB && CCC 'FAILED' -> DDD '*' -> EEE"); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(3, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("EEE_0")); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("EEE_0", sortedStepExecution.get(2).getStepName()); }
@Test public void testWildCardOnlyInLastPosition() { setupContextForGraph("AAA 'FAILED' -> BBB && CCC * -> DDD "); Collection<StepExecution> stepExecutions = getStepExecutions(); Set<String> stepNames= getStepNames(stepExecutions); assertEquals(3, stepExecutions.size()); assertTrue(stepNames.contains("AAA_0")); assertTrue(stepNames.contains("CCC_0")); assertTrue(stepNames.contains("DDD_0")); List<StepExecution> sortedStepExecution = getSortedStepExecutions(stepExecutions); assertEquals("AAA_0", sortedStepExecution.get(0).getStepName()); assertEquals("DDD_0", sortedStepExecution.get(2).getStepName()); }
private Set<String> getStepNames(Collection<StepExecution> stepExecutions) { Set<String> result = new HashSet<>(); for(StepExecution stepExecution : stepExecutions) { result.add(stepExecution.getStepName()); } return result; }
private Collection<StepExecution> getStepExecutions() { JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class); List<JobInstance> jobInstances = jobExplorer.findJobInstancesByJobName("job", 0, 1); assertEquals(1, jobInstances.size()); JobInstance jobInstance = jobInstances.get(0); List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); assertEquals(1, jobExecutions.size()); JobExecution jobExecution = jobExecutions.get(0); return jobExecution.getStepExecutions(); }
private List<StepExecution> getSortedStepExecutions(Collection<StepExecution> stepExecutions) { List<StepExecution> result = new ArrayList<>(stepExecutions); Collections.sort(result, new Comparator<StepExecution>() { @Override public int compare(StepExecution stepExecution1, StepExecution stepExecution2) { return stepExecution1.getStartTime().compareTo(stepExecution2.getStartTime()); } }); return result; }
private StepExecution getStepExecution() { final long JOB_EXECUTION_ID = 123L; final String STEP_NAME = "myTestStep"; JobExecution jobExecution = new JobExecution(JOB_EXECUTION_ID); return new StepExecution(STEP_NAME, jobExecution); }
@Override public void afterJob(JobExecution jobExecution) { for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (stepExecution.getSkipCount() > 0) { jobExecution.setExitStatus(ExitStatus.FAILED); jobExecution.setStatus(BatchStatus.FAILED); return; } } }