RESOLVED - issue BATCH-1407: Integration tests for core (including multi-threaded long running tests)

This commit is contained in:
dsyer
2009-12-21 16:02:43 +00:00
parent 644efc30a0
commit 6270969054
39 changed files with 62344 additions and 210 deletions

View File

@@ -0,0 +1,79 @@
/*
* 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.simple.SimpleJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
/**
* @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 SimpleJdbcTemplate simpleJdbcTemplate;
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
@Before
public void clear() {
SimpleJdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "PLAYER_SUMMARY", "GAMES", "PLAYERS");
}
@Test
public void testLaunchJob() throws Exception {
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().toJobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
for (StepExecution stepExecution : execution.getStepExecutions()) {
logger.info("Processed: "+stepExecution);
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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.simple.SimpleJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
/**
* @author Dave Syer
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/parallelJob.xml" })
public class ParallelJobIntegrationTests {
/** Logger */
private final Log logger = LogFactory.getLog(getClass());
@Autowired
private JobLauncher jobLauncher;
private SimpleJdbcTemplate simpleJdbcTemplate;
@Autowired
private Job job;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
@Before
public void clear() {
SimpleJdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "PLAYER_SUMMARY", "GAMES", "PLAYERS");
}
@Test
public void testLaunchJob() throws Exception {
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().toJobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
for (StepExecution stepExecution : execution.getStepExecutions()) {
logger.info("Processed: "+stepExecution);
}
}
}

View File

