List of usage examples for org.springframework.batch.core JobExecution getStepExecutions
public Collection<StepExecution> getStepExecutions()
From source file:org.cloudfoundry.identity.uaa.scim.job.UserSyncJobIntegrationTests.java
@Test public void testJobRunsWithNoFilters() throws Exception { Date dateInThePast = new Date(System.currentTimeMillis() - 10000); setUpModifiedUaaData(dateInThePast); JobExecution execution = jobLauncher.run(job, new JobParametersBuilder() .addDate("start.date", new Date(System.currentTimeMillis() - 100000)).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); StepExecution stepExecution = execution.getStepExecutions().iterator().next(); assertEquals(3, stepExecution.getReadCount()); assertEquals(0, stepExecution.getFilterCount()); // No records are updated, but the filter count is always write - read assertEquals(3, stepExecution.getWriteCount()); }
From source file:de.langmi.spring.batch.templates.importfile.generic.GenericJobConfigurationTest.java
/** Launch Test. */ @Test//from www .ja v a 2s . c o m public void launchJob() throws Exception { // Job parameters, commit.rate is set with properties file and Spring placeholder Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>(); jobParametersMap.put("time", new JobParameter(System.currentTimeMillis())); jobParametersMap.put("input.files", new JobParameter("file:src/test/resources/input/generic/*.txt")); // launch the job JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap)); // assert job run status assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // assert read/written items for (StepExecution stepExecution : jobExecution.getStepExecutions()) { assertEquals(EXPECTED_COUNT, stepExecution.getReadCount()); assertEquals(EXPECTED_COUNT, stepExecution.getWriteCount()); } // assert items are written successfully to database assertEquals(EXPECTED_COUNT, jdbcTemplate.queryForInt(COUNT_SQL)); }
From source file:de.langmi.spring.batch.templates.importfile.multiplefiles.MultipleFilesJobConfigurationTest.java
/** Launch Test. */ @Test//from w w w . j a v a 2 s .c om public void launchJob() throws Exception { // Job parameters, commit.rate is set with properties file and Spring placeholder Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>(); jobParametersMap.put("time", new JobParameter(System.currentTimeMillis())); jobParametersMap.put("input.files", new JobParameter("file:src/test/resources/input/multiplefiles/*.txt")); // launch the job JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap)); // assert job run status assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // assert read/written items for (StepExecution stepExecution : jobExecution.getStepExecutions()) { assertEquals(EXPECTED_COUNT, stepExecution.getReadCount()); assertEquals(EXPECTED_COUNT, stepExecution.getWriteCount()); } // assert items are written successfully to database assertEquals(EXPECTED_COUNT, jdbcTemplate.queryForInt(COUNT_SQL)); }
From source file:de.langmi.spring.batch.templates.importfile.onefile.OneFileJobConfigurationTest.java
/** Launch Test. */ @Test//from ww w . j a v a 2s . c o m public void launchJob() throws Exception { // Job parameters, commit.rate is set with properties file and Spring placeholder Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>(); jobParametersMap.put("time", new JobParameter(System.currentTimeMillis())); jobParametersMap.put("input.file", new JobParameter("file:src/test/resources/input/onefile/input.txt")); // launch the job JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap)); // assert job run status assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // assert read/written items for (StepExecution stepExecution : jobExecution.getStepExecutions()) { assertEquals(EXPECTED_COUNT, stepExecution.getReadCount()); assertEquals(EXPECTED_COUNT, stepExecution.getWriteCount()); } // assert items are written successfully to database assertEquals(EXPECTED_COUNT, jdbcTemplate.queryForInt(COUNT_SQL)); }
From source file:uk.ac.ebi.eva.pipeline.jobs.AnnotationJobTest.java
@Test public void noVariantsToAnnotateOnlyFindVariantsToAnnotateStepShouldRun() throws Exception { JobExecution jobExecution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); Assert.assertEquals(1, jobExecution.getStepExecutions().size()); StepExecution findVariantsToAnnotateStep = new ArrayList<>(jobExecution.getStepExecutions()).get(0); assertEquals(FIND_VARIANTS_TO_ANNOTATE, findVariantsToAnnotateStep.getStepName()); assertTrue(vepInputFile.exists());// w ww .java2s .com assertTrue(Files.size(Paths.get(vepInputFile.toPath().toUri())) == 0); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapExecutionContextDao.java
/** * Removes all the executionContexts for given jobExecution (Including all the stepExecutions * related to the jobExecution)//w w w. j a v a 2s .com * @param jobExecution */ public void removeExecutionContext(JobExecution jobExecution) { contexts.remove(ContextKey.job(jobExecution.getId())); //No point storing StepExecutionCOntext if jobexecutioncontext have been deleted for (StepExecution stepExecution : jobExecution.getStepExecutions()) { this.removeExecutionContext(stepExecution); } }
From source file:org.cloudfoundry.identity.uaa.scim.job.UserMigrationJobIntegrationTests.java
@Test public void testJobRuns() throws Exception { TestUtils.deleteFrom(cloudControllerDataSource, "users"); TestUtils.deleteFrom(uaaDataSource, "users"); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "invalid", "ENCRYPT_ME", new Date(), new Date()); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date()); JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addString("users", "marissa@test.org,vcap_tester@vmware.com") .addLong("run.id", 0L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); Iterator<StepExecution> iterator = execution.getStepExecutions().iterator(); assertEquals(1, iterator.next().getWriteCount()); assertEquals(1, iterator.next().getWriteCount()); JdbcTemplate jdbcTemplate = new JdbcTemplate(uaaDataSource); assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users")); assertEquals(1,/*from w w w. j a v a 2 s . co m*/ jdbcTemplate.queryForInt("select count(*) from users where authorities=?", "uaa.admin,uaa.user")); }
From source file:org.cloudfoundry.identity.uaa.scim.job.UserMigrationJobIntegrationTests.java
@Test public void testJobRunsWithSkips() throws Exception { TestUtils.runScript(uaaDataSource, "add-name-constraints"); TestUtils.deleteFrom(cloudControllerDataSource, "users"); TestUtils.deleteFrom(uaaDataSource, "users"); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "invalid", "ENCRYPT_ME", new Date(), new Date()); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date()); JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addString("users", "marissa@test.org,vcap_tester@vmware.com") .addLong("run.id", 1L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); Iterator<StepExecution> iterator = execution.getStepExecutions().iterator(); assertEquals(1, iterator.next().getWriteSkipCount()); assertEquals(1, iterator.next().getWriteCount()); JdbcTemplate jdbcTemplate = new JdbcTemplate(uaaDataSource); assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users")); assertEquals(1,//w ww. j av a 2s . c o m jdbcTemplate.queryForInt("select count(*) from users where authorities=?", "uaa.admin,uaa.user")); }
From source file:org.trpr.platform.batch.impl.spring.jmx.BatchMetricsExporter.java
/** * Helper method to register all job steps with JMX *//*from ww w . ja v a2s . c o m*/ private void registerSteps() { for (String jobName : this.jobAdministrator.getJobService().listJobs(0, Integer.MAX_VALUE)) { Collection<JobExecution> jobExecutions = Collections.emptySet(); try { jobExecutions = this.jobAdministrator.getJobService().listJobExecutionsForJob(jobName, 0, 1); } catch (NoSuchJobException e) { // do-nothing LOGGER.error("Job listed but does not exist", e); } for (JobExecution jobExecution : jobExecutions) { for (StepExecution stepExecution : jobExecution.getStepExecutions()) { String stepName = stepExecution.getStepName(); String stepKey = String.format("%s/%s", jobName, stepName); if (!this.stepKeys.contains(stepKey)) { this.stepKeys.add(stepKey); registerBeanNameOrInstance( new SimpleStepExecutionMetrics(this.jobAdministrator.getJobService(), jobName, stepName), getBeanKeyForStepExecution(jobName, stepName)); } } } } }
From source file:uk.ac.ebi.eva.pipeline.jobs.AnnotationJobTest.java
@Test public void allAnnotationStepsShouldBeExecuted() throws Exception { String dump = PopulationStatisticsJobTest.class.getResource("/dump/").getFile(); JobTestUtils.restoreMongoDbFromDump(dump); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); Assert.assertEquals(3, jobExecution.getStepExecutions().size()); List<StepExecution> steps = new ArrayList<>(jobExecution.getStepExecutions()); StepExecution findVariantsToAnnotateStep = steps.get(0); StepExecution generateVepAnnotationsStep = steps.get(1); StepExecution loadVepAnnotationsStep = steps.get(2); Assert.assertEquals(FIND_VARIANTS_TO_ANNOTATE, findVariantsToAnnotateStep.getStepName()); Assert.assertEquals(GENERATE_VEP_ANNOTATION, generateVepAnnotationsStep.getStepName()); Assert.assertEquals(LOAD_VEP_ANNOTATION, loadVepAnnotationsStep.getStepName()); //check list of variants without annotation output file assertTrue(vepInputFile.exists());/*from w ww. ja va 2 s . co m*/ assertEquals("20\t60343\t60343\tG/A\t+", JobTestUtils.readFirstLine(vepInputFile)); //check that documents have the annotation DBCursor cursor = collection(dbName, jobOptions.getDbCollectionsVariantsName()).find(); int cnt = 0; int consequenceTypeCount = 0; while (cursor.hasNext()) { cnt++; DBObject dbObject = (DBObject) cursor.next().get("annot"); if (dbObject != null) { VariantAnnotation annot = converter.convertToDataModelType(dbObject); assertNotNull(annot.getConsequenceTypes()); consequenceTypeCount += annot.getConsequenceTypes().size(); } } assertEquals(300, cnt); assertEquals(536, consequenceTypeCount); //check that one line is skipped because malformed List<StepExecution> variantAnnotationLoadStepExecution = jobExecution.getStepExecutions().stream() .filter(stepExecution -> stepExecution.getStepName().equals(LOAD_VEP_ANNOTATION)) .collect(Collectors.toList()); assertEquals(1, variantAnnotationLoadStepExecution.get(0).getReadSkipCount()); }