@Test public void testRenamePrefix() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.name:batchtest", "spring.batch.schema:classpath:batch/custom-schema-hsql.sql", "spring.batch.tablePrefix:PREFIX_"); this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(JobLauncher.class)).isNotNull(); assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty(); JobExplorer jobExplorer = this.context.getBean(JobExplorer.class); assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty(); JobRepository jobRepository = this.context.getBean(JobRepository.class); assertThat(jobRepository.getLastJobExecution("test", new JobParameters())) .isNull(); }
@Before public void init() throws Exception { this.context.register(BatchConfiguration.class); this.context.refresh(); JobRepository jobRepository = this.context.getBean(JobRepository.class); this.jobLauncher = this.context.getBean(JobLauncher.class); this.jobs = new JobBuilderFactory(jobRepository); PlatformTransactionManager transactionManager = this.context .getBean(PlatformTransactionManager.class); this.steps = new StepBuilderFactory(jobRepository, transactionManager); this.step = this.steps.get("step").tasklet(new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { return null; } }).build(); this.job = this.jobs.get("job").start(this.step).build(); this.jobExplorer = this.context.getBean(JobExplorer.class); this.runner = new JobLauncherCommandLineRunner(this.jobLauncher, this.jobExplorer); this.context.getBean(BatchConfiguration.class).clear(); }
@Test public void testRenamePrefix() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.name:batchtest", "spring.batch.schema:classpath:batch/custom-schema-hsql.sql", "spring.batch.tablePrefix:PREFIX_"); this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertNotNull(this.context.getBean(JobLauncher.class)); assertEquals(0, new JdbcTemplate(this.context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION").size()); JobExplorer jobExplorer = this.context.getBean(JobExplorer.class); assertEquals(0, jobExplorer.findRunningJobExecutions("test").size()); JobRepository jobRepository = this.context.getBean(JobRepository.class); assertNull(jobRepository.getLastJobExecution("test", new JobParameters())); }
public static void main(String[] args) throws Exception { ServerConfigHelper.initLog4j("log4j-shell.xml"); ClassPathXmlApplicationContext ctx = Util.initContext("batch/new-context.xml","batch-file-ac01.xml"); JobLauncher launch = ctx.getBean(JobLauncher.class); JobExplorer epl=ctx.getBean(JobExplorer.class); JobRegistry reg =ctx.getBean(JobRegistry.class); JobOperator jop=ctx.getBean(JobOperator.class); System.out.println(epl.getJobNames()+" "+reg.getJobNames()+" "+jop.toString()); for(String bn: ctx.getBeanFactory().getBeanDefinitionNames()) { System.out.println(bn); } ctx.close(); }
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(); }
public JobServiceImpl(JobExplorer jobExplorer, JobOperator jobOperator, JobLauncher jobLauncher, JobRegistry jobRegistry, JobRepository jobRepository) { this.jobExplorer = jobExplorer; this.jobOperator = jobOperator; this.jobLauncher = jobLauncher; this.jobRegistry = jobRegistry; this.jobRepository = jobRepository; }
@Bean public JobService jobService(JobOperator batchJobOperator, JobRegistry batchJobRegistry, JobExplorer jobExplorer, JobLauncher jobLauncher, JobRepository jobRepository) throws Exception { return new JobServiceImpl(jobExplorer, batchJobOperator, jobLauncher, batchJobRegistry, jobRepository); }
@Bean @ConditionalOnMissingBean(JobExplorer.class) public JobExplorer getJobExplorer() throws Exception { BatchConfigurer batchConfigurer = getBatchConfigurer(); if (batchConfigurer != null) { return batchConfigurer.getJobExplorer(); } JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean(); jobExplorerFactoryBean.setDataSource(dataSource); return jobExplorerFactoryBean.getObject(); }
@Bean @ConditionalOnMissingBean(JobService.class) public JobService jobService(JobOperator batchJobOperator, JobRegistry batchJobRegistry, JobExplorer jobExplorer, JobLauncher jobLauncher, JobRepository jobRepository) throws Exception { return new JobServiceImpl(jobExplorer, batchJobOperator, jobLauncher, batchJobRegistry, jobRepository); }
@Bean public JobExplorer jobExplorer() throws Exception { JobExplorerFactoryBean factory = new JobExplorerFactoryBean(); factory.setDataSource(dataSource); factory.afterPropertiesSet(); return factory.getObject(); }
@Bean public JobExplorer jobExplorer() throws Exception { MapJobExplorerFactoryBean mapJobExplorerFactoryBean = new MapJobExplorerFactoryBean(); mapJobExplorerFactoryBean.setRepositoryFactory(jobRepository()); mapJobExplorerFactoryBean.afterPropertiesSet(); return mapJobExplorerFactoryBean.getObject(); }
protected JobExplorer createJobExplorer() throws Exception { JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean(); jobExplorerFactoryBean.setDataSource(this.dataSource); String tablePrefix = this.properties.getTablePrefix(); if (StringUtils.hasText(tablePrefix)) { jobExplorerFactoryBean.setTablePrefix(tablePrefix); } jobExplorerFactoryBean.afterPropertiesSet(); return jobExplorerFactoryBean.getObject(); }
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true) public JobLauncherCommandLineRunner jobLauncherCommandLineRunner( JobLauncher jobLauncher, JobExplorer jobExplorer) { JobLauncherCommandLineRunner runner = new JobLauncherCommandLineRunner( jobLauncher, jobExplorer); String jobNames = this.properties.getJob().getNames(); if (StringUtils.hasText(jobNames)) { runner.setJobNames(jobNames); } return runner; }
@Bean @ConditionalOnMissingBean @ConditionalOnBean(DataSource.class) public JobExplorer jobExplorer(DataSource dataSource) throws Exception { JobExplorerFactoryBean factory = new JobExplorerFactoryBean(); factory.setDataSource(dataSource); String tablePrefix = this.properties.getTablePrefix(); if (StringUtils.hasText(tablePrefix)) { factory.setTablePrefix(tablePrefix); } factory.afterPropertiesSet(); return factory.getObject(); }
@Bean @ConditionalOnMissingBean(JobOperator.class) public SimpleJobOperator jobOperator(JobExplorer jobExplorer, JobLauncher jobLauncher, ListableJobLocator jobRegistry, JobRepository jobRepository) throws Exception { SimpleJobOperator factory = new SimpleJobOperator(); factory.setJobExplorer(jobExplorer); factory.setJobLauncher(jobLauncher); factory.setJobRegistry(jobRegistry); factory.setJobRepository(jobRepository); if (this.jobParametersConverter != null) { factory.setJobParametersConverter(this.jobParametersConverter); } return factory; }
@Test public void testDefaultContext() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(JobLauncher.class)).isNotNull(); assertThat(this.context.getBean(JobExplorer.class)).isNotNull(); assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty(); }
@Test public void testNoDatabase() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestCustomConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(JobLauncher.class)).isNotNull(); JobExplorer explorer = this.context.getBean(JobExplorer.class); assertThat(explorer).isNotNull(); assertThat(explorer.getJobInstances("job", 0, 100)).isEmpty(); }
@Override public JobExplorer getJobExplorer() throws Exception { MapJobExplorerFactoryBean explorer = new MapJobExplorerFactoryBean( this.factory); explorer.afterPropertiesSet(); return explorer.getObject(); }
private JobExplorer createJobExplorer() throws Exception { JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean(); jobExplorerFactoryBean.setDataSource(this.dataSource); String tablePrefix = this.properties.getTablePrefix(); if (StringUtils.hasText(tablePrefix)) { jobExplorerFactoryBean.setTablePrefix(tablePrefix); } jobExplorerFactoryBean.afterPropertiesSet(); return jobExplorerFactoryBean.getObject(); }
@Test public void testDefaultContext() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertNotNull(this.context.getBean(JobLauncher.class)); assertNotNull(this.context.getBean(JobExplorer.class)); assertEquals(0, new JdbcTemplate(this.context.getBean(DataSource.class)) .queryForList("select * from BATCH_JOB_EXECUTION").size()); }
@Test public void testNoDatabase() throws Exception { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestCustomConfiguration.class, BatchAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertNotNull(this.context.getBean(JobLauncher.class)); JobExplorer explorer = this.context.getBean(JobExplorer.class); assertNotNull(explorer); assertEquals(0, explorer.getJobInstances("job", 0, 100).size()); }
public static void main(String[] args) { try { ServerConfigHelper.initConfig(); ServerConfigHelper.initLog4j("log4j-debug.xml"); ClassPathXmlApplicationContext ctx = Util.initContext("batch/new-context.xml"); JobLauncher launch = ctx.getBean(JobLauncher.class); JobExplorer epl=ctx.getBean(JobExplorer.class); JobRegistry reg =ctx.getBean(JobRegistry.class); JobOperator jop=ctx.getBean(JobOperator.class); ClassPathXmlApplicationContext ctx2 = Util.initContext(false,"batch/job-context.xml","batch-file-prod.xml"); ctx2.setParent(ctx); ctx2.refresh(); Job job = ctx2.getBean(Job.class); JobParametersBuilder build = new JobParametersBuilder(); build.addLong("Id", System.currentTimeMillis()); JobExecution exec= launch.run(job,build.toJobParameters()); System.out.println(reg.getJobNames()); Thread.sleep(Long.MAX_VALUE); } catch (Exception e) { e.printStackTrace(); } }
public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource, String stepName) { Assert.notNull(taskLauncher, "A taskLauncher is required"); Assert.notNull(jobExplorer, "A jobExplorer is required"); Assert.notNull(resource, "A resource is required"); Assert.hasText(stepName, "A step name is required"); this.taskLauncher = taskLauncher; this.jobExplorer = jobExplorer; this.resource = resource; this.stepName = stepName; }
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer, JobRepository jobRepository) { Assert.notNull(beanFactory, "A beanFactory is required"); Assert.notNull(jobExplorer, "A jobExplorer is required"); Assert.notNull(jobRepository, "A jobRepository is required"); this.stepLocator = new BeanFactoryStepLocator(); ((BeanFactoryStepLocator) this.stepLocator).setBeanFactory(beanFactory); this.jobExplorer = jobExplorer; this.jobRepository = jobRepository; }
private void validateConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource, String stepName, String expectedMessage) { try { new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName); } catch (IllegalArgumentException iae) { assertEquals(expectedMessage, iae.getMessage()); } }
private void validateConstructorValidation(BeanFactory beanFactory, JobExplorer jobExplorer, JobRepository jobRepository, String message) { try { new DeployerStepExecutionHandler(beanFactory, jobExplorer, jobRepository); } catch (IllegalArgumentException iae) { assertEquals(message, iae.getMessage()); } }