diff --git a/spring-batch-infrastructure-tests/pom.xml b/spring-batch-infrastructure-tests/pom.xml index a98bba9e5..01818eb38 100644 --- a/spring-batch-infrastructure-tests/pom.xml +++ b/spring-batch-infrastructure-tests/pom.xml @@ -100,6 +100,11 @@ 1.2 test + + org.slf4j + slf4j-log4j12 + true + log4j log4j @@ -121,6 +126,36 @@ woodstox-core-asl test + + org.apache.ibatis + ibatis-sqlmap + true + + + javax.persistence + persistence-api + true + + + org.hibernate + hibernate-core + true + + + org.hibernate + hibernate-entitymanager + true + + + org.hibernate + hibernate-annotations + true + + + org.apache.geronimo.specs + geronimo-jta_1.1_spec + true + org.springframework.ws spring-oxm-tiger @@ -131,6 +166,11 @@ spring-jdbc test + + org.springframework + spring-orm + true + org.springframework spring-jms diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/config/DatasourceTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/config/DatasourceTests.java index e43d7be7a..4bf12f528 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/config/DatasourceTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/config/DatasourceTests.java @@ -42,10 +42,10 @@ public class DatasourceTests { @Transactional @Test public void testTemplate() throws Exception { System.err.println(System.getProperty("java.class.path")); - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", 0, "foo"); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", 0, "foo"); } } diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java new file mode 100644 index 000000000..639111e1e --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java @@ -0,0 +1,157 @@ +package org.springframework.batch.item.database; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.Executors; + +import javax.sql.DataSource; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.item.sample.Foo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.orm.ibatis.SqlMapClientFactoryBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.jdbc.SimpleJdbcTestUtils; + +import com.ibatis.sqlmap.client.SqlMapClient; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +public class IbatisPagingItemReaderAsyncTests { + + /** + * The number of items to read + */ + private static final int ITEM_COUNT = 100; + + /** + * The number of threads to create + */ + private static final int THREAD_COUNT = 5; + + private static Log logger = LogFactory.getLog(IbatisPagingItemReaderAsyncTests.class); + + @Autowired + private DataSource dataSource; + + private int maxId; + + @Before + public void init() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); + for (int i = maxId + 1; i <= ITEM_COUNT; i++) { + jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); + } + assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + } + + @After + public void destroy() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); + } + + @Test + public void testAsyncReader() throws Throwable { + List throwables = new ArrayList(); + int max = 10; + for (int i = 0; i < max; i++) { + try { + doTest(); + } + catch (Throwable e) { + throwables.add(e); + } + } + if (!throwables.isEmpty()) { + throw new IllegalStateException(String.format("Failed %d out of %d", throwables.size(), max), throwables + .get(0)); + } + } + + /** + * @throws Exception + * @throws InterruptedException + * @throws ExecutionException + */ + private void doTest() throws Exception, InterruptedException, ExecutionException { + final IbatisPagingItemReader reader = getItemReader(); + CompletionService> completionService = new ExecutorCompletionService>(Executors + .newFixedThreadPool(THREAD_COUNT)); + for (int i = 0; i < THREAD_COUNT; i++) { + completionService.submit(new Callable>() { + public List call() throws Exception { + List list = new ArrayList(); + Foo next = null; + do { + next = reader.read(); + Thread.sleep(10L); // try to make it fairer + logger.debug("Reading item: " + next); + if (next != null) { + list.add(next); + } + } while (next != null); + return list; + } + }); + } + int count = 0; + Set results = new HashSet(); + for (int i = 0; i < THREAD_COUNT; i++) { + List items = completionService.take().get(); + count += items.size(); + logger.debug("Finished items count: " + items.size()); + logger.debug("Finished items: " + items); + assertNotNull(items); + results.addAll(items); + } + assertEquals(ITEM_COUNT, count); + assertEquals(ITEM_COUNT, results.size()); + reader.close(); + } + + private IbatisPagingItemReader getItemReader() throws Exception { + SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean(); + factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass())); + factory.setDataSource(dataSource); + factory.afterPropertiesSet(); + SqlMapClient sqlMapClient = createSqlMapClient(); + + IbatisPagingItemReader reader = new IbatisPagingItemReader(); + reader.setQueryId("getPagedFoos"); + reader.setPageSize(2); + reader.setSqlMapClient(sqlMapClient); + reader.setSaveState(true); + + reader.afterPropertiesSet(); + + return reader; + } + + private SqlMapClient createSqlMapClient() throws Exception { + SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean(); + factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass())); + factory.setDataSource(dataSource); + factory.afterPropertiesSet(); + return (SqlMapClient) factory.getObject(); + } + +} diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java new file mode 100644 index 000000000..e2481464b --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java @@ -0,0 +1,161 @@ +package org.springframework.batch.item.database; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.Executors; + +import javax.sql.DataSource; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; +import org.springframework.batch.item.sample.Foo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +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; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +public class JdbcPagingItemReaderAsyncTests { + + /** + * The page size + */ + private static final int PAGE_SIZE = 2; + + /** + * The number of items to read + */ + private static final int ITEM_COUNT = 10; + + /** + * The number of threads to create + */ + private static final int THREAD_COUNT = 3; + + private static Log logger = LogFactory.getLog(JdbcPagingItemReaderAsyncTests.class); + + @Autowired + private DataSource dataSource; + + private int maxId; + + @Before + public void init() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); + for (int i = maxId + 1; i <= ITEM_COUNT; i++) { + jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); + } + assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + } + + @After + public void destroy() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); + } + + @Test + public void testAsyncReader() throws Throwable { + List throwables = new ArrayList(); + int max = 10; + for (int i = 0; i < max; i++) { + try { + doTest(); + } + catch (Throwable e) { + throwables.add(e); + } + } + if (!throwables.isEmpty()) { + throw new IllegalStateException(String.format("Failed %d out of %d", throwables.size(), max), throwables + .get(0)); + } + } + + /** + * @throws Exception + * @throws InterruptedException + * @throws ExecutionException + */ + private void doTest() throws Exception, InterruptedException, ExecutionException { + final ItemReader reader = getItemReader(); + CompletionService> completionService = new ExecutorCompletionService>(Executors + .newFixedThreadPool(THREAD_COUNT)); + for (int i = 0; i < THREAD_COUNT; i++) { + completionService.submit(new Callable>() { + public List call() throws Exception { + List list = new ArrayList(); + Foo next = null; + do { + next = reader.read(); + Thread.sleep(10L); + logger.debug("Reading item: " + next); + if (next != null) { + list.add(next); + } + } while (next != null); + return list; + } + }); + } + int count = 0; + Set results = new HashSet(); + for (int i = 0; i < THREAD_COUNT; i++) { + List items = completionService.take().get(); + count += items.size(); + logger.debug("Finished items count: " + items.size()); + logger.debug("Finished items: " + items); + assertNotNull(items); + results.addAll(items); + } + assertEquals(ITEM_COUNT, count); + assertEquals(ITEM_COUNT, results.size()); + } + + protected ItemReader getItemReader() throws Exception { + + JdbcPagingItemReader reader = new JdbcPagingItemReader(); + reader.setDataSource(dataSource); + HsqlPagingQueryProvider queryProvider = new HsqlPagingQueryProvider(); + queryProvider.setSelectClause("select ID, NAME, VALUE"); + queryProvider.setFromClause("from T_FOOS"); + queryProvider.setSortKey("ID"); + reader.setQueryProvider(queryProvider); + reader.setRowMapper(new ParameterizedRowMapper() { + public Foo mapRow(ResultSet rs, int i) throws SQLException { + Foo foo = new Foo(); + foo.setId(rs.getInt(1)); + foo.setName(rs.getString(2)); + foo.setValue(rs.getInt(3)); + return foo; + } + }); + reader.setPageSize(PAGE_SIZE); + reader.afterPropertiesSet(); + reader.setSaveState(false); + + return reader; + } + +} diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java new file mode 100644 index 000000000..1f4055990 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java @@ -0,0 +1,147 @@ +package org.springframework.batch.item.database; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.Executors; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.item.ExecutionContext; +import org.springframework.batch.item.sample.Foo; +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; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml") +public class JpaPagingItemReaderAsyncTests { + + /** + * The number of items to read + */ + private static final int ITEM_COUNT = 10; + + /** + * The number of threads to create + */ + private static final int THREAD_COUNT = 3; + + private static Log logger = LogFactory.getLog(JpaPagingItemReaderAsyncTests.class); + + @Autowired + private DataSource dataSource; + + @Autowired + private EntityManagerFactory entityManagerFactory; + + private int maxId; + + @Before + public void init() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); + for (int i = maxId + 1; i <= ITEM_COUNT; i++) { + jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); + } + assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + } + + @After + public void destroy() { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); + } + + @Test + public void testAsyncReader() throws Throwable { + List throwables = new ArrayList(); + int max = 10; + for (int i = 0; i < max; i++) { + try { + doTest(); + } + catch (Throwable e) { + throwables.add(e); + } + } + if (!throwables.isEmpty()) { + throw new IllegalStateException(String.format("Failed %d out of %d", throwables.size(), max), throwables + .get(0)); + } + } + + /** + * @throws Exception + * @throws InterruptedException + * @throws ExecutionException + */ + private void doTest() throws Exception, InterruptedException, ExecutionException { + final JpaPagingItemReader reader = getItemReader(); + CompletionService> completionService = new ExecutorCompletionService>(Executors + .newFixedThreadPool(THREAD_COUNT)); + for (int i = 0; i < THREAD_COUNT; i++) { + completionService.submit(new Callable>() { + public List call() throws Exception { + List list = new ArrayList(); + Foo next = null; + do { + next = reader.read(); + Thread.sleep(10L); + logger.debug("Reading item: " + next); + if (next != null) { + list.add(next); + } + } while (next != null); + return list; + } + }); + } + int count = 0; + Set results = new HashSet(); + for (int i = 0; i < THREAD_COUNT; i++) { + List items = completionService.take().get(); + count += items.size(); + logger.debug("Finished items count: " + items.size()); + logger.debug("Finished items: " + items); + assertNotNull(items); + results.addAll(items); + } + assertEquals(ITEM_COUNT, count); + assertEquals(ITEM_COUNT, results.size()); + reader.close(); + } + + private JpaPagingItemReader getItemReader() throws Exception { + + String jpqlQuery = "select f from Foo f"; + + JpaPagingItemReader reader = new JpaPagingItemReader(); + reader.setQueryString(jpqlQuery); + reader.setEntityManagerFactory(entityManagerFactory); + reader.setPageSize(3); + reader.afterPropertiesSet(); + reader.setSaveState(false); + reader.open(new ExecutionContext()); + + return reader; + } + +} diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/sample/Foo.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/sample/Foo.java new file mode 100644 index 000000000..9688f920a --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/sample/Foo.java @@ -0,0 +1,94 @@ +package org.springframework.batch.item.sample; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * Simple domain object for testing purposes. + */ +@Entity +@Table(name = "T_FOOS") +public class Foo { + + public static final String FAILURE_MESSAGE = "Foo Failure!"; + + public static final String UGLY_FAILURE_MESSAGE = "Ugly Foo Failure!"; + + @Id + private int id; + private String name; + private int value; + + public Foo(){} + + public Foo(int id, String name, int value) { + this.id = id; + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public int getValue() { + return value; + } + public void setValue(int value) { + this.value = value; + } + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + + public String toString() { + return "Foo[id=" +id +",name=" + name + ",value=" + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + value; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Foo other = (Foo) obj; + if (id != other.id) + return false; + if (name == null) { + if (other.name != null) + return false; + } + else if (!name.equals(other.name)) + return false; + if (value != other.value) + return false; + return true; + } + + public void fail() throws Exception { + throw new Exception(FAILURE_MESSAGE); + } + + public void failUgly() throws Throwable { + throw new Throwable(UGLY_FAILURE_MESSAGE); + } + +} diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventReaderItemReaderTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java similarity index 89% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventReaderItemReaderTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java index d6df61511..2cd27be39 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventReaderItemReaderTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import static org.junit.Assert.assertEquals; @@ -9,18 +9,20 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.batch.io.oxm.domain.Trade; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.xml.StaxEventItemReader; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.oxm.Unmarshaller; +import org.springframework.util.ClassUtils; public abstract class AbstractStaxEventReaderItemReaderTests { protected StaxEventItemReader reader = new StaxEventItemReader(); - protected Resource resource = new ClassPathResource("org/springframework/batch/io/oxm/input.xml"); + protected Resource resource = new ClassPathResource(ClassUtils + .addResourcePathToPackagePath(getClass(), "input.xml")); @Before public void setUp() throws Exception { @@ -28,7 +30,7 @@ public abstract class AbstractStaxEventReaderItemReaderTests { reader.setResource(resource); reader.setFragmentRootElementName("trade"); - + reader.setUnmarshaller(getUnmarshaller()); reader.afterPropertiesSet(); diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java similarity index 97% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java index c48c76ea2..53a098120 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import java.io.File; import java.io.FileReader; @@ -13,9 +13,9 @@ import org.custommonkey.xmlunit.XMLUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.batch.io.oxm.domain.Trade; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.xml.StaxEventItemWriter; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorMarshallingTests.java similarity index 93% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorMarshallingTests.java index cf306d273..e801d0282 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorMarshallingTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import org.springframework.core.io.ClassPathResource; import org.springframework.oxm.Marshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorUnmarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorUnmarshallingTests.java similarity index 93% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorUnmarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorUnmarshallingTests.java index e0083709f..ba002f1e6 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/CastorUnmarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/CastorUnmarshallingTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import org.springframework.core.io.ClassPathResource; import org.springframework.oxm.Unmarshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2MarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java similarity index 93% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2MarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java index d5ba94a9e..7b37bb439 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2MarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import static org.junit.Assert.assertTrue; @@ -11,7 +11,7 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; -import org.springframework.batch.io.oxm.domain.Trade; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.oxm.Marshaller; import org.springframework.oxm.jaxb.Jaxb2Marshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceMarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java similarity index 97% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceMarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java index 6603c8a59..acba0ff7a 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceMarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import static org.junit.Assert.assertTrue; @@ -18,9 +18,9 @@ import org.custommonkey.xmlunit.XMLUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.batch.io.oxm.domain.QualifiedTrade; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.xml.StaxEventItemWriter; +import org.springframework.batch.item.xml.domain.QualifiedTrade; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceUnmarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java similarity index 88% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceUnmarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java index 0ab69cff5..da3de3c03 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2NamespaceUnmarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import static org.junit.Assert.assertEquals; @@ -12,20 +12,22 @@ import javax.xml.transform.stream.StreamSource; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.batch.io.oxm.domain.QualifiedTrade; -import org.springframework.batch.io.oxm.domain.Trade; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.xml.StaxEventItemReader; +import org.springframework.batch.item.xml.domain.QualifiedTrade; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.util.ClassUtils; public class Jaxb2NamespaceUnmarshallingTests { private StaxEventItemReader reader = new StaxEventItemReader(); - private Resource resource = new ClassPathResource("org/springframework/batch/io/oxm/domain/trades.xml"); + private Resource resource = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), + "domain/trades.xml")); @Before public void setUp() throws Exception { @@ -44,7 +46,8 @@ public class Jaxb2NamespaceUnmarshallingTests { @Test public void testUnmarshal() throws Exception { - QualifiedTrade trade = (QualifiedTrade) getUnmarshaller().unmarshal(new StreamSource(new StringReader(TRADE_XML))); + QualifiedTrade trade = (QualifiedTrade) getUnmarshaller().unmarshal( + new StreamSource(new StringReader(TRADE_XML))); assertEquals("XYZ0001", trade.getIsin()); assertEquals(5, trade.getQuantity()); assertEquals(new BigDecimal("11.39"), trade.getPrice()); diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2UnmarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2UnmarshallingTests.java similarity index 84% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2UnmarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2UnmarshallingTests.java index 2fe7af670..6e4f772e3 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/Jaxb2UnmarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2UnmarshallingTests.java @@ -1,6 +1,6 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; -import org.springframework.batch.io.oxm.domain.Trade; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.jaxb.Jaxb2Marshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamMarshallingTests.java similarity index 84% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamMarshallingTests.java index d8ad409d2..1a5272d7a 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamMarshallingTests.java @@ -1,6 +1,6 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; -import org.springframework.batch.io.oxm.domain.Trade; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.oxm.Marshaller; import org.springframework.oxm.xstream.XStreamMarshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamUnmarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamUnmarshallingTests.java similarity index 85% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamUnmarshallingTests.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamUnmarshallingTests.java index d08a59e6b..cf4a87ef8 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/XStreamUnmarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/XStreamUnmarshallingTests.java @@ -1,8 +1,8 @@ -package org.springframework.batch.io.oxm; +package org.springframework.batch.item.xml; import java.math.BigDecimal; -import org.springframework.batch.io.oxm.domain.Trade; +import org.springframework.batch.item.xml.domain.Trade; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.xstream.XStreamMarshaller; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/QualifiedTrade.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/QualifiedTrade.java similarity index 98% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/QualifiedTrade.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/QualifiedTrade.java index 061628253..d014bf74a 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/QualifiedTrade.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/QualifiedTrade.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm.domain; +package org.springframework.batch.item.xml.domain; import java.math.BigDecimal; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/Trade.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/Trade.java similarity index 97% rename from spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/Trade.java rename to spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/Trade.java index 84df42a7a..286f1c76e 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/io/oxm/domain/Trade.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/domain/Trade.java @@ -1,4 +1,4 @@ -package org.springframework.batch.io.oxm.domain; +package org.springframework.batch.item.xml.domain; import java.math.BigDecimal; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java index e31f01535..16cbc7ee4 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java @@ -78,7 +78,7 @@ public class ExternalRetryInBatchTests { @Before public void onSetUp() throws Exception { getMessages(); // drain queue - jdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + jdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); jmsTemplate.convertAndSend("queue", "foo"); jmsTemplate.convertAndSend("queue", "bar"); provider = new ItemReader() { @@ -94,11 +94,11 @@ public class ExternalRetryInBatchTests { @After public void onTearDown() throws Exception { getMessages(); // drain queue - jdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + jdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); } private void assertInitialState() { - int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = jdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); } @@ -139,7 +139,7 @@ public class ExternalRetryInBatchTests { // back. When it comes back for recovery this code is not // executed... jdbcTemplate.update( - "INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", + "INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item); throw new RuntimeException("Rollback!"); } @@ -188,7 +188,7 @@ public class ExternalRetryInBatchTests { assertEquals(2, recovered.size()); // The database portion committed once... - int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = jdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); // ... and so did the message session. diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java index 2f54d40ee..f6bf3a8e8 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java @@ -71,7 +71,7 @@ public class AsynchronousTests { foo = (String) jmsTemplate.receiveAndConvert("queue"); count++; } - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); // Queue is now drained... assertNull(foo); @@ -98,7 +98,7 @@ public class AsynchronousTests { private volatile List list = new ArrayList(); private void assertInitialState() { - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); } @@ -111,7 +111,7 @@ public class AsynchronousTests { public void onMessage(Message message, Session session) throws JMSException { list.add(message.toString()); String text = ((TextMessage) message).getText(); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); } }); @@ -122,14 +122,14 @@ public class AsynchronousTests { // Need to sleep for at least a second here... waitFor(list,2,2000); - System.err.println(simpleJdbcTemplate.queryForList("select * from T_FOOS")); + System.err.println(simpleJdbcTemplate.queryForList("select * from T_BARS")); assertEquals(2, list.size()); String foo = (String) jmsTemplate.receiveAndConvert("queue"); assertEquals(null, foo); - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(2, count); } @@ -146,7 +146,7 @@ public class AsynchronousTests { public void onMessage(Message message, Session session) throws JMSException { list.add(message.toString()); final String text = ((TextMessage) message).getText(); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); // This causes the DB to rollback but not the message if (text.equals("bar")) { throw new RuntimeException("Rollback!"); @@ -175,7 +175,7 @@ public class AsynchronousTests { msgs.add(text); } - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); assertTrue("Foo not on queue", msgs.contains("foo")); diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java index 4650729b2..16650d592 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java @@ -83,13 +83,13 @@ public class SynchronousTests implements ApplicationContextAware { foo = (String) jmsTemplate.receiveAndConvert("queue"); count++; } - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); jmsTemplate.convertAndSend("queue", "foo"); jmsTemplate.convertAndSend("queue", "bar"); } private void assertInitialState() { - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); } @@ -105,12 +105,12 @@ public class SynchronousTests implements ApplicationContextAware { public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); return RepeatStatus.continueIf(text != null); } }); - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(2, count); String text = (String) jmsTemplate.receiveAndConvert("queue"); @@ -129,7 +129,7 @@ public class SynchronousTests implements ApplicationContextAware { public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); return RepeatStatus.continueIf(text != null); } }); @@ -147,7 +147,7 @@ public class SynchronousTests implements ApplicationContextAware { } // The database portion rolled back... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); // ... and so did the message session. The rollback should have restored @@ -174,7 +174,7 @@ public class SynchronousTests implements ApplicationContextAware { public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) txJmsTemplate.receiveAndConvert("queue"); list.add(text); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); return RepeatStatus.continueIf(text != null); } }); @@ -210,7 +210,7 @@ public class SynchronousTests implements ApplicationContextAware { } // The database portion committed... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(2, count); // ...but the JMS session rolled back, so the message is still there diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java new file mode 100644 index 000000000..ec3329bf6 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java @@ -0,0 +1,212 @@ +/* + * Copyright 2006-2007 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.repeat.support; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.springframework.batch.repeat.RepeatCallback; +import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; +import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +/** + * Simple tests for concurrent behaviour in repeat template, in particular the + * barrier at the end of the iteration. N.B. these tests may fail if + * insufficient threads are available (e.g. on a single-core machine, or under + * load). They shouldn't deadlock though. + * + * @author Dave Syer + * + */ +public class TaskExecutorRepeatTemplateBulkAsynchronousTests { + + static Log logger = LogFactory.getLog(TaskExecutorRepeatTemplateBulkAsynchronousTests.class); + + private int total = 1000; + + private int throttleLimit = 30; + + private volatile int early = Integer.MAX_VALUE; + + private TaskExecutorRepeatTemplate template; + + private RepeatCallback callback; + + private List items; + + @Before + public void setUp() { + + template = new TaskExecutorRepeatTemplate(); + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setMaxPoolSize(300); + taskExecutor.setCorePoolSize(10); + taskExecutor.setQueueCapacity(0); + taskExecutor.afterPropertiesSet(); + template.setTaskExecutor(taskExecutor); + template.setThrottleLimit(throttleLimit); + + items = Collections.synchronizedList(new ArrayList()); + + callback = new RepeatCallback() { + + private volatile AtomicInteger count = new AtomicInteger(0); + + public RepeatStatus doInIteration(RepeatContext context) throws Exception { + int position = count.incrementAndGet(); + String item = position <= total ? "" + position : null; + items.add("" + item); + if (item != null) { + beBusy(); + } + /* + * In a multi-threaded task, one of the callbacks can call + * FINISHED early, while other threads are still working, and + * would do more work if the callback was called again. (This + * happens for instance if there is a failure and you want to + * retry the work.) + */ + RepeatStatus result = RepeatStatus.continueIf(position != early && item != null); + if (!result.isContinuable()) { + logger.debug("Returning " + result + " for count=" + position); + } + return result; + } + }; + + } + + @Test + public void testThrottleLimit() throws Exception { + + template.iterate(callback); + int frequency = Collections.frequency(items, "null"); + // System.err.println(items); + // System.err.println("Frequency: " + frequency); + assertEquals(total, items.size() - frequency); + assertTrue(frequency > 1); + assertTrue(frequency <= throttleLimit + 1); + + } + + @Test + public void testThrottleLimitEarlyFinish() throws Exception { + + early = 2; + + template.iterate(callback); + int frequency = Collections.frequency(items, "null"); + // System.err.println("Frequency: " + frequency); + // System.err.println("Items: " + items); + assertEquals(total, items.size() - frequency); + assertTrue(frequency > 1); + assertTrue(frequency <= throttleLimit + 1); + + } + + @Test + public void testThrottleLimitEarlyFinishThreadStarvation() throws Exception { + + early = 2; + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + // Set the concurrency limit below the throttle limit for possible + // starvation condition + taskExecutor.setMaxPoolSize(20); + taskExecutor.setCorePoolSize(10); + taskExecutor.setQueueCapacity(0); + // This is the most sensible setting, otherwise the bookkeeping in + // ResultHolderResultQueue gets out of whack when tasks are aborted. + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.afterPropertiesSet(); + template.setTaskExecutor(taskExecutor); + + template.iterate(callback); + int frequency = Collections.frequency(items, "null"); + // System.err.println("Frequency: " + frequency); + // System.err.println("Items: " + items); + // Extra tasks will be submitted before the termination is detected + assertEquals(total, items.size() - frequency); + assertTrue(frequency <= throttleLimit + 1); + + } + + @Test + public void testThrottleLimitEarlyFinishOneThread() throws Exception { + + early = 4; + SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); + taskExecutor.setConcurrencyLimit(1); + + // This is kind of slow with only one thread, so reduce size: + throttleLimit = 10; + total = 20; + + template.setThrottleLimit(throttleLimit); + template.setTaskExecutor(taskExecutor); + + template.iterate(callback); + int frequency = Collections.frequency(items, "null"); + // System.err.println("Frequency: " + frequency); + // System.err.println("Items: " + items); + assertEquals(total, items.size() - frequency); + assertTrue(frequency <= throttleLimit + 1); + + } + + @Test + public void testThrottleLimitWithEarlyCompletion() throws Exception { + + early = 2; + template.setCompletionPolicy(new SimpleCompletionPolicy(10)); + + template.iterate(callback); + int frequency = Collections.frequency(items, "null"); + assertEquals(10, items.size() - frequency); + // System.err.println("Frequency: " + frequency); + assertEquals(0, frequency); + + } + + /** + * Slightly flakey convenience method. If this doesn't do something that + * lasts sufficiently long for another worker to be launched while it is + * busy, the early completion tests will fail. "Sufficiently long" is the + * problem so we try and block until we know someone else is busy? + * + * @throws Exception + */ + private void beBusy() throws Exception { + synchronized (this) { + wait(100L); + notifyAll(); + } + } + +} diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java index 3eaf09f16..e6c6c1d54 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java @@ -69,7 +69,7 @@ public class ExternalRetryTests { @Before public void onSetUp() throws Exception { getMessages(); // drain queue - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); jmsTemplate.convertAndSend("queue", "foo"); provider = new ItemReader() { public String read() { @@ -82,7 +82,7 @@ public class ExternalRetryTests { } private void assertInitialState() { - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); } @@ -104,7 +104,7 @@ public class ExternalRetryTests { for (Object text : texts) { - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); if (list.size() == 1) { throw new RuntimeException("Rollback!"); @@ -165,7 +165,7 @@ public class ExternalRetryTests { List msgs = getMessages(); // The database portion committed once... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(1, count); // ... and so did the message session. @@ -183,7 +183,7 @@ public class ExternalRetryTests { final String item = provider.read(); final RetryCallback callback = new RetryCallback() { public String doWithRetry(RetryContext context) throws Exception { - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), item); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item); throw new RuntimeException("Rollback!"); } }; @@ -230,7 +230,7 @@ public class ExternalRetryTests { assertEquals(1, recovered.size()); // The database portion committed once... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); // ... and so did the message session. diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java index f6f6f51f4..aaacb8b44 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java @@ -74,7 +74,7 @@ public class SynchronousTests { @BeforeTransaction public void onSetUpBeforeTransaction() throws Exception { - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); jmsTemplate.convertAndSend("queue", "foo"); jmsTemplate.convertAndSend("queue", "foo"); final String text = (String) jmsTemplate.receiveAndConvert("queue"); @@ -94,11 +94,11 @@ public class SynchronousTests { foo = (String) jmsTemplate.receiveAndConvert("queue"); count++; } - simpleJdbcTemplate.getJdbcOperations().execute("delete from T_FOOS"); + simpleJdbcTemplate.getJdbcOperations().execute("delete from T_BARS"); } private void assertInitialState() { - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); } @@ -134,7 +134,7 @@ public class SynchronousTests { list.add(text); System.err.println("Inserting: [" + list.size() + "," + text + "]"); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); if (list.size() == 1) { throw new RuntimeException("Rollback!"); } @@ -151,7 +151,7 @@ public class SynchronousTests { List msgs = getMessages(); // The database portion committed once... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(1, count); // ... and so did the message session. @@ -184,7 +184,7 @@ public class SynchronousTests { list.add(item); System.err.println("Inserting: [" + list.size() + "," + item + "]"); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), item); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), item); if (list.size() == 1) { throw new RuntimeException("Rollback!"); } @@ -202,7 +202,7 @@ public class SynchronousTests { List msgs = getMessages(); // The database portion committed once... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(1, count); // ... and so did the message session. @@ -245,7 +245,7 @@ public class SynchronousTests { list.add(text); System.err.println("Inserting: [" + list.size() + "," + text + "]"); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); return text; } @@ -258,7 +258,7 @@ public class SynchronousTests { } // The nested database transaction has committed... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(1, count); // force rollback... @@ -273,7 +273,7 @@ public class SynchronousTests { List msgs = getMessages(); // The database portion rolled back... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); // ... and so did the message session. @@ -303,7 +303,7 @@ public class SynchronousTests { // transaction... final String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); if (list.size() == 1) { throw new RuntimeException("Rollback!"); } @@ -320,7 +320,7 @@ public class SynchronousTests { List msgs = getMessages(); // The database portion committed once... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(1, count); // ... and so did the message session. @@ -351,7 +351,7 @@ public class SynchronousTests { // transaction... final String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); - simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); + simpleJdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", list.size(), text); throw new RuntimeException("Rollback!"); } @@ -377,7 +377,7 @@ public class SynchronousTests { List msgs = getMessages(); // The database portion rolled back... - int count = simpleJdbcTemplate.queryForInt("select count(*) from T_FOOS"); + int count = simpleJdbcTemplate.queryForInt("select count(*) from T_BARS"); assertEquals(0, count); // ... and so did the message session. diff --git a/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index ccfdef88f..f4adfe9aa 100644 --- a/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure-tests/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -25,7 +25,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.Resource; @@ -52,7 +51,7 @@ import org.springframework.util.StringUtils; * @author Dave Syer * */ -public class DataSourceInitializer implements InitializingBean, DisposableBean { +public class DataSourceInitializer implements InitializingBean { private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); @@ -64,7 +63,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { private boolean ignoreFailedDrop = true; - private static boolean initialized = false; + private boolean initialized = false; /** * Main method as convenient entry point. @@ -76,34 +75,6 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { DataSourceInitializer.class.getSimpleName() + "-context.xml")); } - /** - * @throws Throwable - * @see java.lang.Object#finalize() - */ - protected void finalize() throws Throwable { - super.finalize(); - initialized = false; - logger.debug("finalize called"); - } - - public void destroy() { - if (destroyScripts==null) return; - for (int i = 0; i < destroyScripts.length; i++) { - Resource destroyScript = initScripts[i]; - try { - doExecuteScript(destroyScript); - } - catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.warn("Could not execute destroy script [" + destroyScript + "]", e); - } - else { - logger.warn("Could not execute destroy script [" + destroyScript + "]"); - } - } - } - } - public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource); initialize(); @@ -111,7 +82,12 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { private void initialize() { if (!initialized) { - destroy(); + if (destroyScripts != null) { + for (int i = 0; i < destroyScripts.length; i++) { + Resource initScript = initScripts[i]; + doExecuteScript(initScript); + } + } if (initScripts != null) { for (int i = 0; i < initScripts.length; i++) { Resource initScript = initScripts[i]; diff --git a/spring-batch-infrastructure-tests/src/test/resources/META-INF/persistence.xml b/spring-batch-infrastructure-tests/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..f2ab28139 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,13 @@ + + + + + org.springframework.batch.item.sample.Foo + true + + + + diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo-write.hbm.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo-write.hbm.xml new file mode 100644 index 000000000..612a29924 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo-write.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo.hbm.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo.hbm.xml new file mode 100644 index 000000000..4c4b7bbbb --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/Foo.hbm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + from Foo + + diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml new file mode 100644 index 000000000..eee73841b --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests-context.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests-context.xml new file mode 100644 index 000000000..500260735 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests-context.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/data-source-context.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/data-source-context.xml new file mode 100644 index 000000000..b6001e632 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/data-source-context.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-config.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-config.xml new file mode 100644 index 000000000..f23807357 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-config.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-foo.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-foo.xml new file mode 100644 index 000000000..d418da081 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/ibatis-foo.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert INTO T_WRITE_FOOS (ID, NAME, VALUE) VALUES (#id#, #name#, #value#) + + + + update T_WRITE_FOOS set NAME = #name#, VALUE = #value# where ID = #id# + + + + delete from T_WRITE_FOOS where ID = #id# + + + \ No newline at end of file diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-hsqldb.sql b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-hsqldb.sql new file mode 100644 index 000000000..9fff8df46 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-hsqldb.sql @@ -0,0 +1,24 @@ +DROP TABLE T_FOOS if exists; +DROP TABLE T_WRITE_FOOS if exists; + +CREATE TABLE T_FOOS ( + ID BIGINT NOT NULL, + NAME VARCHAR(45), + VALUE INTEGER +); + +ALTER TABLE T_FOOS ADD PRIMARY KEY (ID); + +INSERT INTO t_foos (id, name, value) VALUES (1, 'bar1', 1); +INSERT INTO t_foos (id, name, value) VALUES (2, 'bar2', 2); +INSERT INTO t_foos (id, name, value) VALUES (3, 'bar3', 3); +INSERT INTO t_foos (id, name, value) VALUES (4, 'bar4', 4); +INSERT INTO t_foos (id, name, value) VALUES (5, 'bar5', 5); + +CREATE TABLE T_WRITE_FOOS ( + ID BIGINT NOT NULL, + NAME VARCHAR(45), + VALUE INTEGER +); + +ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID); diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/domain/trade.xsd b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd similarity index 100% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/domain/trade.xsd rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/domain/trades.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trades.xml similarity index 100% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/domain/trades.xml rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trades.xml diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/expected-output.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/expected-output.xml similarity index 100% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/expected-output.xml rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/expected-output.xml diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/expected-qualified-output.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/expected-qualified-output.xml similarity index 100% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/expected-qualified-output.xml rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/expected-qualified-output.xml diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/input.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/input.xml similarity index 100% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/input.xml rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/input.xml diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/mapping-castor.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/mapping-castor.xml similarity index 85% rename from spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/mapping-castor.xml rename to spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/mapping-castor.xml index 52d256275..8a1eb2cd6 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/io/oxm/mapping-castor.xml +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/mapping-castor.xml @@ -1,5 +1,5 @@ - + diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/destroy.sql b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/destroy.sql index a8f0da237..e6c4f4b4b 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/destroy.sql +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/destroy.sql @@ -1 +1 @@ -DROP TABLE T_FOOS; +DROP TABLE T_BARS; diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/init.sql b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/init.sql index 105bd81af..b1f224950 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/init.sql +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/jms/init.sql @@ -1,5 +1,5 @@ -DROP TABLE T_FOOS; -create table T_FOOS ( +DROP TABLE T_BARS; +create table T_BARS ( id integer not null primary key, name varchar(80), foo_date timestamp diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java index 639111e1e..4e7818ee2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java @@ -39,12 +39,12 @@ public class IbatisPagingItemReaderAsyncTests { /** * The number of items to read */ - private static final int ITEM_COUNT = 100; + private static final int ITEM_COUNT = 10; /** * The number of threads to create */ - private static final int THREAD_COUNT = 5; + private static final int THREAD_COUNT = 3; private static Log logger = LogFactory.getLog(IbatisPagingItemReaderAsyncTests.class); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java index 312be6f0a..e2481464b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java @@ -40,17 +40,17 @@ public class JdbcPagingItemReaderAsyncTests { /** * The page size */ - private static final int PAGE_SIZE = 5; + private static final int PAGE_SIZE = 2; /** * The number of items to read */ - private static final int ITEM_COUNT = 100; + private static final int ITEM_COUNT = 10; /** * The number of threads to create */ - private static final int THREAD_COUNT = 5; + private static final int THREAD_COUNT = 3; private static Log logger = LogFactory.getLog(JdbcPagingItemReaderAsyncTests.class); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java index 34674a990..1f4055990 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java @@ -37,12 +37,12 @@ public class JpaPagingItemReaderAsyncTests { /** * The number of items to read */ - private static final int ITEM_COUNT = 100; + private static final int ITEM_COUNT = 10; /** * The number of threads to create */ - private static final int THREAD_COUNT = 5; + private static final int THREAD_COUNT = 3; private static Log logger = LogFactory.getLog(JpaPagingItemReaderAsyncTests.class); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java index d3c93d000..dd48719e6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java @@ -47,9 +47,9 @@ public class TaskExecutorRepeatTemplateBulkAsynchronousTests { static Log logger = LogFactory.getLog(TaskExecutorRepeatTemplateBulkAsynchronousTests.class); - private int total = 100; + private int total = 20; - private int throttleLimit = 30; + private int throttleLimit = 8; private volatile int early = Integer.MAX_VALUE; @@ -154,8 +154,8 @@ public class TaskExecutorRepeatTemplateBulkAsynchronousTests { taskExecutor.setConcurrencyLimit(1); // This is kind of slow with only one thread, so reduce size: - throttleLimit = 10; - total = 20; + throttleLimit = 4; + total = 10; template.setThrottleLimit(throttleLimit); template.setTaskExecutor(taskExecutor);