Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Mar 18, 2008 · 3 comments
Closed
Labels
in: build status: ideal-for-contribution Issues that are ideal for contribution by the community type: task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Dave Syer opened BATCH-488 and commented

CI builds against various database platforms.


Affects: 1.0.0.rc1

2 votes, 0 watchers

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

Lucas Ward commented

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

@fmbenhassine fmbenhassine added in: build and removed status: waiting-for-triage Issues that we did not analyse yet in: core labels Jan 26, 2021
@fmbenhassine fmbenhassine added this to the 5.0.0 milestone Jan 26, 2021
@fmbenhassine
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: build status: ideal-for-contribution Issues that are ideal for contribution by the community type: task
Projects
None yet
Development

No branches or pull requests

2 participants