This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
forked from spring-projects/spring-batch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-initialize datasource before each integration test
- Loading branch information
1 parent
422c233
commit 797fe1b
Showing
5 changed files
with
309 additions
and
294 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ore-tests/src/test/java/org/springframework/batch/core/test/AbstractIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2006-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.batch.core.test; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.Before; | ||
|
||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; | ||
|
||
/** | ||
* @author Mahmoud Ben Hassine | ||
*/ | ||
public class AbstractIntegrationTests { | ||
|
||
protected DataSource dataSource; | ||
|
||
@Before | ||
public void setUp() { | ||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); | ||
databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-hsqldb.sql")); | ||
databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-hsqldb.sql")); | ||
databasePopulator.addScript(new ClassPathResource("/business-schema-hsqldb.sql")); | ||
databasePopulator.execute(this.dataSource); | ||
} | ||
|
||
} |
160 changes: 76 additions & 84 deletions
160
...c/test/java/org/springframework/batch/core/test/football/FootballJobIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,76 @@ | ||
/* | ||
* Copyright 2006-2009 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.batch.core.test.football; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.batch.core.BatchStatus; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParametersBuilder; | ||
import org.springframework.batch.core.StepExecution; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.jdbc.JdbcTestUtils; | ||
|
||
/** | ||
* @author Dave Syer | ||
* | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/footballJob.xml" }) | ||
public class FootballJobIntegrationTests { | ||
|
||
/** Logger */ | ||
private final Log logger = LogFactory.getLog(getClass()); | ||
|
||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
private JobLauncher jobLauncher; | ||
|
||
@Autowired | ||
private Job job; | ||
|
||
@Autowired | ||
public void setDataSource(DataSource dataSource) { | ||
this.jdbcTemplate = new JdbcTemplate(dataSource); | ||
} | ||
|
||
@Before | ||
public void clear() { | ||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYER_SUMMARY", "GAMES", "PLAYERS"); | ||
} | ||
|
||
@Test | ||
public void testLaunchJob() throws Exception { | ||
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("commit.interval", 10L) | ||
.toJobParameters()); | ||
assertEquals(BatchStatus.COMPLETED, execution.getStatus()); | ||
for (StepExecution stepExecution : execution.getStepExecutions()) { | ||
logger.info("Processed: " + stepExecution); | ||
if (stepExecution.getStepName().equals("playerload")) { | ||
// The effect of the retries | ||
assertEquals(new Double(Math.ceil(stepExecution.getReadCount() / 10. + 1)).intValue(), | ||
stepExecution.getCommitCount()); | ||
} | ||
} | ||
} | ||
|
||
} | ||
/* | ||
* Copyright 2006-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.batch.core.test.football; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.batch.core.BatchStatus; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParametersBuilder; | ||
import org.springframework.batch.core.StepExecution; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.batch.core.test.AbstractIntegrationTests; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* @author Dave Syer | ||
* @author Mahmoud Ben Hassine | ||
* | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/footballJob.xml" }) | ||
public class FootballJobIntegrationTests extends AbstractIntegrationTests { | ||
|
||
/** Logger */ | ||
private final Log logger = LogFactory.getLog(getClass()); | ||
|
||
@Autowired | ||
private JobLauncher jobLauncher; | ||
|
||
@Autowired | ||
private Job job; | ||
|
||
@Autowired | ||
public void setDataSource(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Test | ||
public void testLaunchJob() throws Exception { | ||
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("commit.interval", 10L) | ||
.toJobParameters()); | ||
assertEquals(BatchStatus.COMPLETED, execution.getStatus()); | ||
for (StepExecution stepExecution : execution.getStepExecutions()) { | ||
logger.info("Processed: " + stepExecution); | ||
if (stepExecution.getStepName().equals("playerload")) { | ||
// The effect of the retries | ||
assertEquals(new Double(Math.ceil(stepExecution.getReadCount() / 10. + 1)).intValue(), | ||
stepExecution.getCommitCount()); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.