diff --git a/spring-batch-samples/.springBeans b/spring-batch-samples/.springBeans
index ecdb96f8a..49a0d166a 100644
--- a/spring-batch-samples/.springBeans
+++ b/spring-batch-samples/.springBeans
@@ -7,7 +7,6 @@
- src/main/resources/jobs/fixedLengthImportJob.xml
src/main/resources/jobs/multilineJob.xml
src/main/resources/jobs/multilineOrderIo.xml
src/main/resources/jobs/multilineOrderJob.xml
@@ -36,16 +35,12 @@
src/main/resources/jobs/multilineOrderOutputAggregators.xml
src/main/resources/jobs/compositeItemWriterSampleJob.xml
src/main/resources/jobs/multiResourceJob.xml
- src/main/resources/jobs/jobExecutionContextSample.xml
src/main/resources/hibernate-context.xml
src/main/resources/staging-test-context.xml
src/main/resources/org/springframework/batch/sample/config/common-context.xml
- src/main/resources/jobs/taskletJob.xml
src/main/resources/jobs/headerFooterSample.xml
src/main/resources/jobs/customerFilterJob.xml
- src/main/resources/jobs/nonSequentialDecisionJob.xml
- src/main/resources/jobs/nonSequentialJob-base.xml
- src/main/resources/jobs/nonSequentialJob.xml
+ src/main/resources/skipSample-job-launcher-context.xml
@@ -84,7 +79,6 @@
true
false
- src/main/resources/jobs/fixedLengthImportJob.xml
src/main/resources/data-source-context.xml
src/main/resources/data-source-context-init.xml
src/main/resources/simple-job-launcher-context.xml
@@ -279,7 +273,6 @@
src/main/resources/data-source-context.xml
src/main/resources/data-source-context-init.xml
- src/main/resources/jobs/jobExecutionContextSample.xml
src/main/resources/simple-job-launcher-context.xml
src/main/resources/org/springframework/batch/sample/config/common-context.xml
@@ -336,7 +329,6 @@
src/main/resources/data-source-context-init.xml
src/main/resources/simple-job-launcher-context.xml
src/main/resources/org/springframework/batch/sample/config/common-context.xml
- src/main/resources/jobs/taskletJob.xml
@@ -378,8 +370,6 @@
true
false
- src/main/resources/jobs/nonSequentialDecisionJob.xml
- src/main/resources/jobs/nonSequentialJob-base.xml
src/main/resources/data-source-context.xml
src/main/resources/data-source-context-init.xml
src/main/resources/org/springframework/batch/sample/config/common-context.xml
@@ -391,8 +381,6 @@
true
false
- src/main/resources/jobs/nonSequentialJob.xml
- src/main/resources/jobs/nonSequentialJob-base.xml
src/main/resources/data-source-context.xml
src/main/resources/data-source-context-init.xml
src/main/resources/simple-job-launcher-context.xml
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/Trade.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/Trade.java
index dc4b23e0d..d21cd53dc 100644
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/Trade.java
+++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/Trade.java
@@ -19,7 +19,6 @@ package org.springframework.batch.sample.domain.trade;
import java.io.Serializable;
import java.math.BigDecimal;
-import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -81,7 +80,18 @@ public class Trade implements Serializable {
}
public boolean equals(Object o) {
- return EqualsBuilder.reflectionEquals(this, o);
+ if(!(o instanceof Trade)){
+ return false;
+ }
+
+ if(o == this){
+ return true;
+
+ }
+
+ Trade t = (Trade)o;
+ return isin.equals(t.getIsin()) && quantity == t.getQuantity() &&
+ price.equals(t.getPrice()) && customer.equals(t.getCustomer()) ;
}
public int hashCode() {
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/ItemTrackingItemWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/ItemTrackingItemWriter.java
deleted file mode 100644
index e2ff0baed..000000000
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/support/ItemTrackingItemWriter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.springframework.batch.sample.support;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.batch.item.ItemWriter;
-
-/**
- * Remembers all items written - useful for testing.
- */
-public class ItemTrackingItemWriter implements ItemWriter {
-
- private List items = new ArrayList();
-
- private T failed = null;
-
- private int failure = -1;
-
- private int counter = 0;
-
- public void write(List extends T> items) throws Exception {
- if (failed!=null && items.contains(failed)) {
- throw new RuntimeException("write failed again");
- }
- this.items.addAll(items);
- int current = counter;
- counter += items.size();
- if (current < failure && counter >= failure) {
- failed = items.get(failure-current-1);
- this.items.remove(failed);
- throw new RuntimeException("write failed");
- }
- }
-
- public List getItems() {
- return items;
- }
-
- public void setWriteFailure(int failure) {
- this.failure = failure;
- }
-
-}
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java
deleted file mode 100644
index dcf5fb9f0..000000000
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.springframework.batch.sample.tasklet;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.core.StepContribution;
-import org.springframework.batch.core.StepExecution;
-import org.springframework.batch.core.listener.StepExecutionListenerSupport;
-import org.springframework.batch.core.step.tasklet.Tasklet;
-import org.springframework.batch.item.ExecutionContext;
-import org.springframework.batch.repeat.RepeatStatus;
-import org.springframework.core.AttributeAccessor;
-
-/**
- * Dummy tasklet that retrieves message from the job execution context.
- */
-public class DummyMessageReceivingTasklet extends StepExecutionListenerSupport implements Tasklet {
-
- private static final Log logger = LogFactory.getLog(DummyMessageReceivingTasklet.class);
-
- private String receivedMessage = null;
-
- public void beforeStep(StepExecution stepExecution) {
- ExecutionContext ctx = stepExecution.getJobExecution().getExecutionContext();
- receivedMessage = ctx.getString(DummyMessageSendingTasklet.MESSAGE_KEY);
- logger.info("Got message from context: " + receivedMessage);
- }
-
- public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
- return RepeatStatus.FINISHED;
- }
-
- public String getReceivedMessage() {
- return receivedMessage;
- }
-
-}
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java
deleted file mode 100644
index 66261dd3d..000000000
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.springframework.batch.sample.tasklet;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.core.ExitStatus;
-import org.springframework.batch.core.StepContribution;
-import org.springframework.batch.core.StepExecution;
-import org.springframework.batch.core.listener.StepExecutionListenerSupport;
-import org.springframework.batch.core.step.tasklet.Tasklet;
-import org.springframework.batch.item.ExecutionContext;
-import org.springframework.batch.repeat.RepeatStatus;
-import org.springframework.core.AttributeAccessor;
-
-/**
- * Dummy tasklet that stores a message in the job execution context.
- */
-public class DummyMessageSendingTasklet extends StepExecutionListenerSupport implements Tasklet {
-
- private static final Log logger = LogFactory.getLog(DummyMessageSendingTasklet.class);
-
- public static final String MESSAGE_KEY = DummyMessageSendingTasklet.class.getSimpleName()+".MESSAGE";
-
- private String message = "Hello!";
-
- public ExitStatus afterStep(StepExecution stepExecution) {
- ExecutionContext ctx = stepExecution.getJobExecution().getExecutionContext();
- ctx.putString(MESSAGE_KEY, message);
- logger.info("Put message into context: " + message);
- return null;
- }
-
- public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
- return RepeatStatus.FINISHED;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
-}
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java
deleted file mode 100644
index 7dc1a4382..000000000
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.springframework.batch.sample.tasklet;
-
-import org.springframework.batch.core.StepContribution;
-import org.springframework.batch.core.UnexpectedJobExecutionException;
-import org.springframework.batch.core.step.tasklet.Tasklet;
-import org.springframework.batch.repeat.RepeatStatus;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.AttributeAccessor;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-
-/**
- * Deletes files from an array of resources, so a pattern can be used in
- * configuration, e.g. resources="/home/batch/job/**"
- *
- * @author Robert Kasanicky
- */
-public class FileDeletingTasklet implements Tasklet, InitializingBean {
-
- private Resource[] resources;
-
- public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
- for (Resource resource : resources) {
- boolean deleted = resource.getFile().delete();
- if (!deleted) {
- throw new UnexpectedJobExecutionException("Could not delete file " + resource);
- }
- }
- return RepeatStatus.FINISHED;
- }
-
- public void setResources(Resource[] resources) {
- this.resources = resources;
- }
-
- public void afterPropertiesSet() throws Exception {
- Assert.notNull(resources, "Resources must be set");
- }
-
-}
diff --git a/spring-batch-samples/src/main/resources/business-schema-db2.sql b/spring-batch-samples/src/main/resources/business-schema-db2.sql
index 5da631d16..07bd97742 100644
--- a/spring-batch-samples/src/main/resources/business-schema-db2.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-db2.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-derby.sql b/spring-batch-samples/src/main/resources/business-schema-derby.sql
index 301125ea6..92cb27752 100644
--- a/spring-batch-samples/src/main/resources/business-schema-derby.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-derby.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql b/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql
index aef60cd13..80d3e711b 100644
--- a/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql
@@ -93,5 +93,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-mysql.sql b/spring-batch-samples/src/main/resources/business-schema-mysql.sql
index f90197d03..b1af02373 100644
--- a/spring-batch-samples/src/main/resources/business-schema-mysql.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-mysql.sql
@@ -90,5 +90,7 @@ CREATE TABLE PLAYER_SUMMARY (
) type=InnoDB;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) type=InnoDB;
diff --git a/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql b/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql
index 99e46672c..4469bf8d5 100644
--- a/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-postgresql.sql b/spring-batch-samples/src/main/resources/business-schema-postgresql.sql
index 9d5930974..c82a6f749 100644
--- a/spring-batch-samples/src/main/resources/business-schema-postgresql.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-postgresql.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql b/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql
index 9b7ccb213..5a1238e4d 100644
--- a/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) ,
+ STEP_NAME CHAR(20) ,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/business-schema-sybase.sql b/spring-batch-samples/src/main/resources/business-schema-sybase.sql
index a9aeb1919..0ce4d5d4e 100644
--- a/spring-batch-samples/src/main/resources/business-schema-sybase.sql
+++ b/spring-batch-samples/src/main/resources/business-schema-sybase.sql
@@ -87,5 +87,7 @@ CREATE TABLE PLAYER_SUMMARY (
) ;
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) NULL,
+ STEP_NAME CHAR(20) NULL,
+ MESSAGE CHAR(300) NOT NULL
) ;
diff --git a/spring-batch-samples/src/main/resources/data/multiResourceJob/input/20070122.teststream.ImportTradeDataStep.txt b/spring-batch-samples/src/main/resources/data/multiResourceJob/input/20070122.teststream.ImportTradeDataStep.txt
new file mode 100644
index 000000000..c48f5c51c
--- /dev/null
+++ b/spring-batch-samples/src/main/resources/data/multiResourceJob/input/20070122.teststream.ImportTradeDataStep.txt
@@ -0,0 +1,5 @@
+UK21341EAH4121131.11customer1
+UK21341EAH4221232.11customer2
+UK21341EAH4321333.11customer3
+UK21341EAH4421434.11customer4
+UK21341EAH4521535.11customer5
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/games-small.csv b/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/games-small.csv
deleted file mode 100644
index be449f5ac..000000000
--- a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/games-small.csv
+++ /dev/null
@@ -1,79 +0,0 @@
-AbduKa00,1998,mia,6,jax,0,0,0,0,0,21,43,0,0,1
-AbduKa00,1998,mia,7,ram,0,0,0,0,0,17,59,2,12,0
-AbduKa00,1998,mia,8,nwe,0,0,0,0,0,21,56,3,12,0
-AbduKa00,1998,mia,9,buf,0,0,0,0,0,22,97,2,9,1
-AbduKa00,1999,cle,10,pit,0,0,0,0,0,18,56,1,7,0
-AbduKa00,1999,cle,11,car,0,0,0,0,0,7,11,2,2,0
-AbduKa00,1999,cle,12,oti,0,0,0,0,0,15,35,1,1,0
-AbduKa00,1999,cle,13,sdg,0,0,0,0,0,10,29,1,21,0
-AbduKa00,1999,cle,14,cin,0,0,0,0,0,5,10,2,7,1
-AbduKa00,1999,cle,15,jax,0,0,0,0,0,13,36,1,4,0
-AbduKa00,1999,cle,16,clt,0,0,0,0,0,19,84,2,7,0
-AbduKa00,1999,cle,1,den,0,0,0,0,0,16,60,1,7,1
-AbduKa00,1999,cle,2,crd,0,0,0,0,0,9,33,3,18,0
-AbduKa00,1999,cle,4,buf,0,0,0,0,0,3,2,0,0,0
-AbduKa00,1999,cle,7,ram,0,0,0,0,0,6,27,2,8,0
-AbduKa00,1999,cle,8,nor,0,0,0,0,0,13,39,0,0,0
-AbduKa00,1999,cle,9,rav,0,0,0,0,0,9,23,1,2,0
-AbduKa00,2000,clt,1,kan,0,0,0,0,0,1,-2,0,0,0
-AbduRa00,1999,tam,13,min,0,0,0,0,0,0,0,1,3,0
-AbduRa00,1999,tam,15,rai,0,0,0,0,0,4,12,0,0,0
-AbduRa00,1999,tam,1,nyg,0,0,0,0,0,1,0,0,0,0
-AbduRa00,1999,tam,8,det,0,0,0,0,0,0,0,1,8,0
-AbduRa00,2000,tam,12,chi,0,0,0,0,0,2,18,0,0,0
-AbduRa00,2000,tam,14,dal,0,0,0,0,0,10,38,1,11,0
-AbduRa00,2000,tam,15,mia,0,0,0,0,0,4,14,0,0,0
-AbduRa00,2000,tam,1,nwe,0,0,0,0,0,0,0,1,3,0
-AbduRa00,2001,tam,15,nor,0,0,0,0,0,3,6,0,0,0
-AbduRa00,2001,tam,17,phi,0,0,0,0,0,8,34,2,26,0
-AbduRa00,2003,chi,10,det,0,0,0,0,0,2,3,1,7,0
-AbduRa00,2003,chi,11,ram,0,0,0,0,0,1,1,0,0,0
-AbduRa00,2003,chi,13,crd,0,0,0,0,0,1,0,0,0,0
-AbduRa00,2003,chi,14,gnb,0,0,0,0,0,2,3,1,5,0
-AbduRa00,2003,chi,15,min,0,0,0,0,0,1,3,0,0,0
-AbduRa00,2003,chi,17,kan,0,0,0,0,0,2,8,2,19,0
-AbduRa00,2003,chi,2,min,0,0,0,0,0,1,2,2,10,0
-AbduRa00,2003,chi,4,gnb,0,0,0,0,0,1,-4,2,14,0
-AbduRa00,2003,chi,5,rai,0,0,0,0,0,2,8,0,0,0
-AbduRa00,2003,chi,7,sea,0,0,0,0,0,3,4,0,0,0
-AbduRa00,2003,chi,8,det,0,0,0,0,0,1,6,0,0,0
-AbduRa00,2003,chi,9,sdg,0,0,0,0,0,1,3,0,0,0
-AbduRa00,2004,nwe,10,buf,0,0,0,0,0,4,-5,0,0,0
-AbduRa00,2004,nwe,16,nyj,0,0,0,0,0,1,5,0,0,0
-AbduRa00,2004,nwe,17,sfo,0,0,0,0,0,2,5,0,0,0
-AbduRa00,2004,nwe,2,crd,0,0,0,0,0,1,4,0,0,0
-AbduRa00,2004,nwe,5,mia,0,0,0,0,0,5,4,0,0,1
-AbduRa00,2004,nwe,6,sea,0,0,0,0,0,0,0,1,9,0
-AdamCh00,2005,den,10,rai,0,0,0,0,0,2,5,0,0,0
-AdamCh00,2005,den,11,nyj,0,0,0,0,0,1,3,2,21,0
-AdamCh00,2005,den,12,dal,0,0,0,0,0,0,0,1,7,0
-AdamCh00,2005,den,13,kan,0,0,0,0,0,0,0,0,0,0
-AdamCh00,2005,den,14,rav,0,0,0,0,0,0,0,3,35,0
-AdamCh00,2005,den,15,buf,0,0,0,0,0,0,0,0,0,0
-AdamCh00,2005,den,16,rai,0,0,0,0,0,1,-7,0,0,0
-AdamCh00,2005,den,17,sdg,0,0,0,0,0,0,0,2,6,0
-AdamCh00,2005,den,1,mia,0,0,0,0,0,0,0,2,35,0
-AdamCh00,2005,den,2,sdg,0,0,0,0,0,0,0,3,31,0
-AdamCh00,2005,den,3,kan,0,0,0,0,0,0,0,2,23,0
-AdamCh00,2005,den,4,jax,0,0,0,0,0,1,13,1,9,0
-AdamCh00,2005,den,5,was,0,0,0,0,0,0,0,2,11,0
-AdamCh00,2005,den,6,nwe,0,0,0,0,0,0,0,0,0,0
-AdamCh00,2005,den,7,nyg,0,0,0,0,0,0,0,0,0,0
-AdamCh00,2005,den,8,phi,0,0,0,0,0,0,0,3,25,0
-AdamMi00,1997,pit,5,oti,0,0,0,0,0,0,0,1,39,0
-AddaJo00,2006,clt,10,buf,0,0,0,0,0,13,78,7,46,1
-AddaJo00,2006,clt,11,dal,0,0,0,0,0,13,50,1,7,0
-AddaJo00,2006,clt,12,phi,0,0,0,0,0,24,171,2,37,4
-AddaJo00,2006,clt,13,oti,0,0,0,0,0,16,56,1,11,0
-AddaJo00,2006,clt,14,jax,0,0,0,0,0,11,22,1,14,0
-AddaJo00,2006,clt,15,cin,0,0,0,0,0,8,50,2,29,0
-AddaJo00,2006,clt,16,htx,0,0,0,0,0,15,100,4,8,0
-AddaJo00,2006,clt,17,mia,0,0,0,0,0,21,64,3,29,0
-AddaJo00,2006,clt,1,nyg,0,0,0,0,0,7,26,3,22,0
-AddaJo00,2006,clt,2,htx,0,0,0,0,0,16,82,2,22,1
-AddaJo00,2006,clt,3,jax,0,0,0,0,0,3,15,3,13,0
-AddaJo00,2006,clt,4,nyj,0,0,0,0,0,20,84,3,15,1
-AddaJo00,2006,clt,5,oti,0,0,0,0,0,13,62,2,15,0
-AddaJo00,2006,clt,7,was,0,0,0,0,0,11,85,1,20,0
-AddaJo00,2006,clt,8,den,0,0,0,0,0,17,93,5,37,0
-AddaJo00,2006,clt,9,nwe,0,0,0,0,0,18,43,0,0,1
diff --git a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-containsBadRecords.csv b/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-containsBadRecords.csv
deleted file mode 100644
index c586f7440..000000000
--- a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-containsBadRecords.csv
+++ /dev/null
@@ -1,20 +0,0 @@
-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
-AdamGe00,Adams,George,rb,1962,1985
-AdamGr00,Adams,Grant,2000,2005
-AdamJo00,Adams,John,rb,1937,1959
-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,,1950
-AdamWi00,Adams,Willie,wr,1956,1979
-AddaJo00,Addai,Joseph,1983,2006,rb
-AdkiJa00,Adkisson,James,te,1980,2005
-AdkiMa00,Adkins,Margene,wr,1947,1970
-AdkiSa00,Adkins,Sam,qb,1955,1977
diff --git a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-small.csv b/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-small.csv
deleted file mode 100644
index 48464b030..000000000
--- a/spring-batch-samples/src/main/resources/data/nonSequentialJob/input/player-small.csv
+++ /dev/null
@@ -1,20 +0,0 @@
-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
diff --git a/spring-batch-samples/src/main/resources/data/skipJob/input/input1.txt b/spring-batch-samples/src/main/resources/data/skipJob/input/input1.txt
new file mode 100644
index 000000000..e4a7ab297
--- /dev/null
+++ b/spring-batch-samples/src/main/resources/data/skipJob/input/input1.txt
@@ -0,0 +1,5 @@
+UK21341EAH45,978,98.34,customer1
+UK21341EAH46,112,18.12,customer2
+UK21341EAH47,245,12.78,customer2
+UK21341EAH48,ERR,ERR,customer3
+UK21341EAH49,854,123.39,customer4
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/data/skipJob/input/input2.txt b/spring-batch-samples/src/main/resources/data/skipJob/input/input2.txt
new file mode 100644
index 000000000..b5b445671
--- /dev/null
+++ b/spring-batch-samples/src/main/resources/data/skipJob/input/input2.txt
@@ -0,0 +1,5 @@
+UK21341EAH50,323,38.24,customer5
+UK21341EAH51,654,69.32,customer6
+UK21341EAH52,723,96.53,customer7
+UK21341EAH53,754,17.43,customer8
+UK21341EAH54,934,49.23,customer9
diff --git a/spring-batch-samples/src/main/resources/jobs/fixedLengthImportJob.xml b/spring-batch-samples/src/main/resources/jobs/fixedLengthImportJob.xml
deleted file mode 100644
index dafc08e28..000000000
--- a/spring-batch-samples/src/main/resources/jobs/fixedLengthImportJob.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/jobs/incrementerJob.xml b/spring-batch-samples/src/main/resources/jobs/incrementerJob.xml
deleted file mode 100644
index efb1c70cc..000000000
--- a/spring-batch-samples/src/main/resources/jobs/incrementerJob.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/main/resources/jobs/jobExecutionContextSample.xml b/spring-batch-samples/src/main/resources/jobs/jobExecutionContextSample.xml
deleted file mode 100644
index b47a82eee..000000000
--- a/spring-batch-samples/src/main/resources/jobs/jobExecutionContextSample.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
- Simple example of inter-step communication using persistent job
- execution context.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/main/resources/jobs/nonSequentialDecisionJob.xml b/spring-batch-samples/src/main/resources/jobs/nonSequentialDecisionJob.xml
deleted file mode 100644
index 0435dc7f7..000000000
--- a/spring-batch-samples/src/main/resources/jobs/nonSequentialDecisionJob.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/main/resources/jobs/nonSequentialJob-base.xml b/spring-batch-samples/src/main/resources/jobs/nonSequentialJob-base.xml
deleted file mode 100644
index 1bbe7a4f6..000000000
--- a/spring-batch-samples/src/main/resources/jobs/nonSequentialJob-base.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SELECT games.player_id, games.year_no, SUM(COMPLETES),
- SUM(ATTEMPTS), SUM(PASSING_YARDS), SUM(PASSING_TD),
- SUM(INTERCEPTIONS), SUM(RUSHES), SUM(RUSH_YARDS),
- SUM(RECEPTIONS), SUM(RECEPTIONS_YARDS), SUM(TOTAL_TD)
- from games, players where players.player_id =
- games.player_id group by games.player_id, games.year_no
-
-
-
-
-
-
-
- games.file.name=games-small.csv
- job.commit.interval=2
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/main/resources/jobs/nonSequentialJob.xml b/spring-batch-samples/src/main/resources/jobs/nonSequentialJob.xml
deleted file mode 100644
index b79b23f55..000000000
--- a/spring-batch-samples/src/main/resources/jobs/nonSequentialJob.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/main/resources/jobs/restartSample.xml b/spring-batch-samples/src/main/resources/jobs/restartSample.xml
index 96e92ccc8..264b271cc 100644
--- a/spring-batch-samples/src/main/resources/jobs/restartSample.xml
+++ b/spring-batch-samples/src/main/resources/jobs/restartSample.xml
@@ -43,14 +43,14 @@
value="classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
-
+
-
diff --git a/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml b/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml
index 46ebc1874..cc59b2920 100644
--- a/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml
+++ b/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml
@@ -1,90 +1,116 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.springframework.batch.item.validator.ValidationException
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.springframework.batch.item.validator.ValidationException
+ java.lang.RuntimeException
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/jobs/taskletJob.xml b/spring-batch-samples/src/main/resources/jobs/taskletJob.xml
deleted file mode 100644
index 4ad469200..000000000
--- a/spring-batch-samples/src/main/resources/jobs/taskletJob.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
- Deletes files in given directory - TaskletStep is used as this
- is the kind of task that is not natural to split into read and
- write. In this case the step is wrapped in a standalone job,
- however typically it would be a setup step in a multi-step job.
-
- The second step illustrates executing a system command.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/incrementer-job-launcher-context.xml b/spring-batch-samples/src/main/resources/skipSample-job-launcher-context.xml
similarity index 92%
rename from spring-batch-samples/src/main/resources/incrementer-job-launcher-context.xml
rename to spring-batch-samples/src/main/resources/skipSample-job-launcher-context.xml
index 98b47f271..c34c4291d 100644
--- a/spring-batch-samples/src/main/resources/incrementer-job-launcher-context.xml
+++ b/spring-batch-samples/src/main/resources/skipSample-job-launcher-context.xml
@@ -32,7 +32,7 @@
p:databaseType="${environment}" p:dataSource-ref="dataSource" />
-
+
@@ -40,4 +40,7 @@
+
+
+
diff --git a/spring-batch-samples/src/main/sql/init.sql.vpp b/spring-batch-samples/src/main/sql/init.sql.vpp
index ad278cf00..9ead2b729 100644
--- a/spring-batch-samples/src/main/sql/init.sql.vpp
+++ b/spring-batch-samples/src/main/sql/init.sql.vpp
@@ -75,5 +75,7 @@ CREATE TABLE PLAYER_SUMMARY (
) $!{VOODOO};
CREATE TABLE ERROR_LOG (
- MESSAGE CHAR(300) NOT NULL
+ JOB_NAME CHAR(20) $!{NULL},
+ STEP_NAME CHAR(20) $!{NULL},
+ MESSAGE CHAR(300) NOT NULL
) $!{VOODOO};
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java
deleted file mode 100644
index 77631652a..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.sample;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import javax.sql.DataSource;
-
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.springframework.batch.item.ExecutionContext;
-import org.springframework.batch.item.file.FlatFileItemReader;
-import org.springframework.batch.item.file.mapping.DefaultLineMapper;
-import org.springframework.batch.item.file.mapping.FieldSetMapper;
-import org.springframework.batch.item.file.transform.LineTokenizer;
-import org.springframework.batch.sample.domain.trade.Trade;
-import org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.jdbc.core.RowCallbackHandler;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration()
-public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
-
- //expected line length in input file (sum of pattern lengths + 2, because the counter is appended twice)
- private static final int LINE_LENGTH = 29;
-
- //auto-injected attributes
- private SimpleJdbcTemplate simpleJdbcTemplate;
- private Resource fileLocator;
- protected FlatFileItemReader itemReader;
- private LineTokenizer lineTokenizer;
-
- @Autowired
- public void setDataSource(DataSource dataSource) {
- this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
- }
-
- @Autowired
- public void setLineTokenizer(LineTokenizer lineTokenizer) {
- this.lineTokenizer = lineTokenizer;
- }
-
-
- @Before
- public void onSetUp() throws Exception {
- simpleJdbcTemplate.update("delete from TRADE");
- fileLocator = new ClassPathResource("data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt");
- itemReader = new FlatFileItemReader();
-
- FieldSetMapper mapper = new TradeFieldSetMapper();
- DefaultLineMapper lineMapper = new DefaultLineMapper();
- lineMapper.setLineTokenizer(lineTokenizer);
- lineMapper.setFieldSetMapper(mapper);
- itemReader.setLineMapper(lineMapper);
-
-
- itemReader.setResource(fileLocator);
- itemReader.open(new ExecutionContext());
- }
-
- /**
- * Check that records have been correctly written to database
- * @throws Exception
- */
- protected void validatePostConditions() throws Exception {
-
-
- simpleJdbcTemplate.getJdbcOperations().query(
- "SELECT ID, ISIN, QUANTITY, PRICE, CUSTOMER FROM trade ORDER BY id",
- new RowCallbackHandler() {
- public void processRow(ResultSet rs) throws SQLException {
- Trade trade;
- try {
- trade = itemReader.read();
- }
- catch (Exception e) {
- throw new IllegalStateException(e.getMessage());
- }
- assertEquals(trade.getIsin(), rs.getString(2));
- assertEquals(trade.getQuantity(),rs.getLong(3));
- assertEquals(trade.getPrice(), rs.getBigDecimal(4));
- assertEquals(trade.getCustomer(), rs.getString(5));
- }
-
- });
-
- assertNull(itemReader.read());
- }
-
- /*
- * fixed-length file is expected on input
- */
- protected void validatePreConditions() throws Exception{
- BufferedReader reader;
-
- reader = new BufferedReader(new FileReader(fileLocator.getFile()));
- String line;
- while ((line = reader.readLine()) != null) {
- assertEquals (LINE_LENGTH, line.length());
- }
- }
-
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
index 22b094de2..0a8ddaf00 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java
@@ -47,8 +47,6 @@ public class HibernateFailureJobFunctionalTests extends AbstractCustomerCreditIn
setJobParameters(params);
writer.setFailOnFlush(2);
- int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
- assertTrue(before > 0);
try {
super.testLaunchJob();
} catch (HibernateJdbcException e) {
@@ -62,7 +60,7 @@ public class HibernateFailureJobFunctionalTests extends AbstractCustomerCreditIn
throw e;
}
int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
- assertEquals(before, after);
+ assertEquals(4, after);
}
/*
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/IncrementerJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/IncrementerJobFunctionalTests.java
deleted file mode 100644
index b24e416cb..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/IncrementerJobFunctionalTests.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.springframework.batch.sample;
-
-import static org.junit.Assert.*;
-
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.batch.core.launch.JobOperator;
-import org.springframework.batch.core.launch.JobParametersNotFoundException;
-import org.springframework.batch.core.launch.NoSuchJobException;
-import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
-import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
-import org.springframework.batch.core.repository.JobRestartException;
-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 = { "/incrementer-job-launcher-context.xml" })
-public class IncrementerJobFunctionalTests {
-
- private SimpleJdbcTemplate simpleJdbcTemplate;
-
- @Autowired
- private JobOperator jobOperator;
-
- /**
- * This test calls the same job twice. However, using a job incrementer, the
- * second launching is a separate job instance.
- *
- * Conditions:
- *
- * - Two flat files, each containing 20 player records
- *
- Job is started twice, using the job incrementer to chose the input
- * file.
- *
- * Expected Results:
- *
- * - First run completes with 20 players in the database
- *
- Second run completes with 40 players in the database.
- *
- */
- @Test
- public void testWithSkips() throws Exception {
- simpleJdbcTemplate.update("DELETE from PLAYERS");
-
- long id1 = this.launchJob();
- Map execution1 = this.getJobExecution(id1);
- assertEquals("COMPLETED", execution1.get("STATUS"));
- assertEquals(20, this.countPlayers());
-
- long id2 = this.launchJob();
- Map execution2 = this.getJobExecution(id2);
- assertEquals("COMPLETED", execution2.get("STATUS"));
- assertEquals(40, this.countPlayers());
-
- assertTrue(id1 != id2);
- assertTrue(!execution1.get("JOB_INSTANCE_ID").equals(execution2.get("JOB_INSTANCE_ID")));
- }
-
- private Map getJobExecution(long jobExecutionId) {
- return simpleJdbcTemplate.queryForMap("SELECT * from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID = ?",
- jobExecutionId);
- }
-
- private int countPlayers() {
- return SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "PLAYERS");
- }
-
- /**
- * Launch the entire job, including all steps, in order.
- *
- * @return JobExecution, so that the test may validate the exit status
- */
- public long launchJob() {
- try {
- return this.jobOperator.startNextInstance("incrementerJob");
- }
- catch (NoSuchJobException e) {
- throw new RuntimeException(e);
- }
- catch (JobExecutionAlreadyRunningException e) {
- throw new RuntimeException(e);
- }
- catch (JobParametersNotFoundException e) {
- throw new RuntimeException(e);
- }
- catch (JobRestartException e) {
- throw new RuntimeException(e);
- }
- catch (JobInstanceAlreadyCompleteException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Autowired
- public void setDataSource(DataSource dataSource) {
- this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
- }
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests.java
deleted file mode 100644
index e02821902..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.springframework.batch.sample;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.runner.RunWith;
-import org.springframework.batch.sample.tasklet.DummyMessageReceivingTasklet;
-import org.springframework.batch.sample.tasklet.DummyMessageSendingTasklet;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration()
-public class JobExecutionContextSampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
-
- @Autowired
- private DummyMessageSendingTasklet sender;
-
- @Autowired
- private DummyMessageReceivingTasklet receiver;
-
- protected void validatePostConditions() throws Exception {
- assertEquals(sender.getMessage(), receiver.getReceivedMessage());
- }
-
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultiResourceJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultiResourceJobFunctionalTests.java
index 16e977b5f..526e651ab 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultiResourceJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultiResourceJobFunctionalTests.java
@@ -1,50 +1,113 @@
-package org.springframework.batch.sample;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-
-import static org.junit.Assert.*;
-
-import org.junit.runner.RunWith;
-import org.springframework.batch.core.Job;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration()
-public class MultiResourceJobFunctionalTests extends FixedLengthImportJobFunctionalTests {
-
- /**
- * Context: 5 items overall, min. 2 items per output file, commitInterval=3,
- * => two files created, with 3 items in the first and two in second.
- */
- @Override
- protected void validatePostConditions() throws Exception {
- File file1 = new File("target/test-outputs/multiResourceOutput.txt.1");
- File file2 = new File("target/test-outputs/multiResourceOutput.txt.2");
- assertTrue(file1.exists());
- assertTrue(file2.exists());
-
- BufferedReader reader1 = new BufferedReader(new FileReader(file1));
- for (int i = 1; i <= 3; i++) {
- assertEquals(itemReader.read().toString(), reader1.readLine());
- }
- assertNull(reader1.readLine());
-
- BufferedReader reader2 = new BufferedReader(new FileReader(file2));
- for (int i = 1; i <= 2; i++) {
- assertEquals(itemReader.read().toString(), reader2.readLine());
- }
- assertNull(reader2.readLine());
-
- }
-
- @Autowired
- public void setJob(@Qualifier("multiResourceJob") Job job) {
- super.setJob(job);
- }
-
-}
+package org.springframework.batch.sample;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+import javax.sql.DataSource;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.springframework.batch.core.Job;
+import org.springframework.batch.item.ExecutionContext;
+import org.springframework.batch.item.file.FlatFileItemReader;
+import org.springframework.batch.item.file.mapping.DefaultLineMapper;
+import org.springframework.batch.item.file.mapping.FieldSetMapper;
+import org.springframework.batch.item.file.transform.LineTokenizer;
+import org.springframework.batch.sample.domain.trade.Trade;
+import org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration()
+public class MultiResourceJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
+
+ // expected line length in input file (sum of pattern lengths + 2, because
+ // the counter is appended twice)
+ private static final int LINE_LENGTH = 29;
+
+ // auto-injected attributes
+ private SimpleJdbcTemplate simpleJdbcTemplate;
+ private Resource fileLocator;
+ protected FlatFileItemReader itemReader;
+ private LineTokenizer lineTokenizer;
+
+ @Autowired
+ public void setDataSource(DataSource dataSource) {
+ this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
+ }
+
+ @Autowired
+ public void setLineTokenizer(LineTokenizer lineTokenizer) {
+ this.lineTokenizer = lineTokenizer;
+ }
+
+ @Before
+ public void onSetUp() throws Exception {
+ simpleJdbcTemplate.update("delete from TRADE");
+ fileLocator = new ClassPathResource(
+ "data/multiResourceJob/input/20070122.teststream.ImportTradeDataStep.txt");
+ itemReader = new FlatFileItemReader();
+
+ FieldSetMapper mapper = new TradeFieldSetMapper();
+ DefaultLineMapper lineMapper = new DefaultLineMapper();
+ lineMapper.setLineTokenizer(lineTokenizer);
+ lineMapper.setFieldSetMapper(mapper);
+ itemReader.setLineMapper(lineMapper);
+
+ itemReader.setResource(fileLocator);
+ itemReader.open(new ExecutionContext());
+ }
+
+ /*
+ * fixed-length file is expected on input
+ */
+ protected void validatePreConditions() throws Exception {
+ BufferedReader reader;
+
+ reader = new BufferedReader(new FileReader(fileLocator.getFile()));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ assertEquals(LINE_LENGTH, line.length());
+ }
+ }
+
+ /**
+ * Context: 5 items overall, min. 2 items per output file, commitInterval=3, =>
+ * two files created, with 3 items in the first and two in second.
+ */
+ @Override
+ protected void validatePostConditions() throws Exception {
+ File file1 = new File("target/test-outputs/multiResourceOutput.txt.1");
+ File file2 = new File("target/test-outputs/multiResourceOutput.txt.2");
+ assertTrue(file1.exists());
+ assertTrue(file2.exists());
+
+ BufferedReader reader1 = new BufferedReader(new FileReader(file1));
+ for (int i = 1; i <= 3; i++) {
+ assertEquals(itemReader.read().toString(), reader1.readLine());
+ }
+ assertNull(reader1.readLine());
+
+ BufferedReader reader2 = new BufferedReader(new FileReader(file2));
+ for (int i = 1; i <= 2; i++) {
+ assertEquals(itemReader.read().toString(), reader2.readLine());
+ }
+ assertNull(reader2.readLine());
+
+ }
+
+ @Autowired
+ public void setJob(@Qualifier("multiResourceJob")
+ Job job) {
+ super.setJob(job);
+ }
+}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialDecisionJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialDecisionJobFunctionalTests.java
deleted file mode 100644
index 66abad61c..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialDecisionJobFunctionalTests.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.springframework.batch.sample;
-
-import org.junit.runner.RunWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/nonSequentialDecisionJob.xml" })
-public class NonSequentialDecisionJobFunctionalTests extends NonSequentialJobFunctionalTestsBase {
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTests.java
deleted file mode 100644
index 099f358c2..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTests.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.springframework.batch.sample;
-
-import org.junit.runner.RunWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/nonSequentialJob.xml" })
-public class NonSequentialJobFunctionalTests extends NonSequentialJobFunctionalTestsBase {
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTestsBase.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTestsBase.java
deleted file mode 100644
index 992c2e3b9..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/NonSequentialJobFunctionalTestsBase.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.springframework.batch.sample;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.batch.core.BatchStatus;
-import org.springframework.batch.core.JobParameter;
-import org.springframework.batch.core.JobParameters;
-import org.springframework.batch.test.AbstractJobTests;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.test.jdbc.SimpleJdbcTestUtils;
-
-public abstract class NonSequentialJobFunctionalTestsBase extends AbstractJobTests {
-
- private SimpleJdbcTemplate simpleJdbcTemplate;
-
- @Before
- public void removeOldData() throws Exception {
- simpleJdbcTemplate.update("DELETE FROM PLAYERS");
- simpleJdbcTemplate.update("DELETE FROM GAMES");
- simpleJdbcTemplate.update("DELETE FROM PLAYER_SUMMARY");
- }
-
- /**
- * This test processes a file that contains bad records. Those records will
- * skip. The step execution listener will detect that skips have occurred,
- * and return an exit status that directs the flow job to the error logging
- * step. The error logging step will log an error.
- *
- * Conditions:
- *
- * - Flat file containing 20 player records, 5 are invalid
- *
- Skipping is allowed
- *
- * Expected Results:
- *
- * - 15 player records written to the database
- *
- 1 error logged to the database
- *
- */
- @Test
- public void testWithSkips() throws Exception {
- launchTest("player-containsBadRecords.csv");
- assertEquals(1, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG"));
- assertEquals(15, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "PLAYERS"));
- }
-
- /**
- * This test processes a file that contains all valid record. The step
- * execution listener will detect that NO skips have occurred, and return an
- * exit status that direct the flow job to bypass the error logging step.
- *
- * Conditions:
- *
- * - Flat file containing 20 player records, all are valid
- *
- Skipping is allowed
- *
- * Expected Results:
- *
- * - 20 player records written to the database
- *
- NO errors logged to the database
- *
- */
- @Test
- public void testWithoutSkips() throws Exception {
- launchTest("player-small1.csv");
- assertEquals(0, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG"));
- assertEquals(20, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "PLAYERS"));
- }
-
- private void launchTest(String playerInputfile) throws Exception {
- simpleJdbcTemplate.update("DELETE from ERROR_LOG");
- simpleJdbcTemplate.update("DELETE from PLAYER_SUMMARY");
- simpleJdbcTemplate.update("DELETE from PLAYERS");
- simpleJdbcTemplate.update("DELETE from GAMES");
-
- Map parameters = new HashMap();
- parameters.put("timestamp", new JobParameter(new Date().getTime()));
- parameters.put("player.file.name", new JobParameter(playerInputfile));
- JobParameters jobParameters = new JobParameters(parameters);
-
- assertEquals(BatchStatus.COMPLETED, this.launchJob(jobParameters).getStatus());
- }
-
- @Autowired
- public void setDataSource(DataSource dataSource) {
- this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
- }
-}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
index 2545db4fe..94373d524 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java
@@ -1,33 +1,46 @@
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
import javax.sql.DataSource;
import org.junit.Before;
+import org.junit.Test;
import org.junit.runner.RunWith;
-import org.springframework.batch.sample.support.ItemTrackingItemWriter;
+import org.springframework.batch.core.launch.JobOperator;
+import org.springframework.batch.core.launch.JobParametersNotFoundException;
+import org.springframework.batch.core.launch.NoSuchJobException;
+import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
+import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
+import org.springframework.batch.core.repository.JobRestartException;
+import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter;
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;
/**
* Error is encountered during writing - transaction is rolled back and the
* error item is skipped on second attempt to process the chunk.
*
* @author Robert Kasanicky
+ * @author Dan Garrette
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration()
-public class SkipSampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
+@ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" })
+public class SkipSampleFunctionalTests {
- int before = -1;
-
- SimpleJdbcTemplate simpleJdbcTemplate;
+ private SimpleJdbcTemplate simpleJdbcTemplate;
@Autowired
- ItemTrackingItemWriter> writer;
+ private JobOperator jobOperator;
+
+ @Autowired
+ private ItemTrackingTradeItemWriter itemTrackingWriter;
@Autowired
public void setDataSource(DataSource dataSource) {
@@ -35,18 +48,177 @@ public class SkipSampleFunctionalTests extends AbstractValidatingBatchLauncherTe
}
@Before
- public void onSetUp() throws Exception {
- before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
+ public void setUp() {
+ simpleJdbcTemplate.update("DELETE from TRADE");
+ simpleJdbcTemplate.update("DELETE from CUSTOMER");
+ for (int i = 1; i < 10; i++) {
+ simpleJdbcTemplate.update("INSERT INTO CUSTOMER VALUES (" + i + ", 0, 'customer" + i + "', 100000)");
+ }
+ simpleJdbcTemplate.update("DELETE from ERROR_LOG");
+
+ itemTrackingWriter.clearItems();
+ itemTrackingWriter.setWriteFailureISIN("UK21341EAH47");
}
- protected void validatePostConditions() throws Exception {
+ /**
+ * LAUNCH 1
+ *
+ * step1
+ *
+ * - The step name is saved to the job execution context.
+ *
- Read five records from flat file and insert them into the TRADE
+ * table.
+ *
- One record will be invalid, and it will be skipped. Four records
+ * will be written to the database.
+ *
- The skip will result in an exit status that directs the job to run
+ * the error logging step.
+ *
+ * errorPrint1
+ *
+ * - The error logging step will log one record using the step name from
+ * the job execution context.
+ *
+ * step2
+ *
+ * - The step name is saved to the job execution context.
+ *
- Read four records from the TRADE table and processes them.
+ *
- One record will be invalid, and it will be skipped. Three records
+ * will be stored in the writer's "items" property.
+ *
- The skip will result in an exit status that directs the job to run
+ * the error logging step.
+ *
+ * errorPrint2
+ *
+ * - The error logging step will log one record using the step name from
+ * the job execution context.
+ *
+ *
+ *
+ * LAUNCH 2
+ *
+ * step1
+ *
+ * - The step name is saved to the job execution context.
+ *
- Read five records from flat file and insert them into the TRADE
+ * table.
+ *
- No skips will occur.
+ *
- The exist status of SUCCESS will direct the job to step2.
+ *
+ * errorPrint1
+ *
+ * - This step does not occur. No error records are logged.
+ *
+ * step2
+ *
+ * - The step name is saved to the job execution context.
+ *
- Read five records from the TRADE table and processes them.
+ *
- No skips will occur.
+ *
- The exist status of SUCCESS will direct the job to end.
+ *
+ * errorPrint2
+ *
+ * - This step does not occur. No error records are logged.
+ *
+ */
+ @Test
+ public void testJobIncrementing() {
+ //
+ // Launch 1
+ //
+ long id1 = this.launchJobWithIncrementer();
+ Map execution1 = this.getJobExecution(id1);
+ assertEquals("COMPLETED", execution1.get("STATUS"));
- int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
- // 5 input records, 1 skipped => 4 written to output
- assertEquals(before + 4, after);
+ this.validateLaunchWithSkips();
+
+ //
+ // Clear the data
+ //
+ setUp();
+
+ //
+ // Launch 2
+ //
+ long id2 = this.launchJobWithIncrementer();
+ Map execution2 = this.getJobExecution(id2);
+ assertEquals("COMPLETED", execution2.get("STATUS"));
+
+ this.validateLaunchWithoutSkips();
+
+ //
+ // Make sure that the launches were separate executions and separate
+ // instances
+ //
+ assertTrue(id1 != id2);
+ assertTrue(!execution1.get("JOB_INSTANCE_ID").equals(execution2.get("JOB_INSTANCE_ID")));
+ }
+
+ /**
+ *
+ */
+ private void validateLaunchWithSkips() {
+ // Step1: 5 input records, 1 skipped => 4 written to output
+ assertEquals(4, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "TRADE"));
+
+ // Step2: 4 input records, 1 skipped => 3 written to output
+ assertEquals(3, itemTrackingWriter.getItems().size());
+
+ for(Object o : simpleJdbcTemplate.queryForList(
+ "SELECT * from ERROR_LOG"))
+ {
+ System.err.println("DHG > "+o);
+ }
- // no item was processed twice (one rollback occurred due to validation error)
- assertEquals(after - 1, writer.getItems().size());
+ // Both steps contained skips
+ assertEquals(2, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG"));
+ assertEquals(1, simpleJdbcTemplate.queryForInt(
+ "SELECT Count(*) from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", "skipJob", "step1"));
+ assertEquals(1, simpleJdbcTemplate.queryForInt(
+ "SELECT Count(*) from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", "skipJob", "step2"));
}
+ /**
+ *
+ */
+ private void validateLaunchWithoutSkips() {
+ // Step1: 5 input records => 5 written to output
+ assertEquals(5, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "TRADE"));
+
+ // Step2: 5 input records => 5 written to output
+ assertEquals(5, itemTrackingWriter.getItems().size());
+
+ // Neither step contained skips
+ assertEquals(0, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG"));
+ }
+
+ private Map getJobExecution(long jobExecutionId) {
+ return simpleJdbcTemplate.queryForMap("SELECT * from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID = ?",
+ jobExecutionId);
+ }
+
+ /**
+ * Launch the entire job, including all steps, in order.
+ *
+ * @return JobExecution, so that the test may validate the exit status
+ */
+ public long launchJobWithIncrementer() {
+ try {
+ return this.jobOperator.startNextInstance("skipJob");
+ }
+ catch (NoSuchJobException e) {
+ throw new RuntimeException(e);
+ }
+ catch (JobExecutionAlreadyRunningException e) {
+ throw new RuntimeException(e);
+ }
+ catch (JobParametersNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ catch (JobRestartException e) {
+ throw new RuntimeException(e);
+ }
+ catch (JobInstanceAlreadyCompleteException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java
deleted file mode 100644
index 2ca897d10..000000000
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TaskletJobFunctionalTests.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.springframework.batch.sample;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-
-import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-/**
- * Deletes files in the given directory.
- *
- * @author Robert Kasanicky
- */
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration()
-public class TaskletJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
-
- private static Resource directory = new FileSystemResource("target/test-outputs/test-dir");
-
- /*
- * Create the directory and some files in it.
- */
- @BeforeClass
- public static void onSetUp() throws Exception {
- File dir = directory.getFile();
- dir.mkdirs();
- new File(dir, "file1").createNewFile();
- new File(dir, "file2").createNewFile();
- }
-
- /**
- * We have directory with some files in it.
- */
- @Override
- protected void validatePreConditions() throws Exception {
- assertTrue(directory.getFile().isDirectory());
- assertTrue(directory.getFile().listFiles().length > 0);
- }
-
- /**
- * Directory still exists but contains no files.
- */
- @Override
- protected void validatePostConditions() throws Exception {
- assertTrue(directory.getFile().isDirectory());
- assertEquals(0, directory.getFile().listFiles().length);
- }
-
-}
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/ErrorLogTasklet.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java
similarity index 52%
rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/ErrorLogTasklet.java
rename to spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java
index f466ad761..05ad7a557 100644
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/ErrorLogTasklet.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java
@@ -1,26 +1,43 @@
-package org.springframework.batch.sample.domain.football.internal;
+package org.springframework.batch.sample.common;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.core.StepExecution;
+import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.core.AttributeAccessor;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-public class ErrorLogTasklet implements Tasklet {
+public class ErrorLogTasklet implements Tasklet, StepExecutionListener {
protected final Log logger = LogFactory.getLog(getClass());
private SimpleJdbcTemplate simpleJdbcTemplate;
+
+ private String jobName;
+ private String stepName;
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
- this.simpleJdbcTemplate.update("insert into ERROR_LOG values ('Some records were skipped!')");
+ this.simpleJdbcTemplate.update("insert into ERROR_LOG values ('"+jobName+"', '"+stepName+"', 'Some records were skipped!')");
return RepeatStatus.FINISHED;
}
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
+
+ public ExitStatus afterStep(StepExecution stepExecution) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void beforeStep(StepExecution stepExecution) {
+ this.jobName = stepExecution.getJobExecution().getJobInstance().getJobName().trim();
+ this.stepName = (String)stepExecution.getJobExecution().getExecutionContext().get("stepName");
+
+ }
}
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingDecider.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingDecider.java
similarity index 76%
rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingDecider.java
rename to spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingDecider.java
index c248fbc49..94bca625a 100644
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingDecider.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingDecider.java
@@ -1,4 +1,4 @@
-package org.springframework.batch.sample.domain.football.internal;
+package org.springframework.batch.sample.common;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
@@ -8,11 +8,12 @@ import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider
public class SkipCheckingDecider implements JobExecutionDecider {
public String decide(JobExecution jobExecution, StepExecution stepExecution) {
- if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
+ if (!stepExecution.getExitStatus().getExitCode().equals(
+ ExitStatus.FAILED.getExitCode())
&& stepExecution.getSkipCount() > 0) {
return "COMPLETED WITH SKIPS";
} else {
return ExitStatus.FINISHED.getExitCode();
}
}
-}
+}
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingListener.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingListener.java
similarity index 79%
rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingListener.java
rename to spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingListener.java
index 9ec4bd61c..0dd0aea03 100644
--- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/SkipCheckingListener.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/SkipCheckingListener.java
@@ -1,4 +1,4 @@
-package org.springframework.batch.sample.domain.football.internal;
+package org.springframework.batch.sample.common;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
@@ -16,5 +16,6 @@ public class SkipCheckingListener implements StepExecutionListener {
}
public void beforeStep(StepExecution stepExecution) {
+ stepExecution.getJobExecution().getExecutionContext().put("stepName", stepExecution.getStepName());
}
}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java
new file mode 100644
index 000000000..91b4a2bd0
--- /dev/null
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/TradeTests.java
@@ -0,0 +1,21 @@
+package org.springframework.batch.sample.domain.trade;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+
+import org.junit.Test;
+
+public class TradeTests {
+
+ @Test
+ public void testEquality(){
+
+ Trade trade1 = new Trade("isin", 1, new BigDecimal(1.1), "customer1");
+ Trade trade1Clone = new Trade("isin", 1, new BigDecimal(1.1), "customer1");
+ Trade trade2 = new Trade("isin", 1, new BigDecimal(2.3), "customer2");
+
+ assertEquals(trade1, trade1Clone);
+ assertFalse(trade1.equals(trade2));
+ }
+}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java
new file mode 100644
index 000000000..f1b6db8a9
--- /dev/null
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java
@@ -0,0 +1,39 @@
+package org.springframework.batch.sample.domain.trade.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.batch.item.ItemWriter;
+import org.springframework.batch.sample.domain.trade.Trade;
+
+public class ItemTrackingTradeItemWriter implements ItemWriter {
+ private List items = new ArrayList();
+ private String writeFailureISIN;
+
+ public void setWriteFailureISIN(String writeFailureISIN) {
+ this.writeFailureISIN = writeFailureISIN;
+ }
+
+ public void setItems(List items) {
+ this.items = items;
+ }
+
+ public List getItems() {
+ return items;
+ }
+
+ public void clearItems(){
+ this.items.clear();
+ }
+
+ public void write(List extends Trade> items) throws Exception {
+ List newItems = new ArrayList();
+ for(Trade t : items){
+ if (t.getIsin().equals(this.writeFailureISIN)){
+ throw new RuntimeException("write failed");
+ }
+ newItems.add(t);
+ }
+ this.items.addAll(newItems);
+ }
+}
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java
index c8741cfb4..20f58af5e 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/support/ItemTrackingItemWriterTests.java
@@ -21,49 +21,53 @@ import static org.junit.Assert.fail;
import java.util.Arrays;
import org.junit.Test;
+import org.springframework.batch.sample.domain.trade.Trade;
+import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter;
/**
* @author Dave Syer
- *
+ *
*/
public class ItemTrackingItemWriterTests {
-
- private ItemTrackingItemWriter writer = new ItemTrackingItemWriter();
+
+ private ItemTrackingTradeItemWriter writer = new ItemTrackingTradeItemWriter();
/**
- * Test method for {@link org.springframework.batch.sample.support.ItemTrackingItemWriter#write(java.util.List)}.
- * @throws Exception
+ * Test method for
+ * {@link org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter#write(java.util.List)}.
+ *
+ * @throws Exception
*/
@Test
public void testWrite() throws Exception {
assertEquals(0, writer.getItems().size());
- writer.write(Arrays.asList("a", "b", "c"));
+ Trade a = new Trade("a", 0, null, null);
+ Trade b = new Trade("b", 0, null, null);
+ Trade c = new Trade("c", 0, null, null);
+ writer.write(Arrays.asList(a, b, c));
assertEquals(3, writer.getItems().size());
}
@Test
public void testWriteFailure() throws Exception {
- writer.setWriteFailure(2);
+ writer.setWriteFailureISIN("c");
try {
- writer.write(Arrays.asList("a", "b", "c"));
+ Trade a = new Trade("a", 0, null, null);
+ Trade b = new Trade("b", 0, null, null);
+ Trade c = new Trade("c", 0, null, null);
+ writer.write(Arrays.asList(a, b, c));
fail("Expected Write Failure Exception");
}
catch (RuntimeException e) {
// expected
}
// the failed item is removed
- assertEquals(2, writer.getItems().size());
- writer.write(Arrays.asList("a", "e", "c"));
- assertEquals(5, writer.getItems().size());
- try {
- writer.write(Arrays.asList("f", "b", "g"));
- fail("Expected RuntimeException");
- }
- catch (RuntimeException e) {
- // expected
- }
- // barf immediately if a failure is detected
- assertEquals(5, writer.getItems().size());
- }
+ assertEquals(0, writer.getItems().size());
+ Trade e = new Trade("e", 0, null, null);
+ Trade f = new Trade("f", 0, null, null);
+ Trade g = new Trade("g", 0, null, null);
+ writer.write(Arrays.asList(e, f, g));
+ assertEquals(3, writer.getItems().size());
+ }
}
diff --git a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests-context.xml b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests-context.xml
deleted file mode 100644
index 1be281566..000000000
--- a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests-context.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests-context.xml b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests-context.xml
deleted file mode 100644
index d04503b41..000000000
--- a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/JobExecutionContextSampleFunctionalTests-context.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/SkipSampleFunctionalTests-context.xml b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/SkipSampleFunctionalTests-context.xml
deleted file mode 100644
index 9bc6e791c..000000000
--- a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/SkipSampleFunctionalTests-context.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
diff --git a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/TaskletJobFunctionalTests-context.xml b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/TaskletJobFunctionalTests-context.xml
deleted file mode 100644
index 71285d6a8..000000000
--- a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/TaskletJobFunctionalTests-context.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file