@@ -53,8 +53,6 @@ import org.springframework.transaction.support.TransactionTemplate;
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml" })
public class JdbcJobRepositoryTests {
private JobRepository repository;
private JobSupport job;
private Set<Long> jobExecutionIds = new HashSet<Long>();
@@ -65,6 +63,10 @@ public class JdbcJobRepositoryTests {
private SimpleJdbcTemplate simpleJdbcTemplate;
@Autowired
private JobRepository repository;
@Autowired
private PlatformTransactionManager transactionManager;
/** Logger */
@@ -75,16 +77,6 @@ public class JdbcJobRepositoryTests {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
@Autowired
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Autowired
public void setRepository(JobRepository repository) {
this.repository = repository;
}
@BeforeTransaction
public void onSetUpInTransaction() throws Exception {
job = new JobSupport("test-job");

View File

@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionStatus;
@@ -116,7 +117,13 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
for (int i = 0; i < scripts.length; i++) {
String script = scripts[i].trim();
if (StringUtils.hasText(script)) {
jdbcTemplate.execute(scripts[i]);
try {
jdbcTemplate.execute(scripts[i]);
} catch (DataAccessException e) {
if (!script.toUpperCase().startsWith("DROP")) {
throw e;
}
}
}
}
return null;

View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<import resource="simple-job-launcher-context.xml" />
<bean class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="spring:service=batch,bean=jobOperator">
<bean class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="jobOperator" />
<property name="interceptorNames" value="exceptionTranslator" />
</bean>
</entry>
<entry key="spring:service=batch,bean=jobLoader" value-ref="loader" />
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="interfaceMappings">
<map>
<entry key="spring:service=batch,bean=jobOperator" value="org.springframework.batch.core.launch.JobOperator" />
<entry key="spring:service=batch,bean=jobLoader" value="org.springframework.batch.core.test.launch.JobLoader" />
</map>
</property>
</bean>
</property>
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<property name="jobExplorer">
<bean class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
</property>
<property name="jobRepository" ref="jobRepository" />
<property name="jobRegistry" ref="jobRegistry" />
<property name="jobLauncher">
<bean parent="jobLauncher">
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
</property>
</bean>
<bean id="exceptionTranslator" class="org.springframework.batch.core.launch.support.RuntimeExceptionTranslator" />
<bean id="loader" class="org.springframework.batch.core.test.launch.DefaultJobLoader">
<property name="registry" ref="jobRegistry" />
</bean>
</beans>

View File

@@ -4,15 +4,13 @@ batch.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
batch.jdbc.url=jdbc:derby:derby-home/test;create=true
batch.jdbc.user=sa
batch.jdbc.password=
batch.schema=
batch.jndi.name=
batch.naming.factory.initial=
batch.naming.provider.url=
batch.schema.script=schema-derby.sql
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-derby.sql
batch.schema.script=classpath:/org/springframework/batch/core/schema-derby.sql
batch.business.schema.script=business-schema-derby.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer
batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler
# Bean Properties for override
# when not using sequences:
incrementerParent.columnName=ID
batch.database.incrementer.parent=columnIncrementerParent
batch.grid.size=2
batch.verify.cursor.position=false

View File

@@ -15,3 +15,4 @@ batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
batch.database.incrementer.parent=columnIncrementerParent
batch.grid.size=2
batch.verify.cursor.position=true

View File

@@ -8,12 +8,9 @@ batch.schema=
batch.jndi.name=
batch.naming.factory.initial=
batch.naming.provider.url=
batch.schema.script=schema-mysql.sql
batch.drop.script=schema-drop-mysql.sql
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
batch.drop.script=
batch.business.schema.script=business-schema-mysql.sql
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer
batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler
# Bean Properties for override
# when not using sequences:
incrementerParent.columnName=ID
batch.verify.cursor.position=true

View File

@@ -32,24 +32,12 @@
<bean id="environment"
class="org.springframework.batch.support.SystemPropertyInitializer">
<property name="defaultValue" value="hsql"/>
</bean>
<!-- Use this to set additional properties on beans at run time -->
<bean id="overrideProperties" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer"
depends-on="environment">
<property name="location" value="classpath:batch-${org.springframework.batch.support.SystemPropertyInitializer.ENVIRONMENT}.properties" />
<!-- Allow system properties (-D) to override those from file -->
<property name="localOverride" value="true" />
<property name="properties">
<bean class="java.lang.System" factory-method="getProperties" />
</property>
<property name="ignoreInvalidKeys" value="true" />
<property name="order" value="2" />
<property name="keyName" value="ENVIRONMENT"/>
</bean>
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
depends-on="environment">
<property name="location" value="classpath:batch-${org.springframework.batch.support.SystemPropertyInitializer.ENVIRONMENT}.properties" />
<property name="location" value="classpath:batch-${ENVIRONMENT}.properties" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
@@ -67,6 +55,4 @@
<property name="incrementerName" value="DUMMY" />
</bean>
<!--import resource="alt-data-source-context.xml" /-->
</beans>

View File

@@ -0,0 +1,5 @@
AbduKa00,1996,mia,10,nwe,0,0,0,0,0,29,104,,16,2
AbduKa00,1996,mia,11,clt,0,0,0,0,0,18,70,,11,2
AbduKa00,1996,mia,12,oti,0,0,0,0,0,18,59,,0,0
AbduKa00,1996,mia,13,pit,0,0,0,0,0,16,57,,0,0
AbduKa00,1996,mia,14,rai,0,0,0,0,0,18,39,,7,0
1 AbduKa00 1996 mia 10 nwe 0 0 0 0 0 29 104 16 2
2 AbduKa00 1996 mia 11 clt 0 0 0 0 0 18 70 11 2
3 AbduKa00 1996 mia 12 oti 0 0 0 0 0 18 59 0 0
4 AbduKa00 1996 mia 13 pit 0 0 0 0 0 16 57 0 0
5 AbduKa00 1996 mia 14 rai 0 0 0 0 0 18 39 7 0

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
AbduKa00,Abdul-Jabbar,Karim,rb,1974,1996
AbduRa00,Abdullah,Rabih,rb,1975,1999
AberWa00,Abercrombie,Walter,rb,1959,1982
AbraDa00,Abramowicz,Danny,wr,1945,1967
AdamBo00,Adams,Bob,te,1946,1969
AdamCh00,Adams,Charlie,wr,1979,2003
AdamCu00,Adams,Curtis,rb,1962,1985
AdamGe00,Adams,George,rb,1962,1985
AdamGr00,Adams,Grant,wr,2000,2005
AdamJo00,Adams,John,rb,1937,1959
AdamMi00,Adams,Michael,wr,1974,1997
AdamMi01,Adamle,Mike,rb,1949,1971
AdamTo00,Adams,Tony,qb,1950,1975
AdamTo01,Adams,Tom,wr,1940,1962
AdamTo02,Adamle,Tony,rb,1924,1950
AdamWi00,Adams,Willie,wr,1956,1979
AddaJo00,Addai,Joseph,rb,1983,2006
AdkiJa00,Adkisson,James,te,1980,2005
AdkiMa00,Adkins,Margene,wr,1947,1970
AdkiSa00,Adkins,Sam,qb,1955,1977
1 AbduKa00 Abdul-Jabbar Karim rb 1974 1996
2 AbduRa00 Abdullah Rabih rb 1975 1999
3 AberWa00 Abercrombie Walter rb 1959 1982
4 AbraDa00 Abramowicz Danny wr 1945 1967
5 AdamBo00 Adams Bob te 1946 1969
6 AdamCh00 Adams Charlie wr 1979 2003
7 AdamCu00 Adams Curtis rb 1962 1985
8 AdamGe00 Adams George rb 1962 1985
9 AdamGr00 Adams Grant wr 2000 2005
10 AdamJo00 Adams John rb 1937 1959
11 AdamMi00 Adams Michael wr 1974 1997
12 AdamMi01 Adamle Mike rb 1949 1971
13 AdamTo00 Adams Tony qb 1950 1975
14 AdamTo01 Adams Tom wr 1940 1962
15 AdamTo02 Adamle Tony rb 1924 1950
16 AdamWi00 Adams Willie wr 1956 1979
17 AddaJo00 Addai Joseph rb 1983 2006
18 AdkiJa00 Adkisson James te 1980 2005
19 AdkiMa00 Adkins Margene wr 1947 1970
20 AdkiSa00 Adkins Sam qb 1955 1977

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
multiple environments. -->
<job id="loopJob" incrementer="jobParametersIncrementer" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="reader" writer="writer" commit-interval="3"/>
</tasklet>
</step>
</job>
<bean id="reader" class="org.springframework.batch.core.test.launch.InfiniteLoopReader" />
<bean id="writer" class="org.springframework.batch.core.test.launch.InfiniteLoopWriter" />
<bean id="jobParametersIncrementer"
class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
</beans>

View File

@@ -6,7 +6,8 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%L - %m
log4j.category.org.apache.activemq=ERROR
# log4j.category.org.springframework=DEBUG
log4j.category.org.springframework.jdbc=DEBUG
log4j.category.org.springframework.jms=DEBUG
log4j.category.org.springframework.batch=DEBUG
log4j.category.org.springframework.retry=DEBUG
log4j.category.org.springframework.jdbc=INFO
log4j.category.org.springframework.jms=INFO
log4j.category.org.springframework.batch=INFO
log4j.category.org.springframework.retry=INFO
# log4j.category.org.springframework.beans.factory.config=TRACE