Skip to content

CI builds against various database platforms [BATCH-488]Β #3092

Closed

Description

@spring-projects-issues

Dave Syer opened BATCH-488 and commented

CI builds against various database platforms.


Affects: 1.0.0.rc1

2 votes, 0 watchers

Activity

  1. spring-projects-issues commented on Apr 21, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Lucas Ward commented

    Ben,

    Should we go ahead and move this to be a 1.1 issue? Given our discussion last week, it doesn't sound like you will have availability to look at it until next month, after 1.0.1 should go out.

  2. spring-projects-issues commented on Jun 23, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Lucas Ward commented

    Considering the release timeline...I don't see how this could be done by 1.1, moving to 2.0.

  3. added this to the 5.0.0 milestone on Jan 26, 2021
  4. fmbenhassine commented on Jan 27, 2021

    @fmbenhassine
    Contributor

    This is now relatively easy to setup thanks to docker and testcontainers. Here is a quick example for postgresql:

    import javax.sql.DataSource;
    
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.ClassRule;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.postgresql.ds.PGSimpleDataSource;
    import org.testcontainers.containers.PostgreSQLContainer;
    
    import org.springframework.batch.core.ExitStatus;
    import org.springframework.batch.core.Job;
    import org.springframework.batch.core.JobExecution;
    import org.springframework.batch.core.JobParameters;
    import org.springframework.batch.core.JobParametersBuilder;
    import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
    import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
    import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
    import org.springframework.batch.core.launch.JobLauncher;
    import org.springframework.batch.repeat.RepeatStatus;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringRunner;
    
    /**
     * @author Mahmoud Ben Hassine
     */
    @RunWith(SpringRunner.class)
    @ContextConfiguration
    public class PostgreSQLJdbcJobRepositoryTests {
    
    	@ClassRule
    	public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>();
    
    	@Autowired
    	private DataSource dataSource;
    	@Autowired
    	private JobLauncher jobLauncher;
    	@Autowired
    	private Job job;
    
    	@Before
    	public void setUp() {
    		ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    		databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-postgresql.sql"));
    		databasePopulator.execute(this.dataSource);
    	}
    
    	@Test
    	public void testJobOnPostgreSQL() throws Exception {
    		// given
    		JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
    
    		// when
    		JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
    
    		// then
    		Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    	}
    
    	@Configuration
    	@EnableBatchProcessing
    	static class TestConfiguration {
    
    		@Bean
    		public DataSource dataSource() {
    			PGSimpleDataSource dataSource = new PGSimpleDataSource();
    			dataSource.setDatabaseName(postgreSQLContainer.getDatabaseName());
    			dataSource.setUrl(postgreSQLContainer.getJdbcUrl());
    			dataSource.setUser(postgreSQLContainer.getUsername());
    			dataSource.setPassword(postgreSQLContainer.getPassword());
    			return dataSource;
    		}
    
    		@Bean
    		public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
    			return jobs.get("job")
    					.start(steps.get("step")
    							.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
    							.build())
    					.build();
    		}
    
    	}
    }

    The release acceptance test suite (part of the nightly CI build) should contain at least one such test for each supported database. All supported non-embeddable databases already provide official docker images (mysql, postgresql, db2, oracle, sqlserver and sybase). For embeddable databases (hsqldb, h2, derby and sqlite), the test is not required to be based on docker, using an EmbeddedDataSource is enough.

  5. added a commit that references this issue on Jul 26, 2021
    0ae44c8
  6. modified the milestones: 5.0.0, 5.0.0-M1 on Aug 16, 2021
  7. added a commit that references this issue on Mar 2, 2024
    a031637
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions