IN PROGRESS - issue BATCH-894: RFC: move ExitStatus up into Core?
Remove continuable from ExitStatus
This commit is contained in:
@@ -29,13 +29,13 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ExitStatus implements Serializable {
|
||||
public class ExitStatus implements Serializable, Comparable<ExitStatus> {
|
||||
|
||||
/**
|
||||
* Convenient constant value representing unknown state - assumed not
|
||||
* continuable.
|
||||
*/
|
||||
public static final ExitStatus UNKNOWN = new ExitStatus(false, "UNKNOWN");
|
||||
public static final ExitStatus UNKNOWN = new ExitStatus("UNKNOWN");
|
||||
|
||||
/**
|
||||
* Convenient constant value representing continuable state where processing
|
||||
@@ -44,62 +44,44 @@ public class ExitStatus implements Serializable {
|
||||
* another thread or process and the caller is not required to wait for the
|
||||
* result.
|
||||
*/
|
||||
public static final ExitStatus EXECUTING = new ExitStatus(true, "EXECUTING");
|
||||
public static final ExitStatus EXECUTING = new ExitStatus("EXECUTING");
|
||||
|
||||
/**
|
||||
* Convenient constant value representing finished processing.
|
||||
*/
|
||||
public static final ExitStatus FINISHED = new ExitStatus(false, "COMPLETED");
|
||||
public static final ExitStatus FINISHED = new ExitStatus("COMPLETED");
|
||||
|
||||
/**
|
||||
* Convenient constant value representing job that did no processing (e.g.
|
||||
* because it was already complete).
|
||||
*/
|
||||
public static final ExitStatus NOOP = new ExitStatus(false, "NOOP");
|
||||
public static final ExitStatus NOOP = new ExitStatus("NOOP");
|
||||
|
||||
/**
|
||||
* Convenient constant value representing finished processing with an error.
|
||||
*/
|
||||
public static final ExitStatus FAILED = new ExitStatus(false, "FAILED");
|
||||
public static final ExitStatus FAILED = new ExitStatus("FAILED");
|
||||
|
||||
/**
|
||||
* Convenient constant value representing finished processing with interrupted status.
|
||||
* Convenient constant value representing finished processing with
|
||||
* interrupted status.
|
||||
*/
|
||||
public static final ExitStatus INTERRUPTED = new ExitStatus(false, "INTERRUPTED");
|
||||
|
||||
private final boolean continuable;
|
||||
public static final ExitStatus INTERRUPTED = new ExitStatus("INTERRUPTED");
|
||||
|
||||
private final String exitCode;
|
||||
|
||||
private final String exitDescription;
|
||||
|
||||
public ExitStatus(boolean continuable) {
|
||||
this(continuable, "", "");
|
||||
public ExitStatus(String exitCode) {
|
||||
this(exitCode, "");
|
||||
}
|
||||
|
||||
public ExitStatus(boolean continuable, String exitCode) {
|
||||
this(continuable, exitCode, "");
|
||||
}
|
||||
|
||||
public ExitStatus(boolean continuable, String exitCode, String exitDescription) {
|
||||
public ExitStatus(String exitCode, String exitDescription) {
|
||||
super();
|
||||
this.continuable = continuable;
|
||||
this.exitCode = exitCode;
|
||||
this.exitDescription = exitDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to signal that processing can continue. This is distinct from any
|
||||
* flag that might indicate that a batch is complete, or terminated, since a
|
||||
* batch might be only a small part of a larger whole, which is still not
|
||||
* finished.
|
||||
*
|
||||
* @return true if processing can continue.
|
||||
*/
|
||||
public boolean isContinuable() {
|
||||
return continuable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the exit code (defaults to blank).
|
||||
*
|
||||
@@ -117,73 +99,78 @@ public class ExitStatus implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ExitStatus} with a logical combination of the
|
||||
* continuable flag.
|
||||
*
|
||||
* @param continuable true if the caller thinks it is safe to continue.
|
||||
* @return a new {@link ExitStatus} with {@link #isContinuable()} the
|
||||
* logical and of the current value and the argument provided.
|
||||
*/
|
||||
public ExitStatus and(boolean continuable) {
|
||||
return new ExitStatus(this.continuable && continuable, this.exitCode, this.exitDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ExitStatus} with a logical combination of the
|
||||
* continuable flag, and a concatenation of the descriptions. If either
|
||||
* value has a higher severity then its exit code will be used in the
|
||||
* result. In the case of equal severity, the exit code is only replaced if
|
||||
* the result is continuable or the input is not continuable.<br/>
|
||||
* Create a new {@link ExitStatus} with a logical combination of the exit
|
||||
* code, and a concatenation of the descriptions. If either value has a
|
||||
* higher severity then its exit code will be used in the result. In the
|
||||
* case of equal severity, the exit code is replaced if the new value is
|
||||
* alphabetically greater.<br/>
|
||||
* <br/>
|
||||
*
|
||||
* Severity is defined by the exit code:
|
||||
* <ul>
|
||||
* <li>Codes beginning with NOOP have severity 1</li>
|
||||
* <li>Codes beginning with INTERRUPTED have severity 2</li>
|
||||
* <li>Codes beginning with FAILED have severity 3</li>
|
||||
* <li>Codes beginning with UNKNOWN have severity 4</li>
|
||||
* <li>Codes beginning with EXECUTING have severity 0</li>
|
||||
* <li>Codes beginning with COMPLETED have severity 2</li>
|
||||
* <li>Codes beginning with NOOP have severity 3</li>
|
||||
* <li>Codes beginning with INTERRUPTED have severity 4</li>
|
||||
* <li>Codes beginning with FAILED have severity 5</li>
|
||||
* <li>Codes beginning with UNKNOWN have severity 6</li>
|
||||
* </ul>
|
||||
* Others have severity 0.<br/>
|
||||
* Others have severity 1.<br/>
|
||||
*
|
||||
* If the input is null just return this.
|
||||
*
|
||||
* @param status an {@link ExitStatus} to combine with this one.
|
||||
* @return a new {@link ExitStatus} with {@link #isContinuable()} the
|
||||
* logical and of the current value and the argument provided.
|
||||
* @return a new {@link ExitStatus} combining the current value and the
|
||||
* argument provided.
|
||||
*/
|
||||
public ExitStatus and(ExitStatus status) {
|
||||
if (status == null) {
|
||||
return this;
|
||||
}
|
||||
ExitStatus result = and(status.continuable).addExitDescription(status.exitDescription);
|
||||
if (severity(status) > severity(this)) {
|
||||
ExitStatus result = addExitDescription(status.exitDescription);
|
||||
if (compareTo(status) < 0) {
|
||||
result = result.replaceExitCode(status.exitCode);
|
||||
}
|
||||
else {
|
||||
if (severity(this) == severity(status) && (result.continuable || !status.continuable)) {
|
||||
result = result.replaceExitCode(status.exitCode);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param status an {@link ExitStatus} to compare
|
||||
* @return 1,0,-1 according to the severity and exit code
|
||||
*/
|
||||
public int compareTo(ExitStatus status) {
|
||||
if (severity(status) > severity(this)) {
|
||||
return -1;
|
||||
}
|
||||
if (severity(status) < severity(this)) {
|
||||
return 1;
|
||||
}
|
||||
return this.getExitCode().compareTo(status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
private int severity(ExitStatus status) {
|
||||
if (status.exitCode.startsWith(NOOP.exitCode)) {
|
||||
return 0;
|
||||
}
|
||||
if (status.exitCode.startsWith(INTERRUPTED.exitCode)) {
|
||||
return 1;
|
||||
}
|
||||
if (status.exitCode.startsWith(FAILED.exitCode)) {
|
||||
if (status.exitCode.startsWith(FINISHED.exitCode)) {
|
||||
return 2;
|
||||
}
|
||||
if (status.exitCode.startsWith(UNKNOWN.exitCode)) {
|
||||
if (status.exitCode.startsWith(NOOP.exitCode)) {
|
||||
return 3;
|
||||
}
|
||||
if (status.exitCode.startsWith(INTERRUPTED.exitCode)) {
|
||||
return 4;
|
||||
}
|
||||
if (status.exitCode.startsWith(FAILED.exitCode)) {
|
||||
return 5;
|
||||
}
|
||||
if (status.exitCode.startsWith(UNKNOWN.exitCode)) {
|
||||
return 6;
|
||||
}
|
||||
if (!status.exitCode.startsWith(EXECUTING.exitCode)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -193,7 +180,7 @@ public class ExitStatus implements Serializable {
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return String.format("continuable=%s;exitCode=%s;exitDescription=%s", continuable, exitCode, exitDescription);
|
||||
return String.format("exitCode=%s;exitDescription=%s", exitCode, exitDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +213,7 @@ public class ExitStatus implements Serializable {
|
||||
* code.
|
||||
*/
|
||||
public ExitStatus replaceExitCode(String code) {
|
||||
return new ExitStatus(continuable, code, exitDescription);
|
||||
return new ExitStatus(code, exitDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +246,7 @@ public class ExitStatus implements Serializable {
|
||||
if (changed) {
|
||||
buffer.append(description);
|
||||
}
|
||||
return new ExitStatus(continuable, exitCode, buffer.toString());
|
||||
return new ExitStatus(exitCode, buffer.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,25 +39,25 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
private static final Log logger = LogFactory.getLog(JdbcJobExecutionDao.class);
|
||||
|
||||
private static final String SAVE_JOB_EXECUTION = "INSERT into %PREFIX%JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, "
|
||||
+ "END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
+ "END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String CHECK_JOB_EXECUTION_EXISTS = "SELECT COUNT(*) FROM %PREFIX%JOB_EXECUTION WHERE JOB_EXECUTION_ID = ?";
|
||||
|
||||
private static final String GET_STATUS = "SELECT STATUS from %PREFIX%JOB_EXECUTION where JOB_EXECUTION_ID = ?";
|
||||
|
||||
private static final String UPDATE_JOB_EXECUTION = "UPDATE %PREFIX%JOB_EXECUTION set START_TIME = ?, END_TIME = ?, "
|
||||
+ " STATUS = ?, CONTINUABLE = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?";
|
||||
+ " STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?";
|
||||
|
||||
private static final String FIND_JOB_EXECUTIONS = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION"
|
||||
private static final String FIND_JOB_EXECUTIONS = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION"
|
||||
+ " from %PREFIX%JOB_EXECUTION where JOB_INSTANCE_ID = ? order by JOB_EXECUTION_ID desc";
|
||||
|
||||
private static final String GET_LAST_EXECUTION = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION "
|
||||
private static final String GET_LAST_EXECUTION = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION "
|
||||
+ "from %PREFIX%JOB_EXECUTION where JOB_INSTANCE_ID = ? and CREATE_TIME = (SELECT max(CREATE_TIME) from %PREFIX%JOB_EXECUTION where JOB_INSTANCE_ID = ?)";
|
||||
|
||||
private static final String GET_EXECUTION_BY_ID = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION"
|
||||
private static final String GET_EXECUTION_BY_ID = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION"
|
||||
+ " from %PREFIX%JOB_EXECUTION where JOB_EXECUTION_ID = ?";
|
||||
|
||||
private static final String GET_RUNNING_EXECUTIONS = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION "
|
||||
private static final String GET_RUNNING_EXECUTIONS = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION "
|
||||
+ "JOB_INSTANCE_ID from %PREFIX%JOB_EXECUTION where END_TIME is NULL order by JOB_EXECUTION_ID desc";
|
||||
|
||||
private static final String CURRENT_VERSION_JOB_EXECUTION = "SELECT VERSION FROM %PREFIX%JOB_EXECUTION WHERE JOB_EXECUTION_ID=?";
|
||||
@@ -117,13 +117,12 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
jobExecution.setId(new Long(jobExecutionIncrementer.nextLongValue()));
|
||||
Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(),
|
||||
jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(),
|
||||
jobExecution.getExitStatus().isContinuable() ? "Y" : "N", jobExecution.getExitStatus().getExitCode(),
|
||||
jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(),
|
||||
jobExecution.getCreateTime(), jobExecution.getLastUpdated() };
|
||||
jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(),
|
||||
jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated() };
|
||||
getJdbcTemplate().getJdbcOperations().update(
|
||||
getQuery(SAVE_JOB_EXECUTION),
|
||||
parameters,
|
||||
new int[] { Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR,
|
||||
new int[] { Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR,
|
||||
Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP });
|
||||
}
|
||||
|
||||
@@ -169,9 +168,9 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
logger.debug("Truncating long message before update of JobExecution: " + jobExecution);
|
||||
}
|
||||
Object[] parameters = new Object[] { jobExecution.getStartTime(), jobExecution.getEndTime(),
|
||||
jobExecution.getStatus().toString(), jobExecution.getExitStatus().isContinuable() ? "Y" : "N",
|
||||
jobExecution.getExitStatus().getExitCode(), exitDescription, version, jobExecution.getCreateTime(),
|
||||
jobExecution.getLastUpdated(), jobExecution.getId(), jobExecution.getVersion() };
|
||||
jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), exitDescription,
|
||||
version, jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getId(),
|
||||
jobExecution.getVersion() };
|
||||
|
||||
// Check if given JobExecution's Id already exists, if none is found
|
||||
// it
|
||||
@@ -185,9 +184,8 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
int count = getJdbcTemplate().getJdbcOperations().update(
|
||||
getQuery(UPDATE_JOB_EXECUTION),
|
||||
parameters,
|
||||
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, Types.VARCHAR,
|
||||
Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.INTEGER,
|
||||
Types.INTEGER });
|
||||
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER });
|
||||
|
||||
// Avoid concurrent modifications...
|
||||
if (count == 0) {
|
||||
@@ -293,10 +291,10 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
jobExecution.setStartTime(rs.getTimestamp(2));
|
||||
jobExecution.setEndTime(rs.getTimestamp(3));
|
||||
jobExecution.setStatus(BatchStatus.valueOf(rs.getString(4)));
|
||||
jobExecution.setExitStatus(new ExitStatus("Y".equals(rs.getString(5)), rs.getString(6), rs.getString(7)));
|
||||
jobExecution.setCreateTime(rs.getTimestamp(8));
|
||||
jobExecution.setLastUpdated(rs.getTimestamp(9));
|
||||
jobExecution.setVersion(rs.getInt(10));
|
||||
jobExecution.setExitStatus(new ExitStatus(rs.getString(5), rs.getString(6)));
|
||||
jobExecution.setCreateTime(rs.getTimestamp(7));
|
||||
jobExecution.setLastUpdated(rs.getTimestamp(8));
|
||||
jobExecution.setVersion(rs.getInt(9));
|
||||
return jobExecution;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,16 +41,16 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
private static final Log logger = LogFactory.getLog(JdbcStepExecutionDao.class);
|
||||
|
||||
private static final String SAVE_STEP_EXECUTION = "INSERT into %PREFIX%STEP_EXECUTION(STEP_EXECUTION_ID, VERSION, STEP_NAME, JOB_EXECUTION_ID, START_TIME, "
|
||||
+ "END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED) "
|
||||
+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
+ "END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED) "
|
||||
+ "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String UPDATE_STEP_EXECUTION = "UPDATE %PREFIX%STEP_EXECUTION set START_TIME = ?, END_TIME = ?, "
|
||||
+ "STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, CONTINUABLE = ? , EXIT_CODE = ?, "
|
||||
+ "STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, "
|
||||
+ "EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ?"
|
||||
+ " where STEP_EXECUTION_ID = ? and VERSION = ?";
|
||||
|
||||
private static final String GET_RAW_STEP_EXECUTIONS = "SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT,"
|
||||
+ " READ_COUNT, FILTER_COUNT, WRITE_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from %PREFIX%STEP_EXECUTION where JOB_EXECUTION_ID = ?";
|
||||
+ " READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from %PREFIX%STEP_EXECUTION where JOB_EXECUTION_ID = ?";
|
||||
|
||||
private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS + " order by STEP_EXECUTION_ID";
|
||||
|
||||
@@ -104,16 +104,16 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(),
|
||||
stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
|
||||
stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
|
||||
stepExecution.getExitStatus().isContinuable() ? "Y" : "N", stepExecution.getExitStatus().getExitCode(),
|
||||
exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(),
|
||||
stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
|
||||
stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(),
|
||||
stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(),
|
||||
stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
|
||||
getJdbcTemplate().getJdbcOperations().update(
|
||||
getQuery(SAVE_STEP_EXECUTION),
|
||||
parameters,
|
||||
new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP,
|
||||
Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.TIMESTAMP });
|
||||
Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.TIMESTAMP });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,19 +149,16 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(),
|
||||
stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(),
|
||||
stepExecution.getFilterCount(), stepExecution.getWriteCount(),
|
||||
stepExecution.getExitStatus().isContinuable() ? "Y" : "N",
|
||||
stepExecution.getExitStatus().getExitCode(), exitDescription, version,
|
||||
stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(),
|
||||
stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(),
|
||||
stepExecution.getVersion() };
|
||||
int count = getJdbcTemplate().getJdbcOperations()
|
||||
.update(
|
||||
getQuery(UPDATE_STEP_EXECUTION),
|
||||
parameters,
|
||||
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.CHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP,
|
||||
Types.INTEGER, Types.INTEGER });
|
||||
int count = getJdbcTemplate().getJdbcOperations().update(
|
||||
getQuery(UPDATE_STEP_EXECUTION),
|
||||
parameters,
|
||||
new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER });
|
||||
|
||||
// Avoid concurrent modifications...
|
||||
if (count == 0) {
|
||||
@@ -230,14 +227,13 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
stepExecution.setReadCount(rs.getInt(7));
|
||||
stepExecution.setFilterCount(rs.getInt(8));
|
||||
stepExecution.setWriteCount(rs.getInt(9));
|
||||
stepExecution
|
||||
.setExitStatus(new ExitStatus("Y".equals(rs.getString(10)), rs.getString(11), rs.getString(12)));
|
||||
stepExecution.setReadSkipCount(rs.getInt(13));
|
||||
stepExecution.setWriteSkipCount(rs.getInt(14));
|
||||
stepExecution.setProcessSkipCount(rs.getInt(15));
|
||||
stepExecution.setRollbackCount(rs.getInt(16));
|
||||
stepExecution.setLastUpdated(rs.getTimestamp(17));
|
||||
stepExecution.setVersion(rs.getInt(18));
|
||||
stepExecution.setExitStatus(new ExitStatus(rs.getString(10), rs.getString(11)));
|
||||
stepExecution.setReadSkipCount(rs.getInt(12));
|
||||
stepExecution.setWriteSkipCount(rs.getInt(13));
|
||||
stepExecution.setProcessSkipCount(rs.getInt(14));
|
||||
stepExecution.setRollbackCount(rs.getInt(15));
|
||||
stepExecution.setLastUpdated(rs.getTimestamp(16));
|
||||
stepExecution.setVersion(rs.getInt(17));
|
||||
return stepExecution;
|
||||
}
|
||||
|
||||
|
||||
@@ -353,7 +353,7 @@ public abstract class AbstractStep implements Step, InitializingBean,
|
||||
.addExitDescription(JobInterruptedException.class.getName());
|
||||
} else if (ex instanceof NoSuchJobException
|
||||
|| ex.getCause() instanceof NoSuchJobException) {
|
||||
exitStatus = new ExitStatus(false, ExitCodeMapper.NO_SUCH_JOB, ex
|
||||
exitStatus = new ExitStatus(ExitCodeMapper.NO_SUCH_JOB, ex
|
||||
.getClass().getName());
|
||||
} else {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -29,39 +28,21 @@ import org.springframework.batch.core.ExitStatus;
|
||||
*/
|
||||
public class ExitStatusTests {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusBooleanInt() {
|
||||
ExitStatus status = new ExitStatus(true, "10");
|
||||
assertTrue(status.isContinuable());
|
||||
ExitStatus status = new ExitStatus("10");
|
||||
assertEquals("10", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsContinuable() {
|
||||
ExitStatus status = ExitStatus.EXECUTING;
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("EXECUTING", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsFinished() {
|
||||
ExitStatus status = ExitStatus.FINISHED;
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals("COMPLETED", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -72,18 +53,18 @@ public class ExitStatusTests {
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsWithSameProperties() throws Exception {
|
||||
assertEquals(ExitStatus.EXECUTING, new ExitStatus(true, "EXECUTING"));
|
||||
assertEquals(ExitStatus.EXECUTING, new ExitStatus("EXECUTING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsSelf() {
|
||||
ExitStatus status = new ExitStatus(true, "test");
|
||||
ExitStatus status = new ExitStatus("test");
|
||||
assertEquals(status, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertEquals(new ExitStatus(true, "test"), new ExitStatus(true, "test"));
|
||||
assertEquals(new ExitStatus("test"), new ExitStatus("test"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,30 +87,14 @@ public class ExitStatusTests {
|
||||
assertEquals(ExitStatus.EXECUTING.toString().hashCode(), ExitStatus.EXECUTING.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(boolean)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAndBoolean() {
|
||||
assertTrue(ExitStatus.EXECUTING.and(true).isContinuable());
|
||||
assertFalse(ExitStatus.EXECUTING.and(false).isContinuable());
|
||||
ExitStatus status = new ExitStatus(false, "CUSTOM_CODE", "CUSTOM_DESCRIPTION");
|
||||
assertTrue(status.and(true).getExitCode() == "CUSTOM_CODE");
|
||||
assertTrue(status.and(true).getExitDescription() == "CUSTOM_DESCRIPTION");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusStillContinuable() {
|
||||
assertTrue(ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).isContinuable());
|
||||
assertFalse(ExitStatus.EXECUTING.and(ExitStatus.FINISHED).isContinuable());
|
||||
assertTrue(ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).getExitCode().equals(
|
||||
ExitStatus.EXECUTING.getExitCode()));
|
||||
public void testAndExitStatusStillExecutable() {
|
||||
assertEquals(ExitStatus.EXECUTING.getExitCode(), ExitStatus.EXECUTING.and(ExitStatus.EXECUTING).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,8 +124,17 @@ public class ExitStatusTests {
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomContinuableAddedToContinuable() {
|
||||
assertEquals("CUSTOM", ExitStatus.EXECUTING.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM"))
|
||||
.getExitCode());
|
||||
assertEquals("CUSTOM", ExitStatus.EXECUTING.and(ExitStatus.EXECUTING.replaceExitCode("CUSTOM")).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomCompletedAddedToCompleted() {
|
||||
assertEquals("COMPLETED_CUSTOM", ExitStatus.FINISHED.and(ExitStatus.EXECUTING.replaceExitCode("COMPLETED_CUSTOM")).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +163,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCode() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -197,7 +170,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCodeToExistingStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO").replaceExitCode("BAR");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("BAR", status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -205,7 +177,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitCodeToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode(ExitStatus.EXECUTING.getExitCode());
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals(ExitStatus.EXECUTING.getExitCode(), status.getExitCode());
|
||||
}
|
||||
|
||||
@@ -213,7 +184,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitDescription() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@@ -221,7 +191,6 @@ public class ExitStatusTests {
|
||||
public void testAddExitDescriptionToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.EXECUTING.addExitDescription("Foo").addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.EXECUTING != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@@ -233,7 +202,7 @@ public class ExitStatusTests {
|
||||
|
||||
@Test
|
||||
public void testAddExitCodeWithDescription() throws Exception {
|
||||
ExitStatus status = new ExitStatus(true, "BAR", "Bar").replaceExitCode("FOO");
|
||||
ExitStatus status = new ExitStatus("BAR", "Bar").replaceExitCode("FOO");
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
assertEquals("Bar", status.getExitDescription());
|
||||
}
|
||||
@@ -250,7 +219,6 @@ public class ExitStatusTests {
|
||||
Object object = SerializationUtils.deserialize(bytes);
|
||||
assertTrue(object instanceof ExitStatus);
|
||||
ExitStatus restored = (ExitStatus) object;
|
||||
assertTrue(restored.isContinuable());
|
||||
assertEquals(status.getExitCode(), restored.getExitCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -29,11 +33,12 @@ import org.junit.Test;
|
||||
*/
|
||||
public class JobExecutionTests {
|
||||
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"), new Long(12));
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"),
|
||||
new Long(12));
|
||||
|
||||
@Test
|
||||
public void testJobExecution() {
|
||||
assertNull(new JobExecution(new JobInstance(null,null,"foo")).getId());
|
||||
assertNull(new JobExecution(new JobInstance(null, null, "foo")).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +165,7 @@ public class JobExecutionTests {
|
||||
@Test
|
||||
public void testGetExitCode() {
|
||||
assertEquals(ExitStatus.UNKNOWN, execution.getExitStatus());
|
||||
execution.setExitStatus(new ExitStatus(true, "23"));
|
||||
execution.setExitStatus(new ExitStatus("23"));
|
||||
assertEquals("23", execution.getExitStatus().getExitCode());
|
||||
}
|
||||
|
||||
@@ -175,7 +180,7 @@ public class JobExecutionTests {
|
||||
execution.createStepExecution("step");
|
||||
assertEquals(1, execution.getStepExecutions().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStop() throws Exception {
|
||||
StepExecution stepExecution = execution.createStepExecution("step");
|
||||
@@ -192,11 +197,11 @@ public class JobExecutionTests {
|
||||
|
||||
@Test
|
||||
public void testToStringWithNullJob() throws Exception {
|
||||
execution = new JobExecution(new JobInstance(null,null,"foo"));
|
||||
execution = new JobExecution(new JobInstance(null, null, "foo"));
|
||||
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
@@ -205,9 +210,9 @@ public class JobExecutionTests {
|
||||
assertNotNull(deserialize.createStepExecution("foo"));
|
||||
assertNotNull(deserialize.getFailureExceptions());
|
||||
}
|
||||
|
||||
public void testFailureExceptions(){
|
||||
|
||||
|
||||
public void testFailureExceptions() {
|
||||
|
||||
RuntimeException exception = new RuntimeException();
|
||||
assertEquals(0, execution.getFailureExceptions().size());
|
||||
execution.addFailureException(exception);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SimpleJobTests {
|
||||
private JobExecutionDao jobExecutionDao;
|
||||
|
||||
private StepExecutionDao stepExecutionDao;
|
||||
|
||||
|
||||
private ExecutionContextDao ecDao;
|
||||
|
||||
private List<Serializable> list = new ArrayList<Serializable>();
|
||||
@@ -163,7 +163,7 @@ public class SimpleJobTests {
|
||||
@Test
|
||||
public void testExitStatusReturned() throws JobExecutionException {
|
||||
|
||||
final ExitStatus customStatus = new ExitStatus(true, "test");
|
||||
final ExitStatus customStatus = new ExitStatus("test");
|
||||
|
||||
Step testStep = new Step() {
|
||||
|
||||
@@ -260,7 +260,7 @@ public class SimpleJobTests {
|
||||
step2.setStartLimit(5);
|
||||
final RuntimeException exception = new RuntimeException("Foo!");
|
||||
step1.setProcessException(exception);
|
||||
|
||||
|
||||
job.execute(jobExecution);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
assertEquals(exception, jobExecution.getAllFailureExceptions().get(0));
|
||||
@@ -306,11 +306,11 @@ public class SimpleJobTests {
|
||||
step1.setStartLimit(0);
|
||||
|
||||
job.execute(jobExecution);
|
||||
|
||||
|
||||
assertEquals(1, jobExecution.getFailureExceptions().size());
|
||||
Throwable ex = jobExecution.getFailureExceptions().get(0);
|
||||
assertTrue("Wrong message in exception: " + ex.getMessage(), ex.getMessage()
|
||||
.indexOf("start limit exceeded") >= 0);
|
||||
assertTrue("Wrong message in exception: " + ex.getMessage(),
|
||||
ex.getMessage().indexOf("start limit exceeded") >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,7 +340,7 @@ public class SimpleJobTests {
|
||||
public void testNotExecutedIfAlreadyStopped() throws Exception {
|
||||
jobExecution.stop();
|
||||
job.execute(jobExecution);
|
||||
|
||||
|
||||
assertEquals(0, list.size());
|
||||
checkRepository(BatchStatus.STOPPED, ExitStatus.NOOP);
|
||||
ExitStatus exitStatus = jobExecution.getExitStatus();
|
||||
@@ -430,9 +430,9 @@ public class SimpleJobTests {
|
||||
job.execute(jobExecution);
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
Throwable expected = jobExecution.getAllFailureExceptions().get(0);
|
||||
assertTrue("Wrong exception "+expected, expected instanceof JobInterruptedException);
|
||||
assertTrue("Wrong exception " + expected, expected instanceof JobInterruptedException);
|
||||
assertEquals("JobExecution interrupted.", expected.getMessage());
|
||||
|
||||
|
||||
assertNull("Second step was not supposed to be executed", step2.passedInStepContext);
|
||||
}
|
||||
|
||||
@@ -490,7 +490,9 @@ public class SimpleJobTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.step.StepSupport#execute(org.springframework.batch.core.StepExecution)
|
||||
*
|
||||
* @seeorg.springframework.batch.core.step.StepSupport#execute(org.
|
||||
* springframework.batch.core.StepExecution)
|
||||
*/
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException,
|
||||
UnexpectedJobExecutionException {
|
||||
|
||||
@@ -36,7 +36,8 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#setListeners(org.springframework.batch.core.StepExecutionListener[])}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#setListeners(org.springframework.batch.core.StepExecutionListener[])}
|
||||
* .
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() {
|
||||
@@ -50,13 +51,14 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
return ExitStatus.EXECUTING;
|
||||
}
|
||||
} });
|
||||
assertFalse(listener.afterStep(null).isContinuable());
|
||||
assertEquals(ExitStatus.FAILED, listener.afterStep(null));
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#register(org.springframework.batch.core.StepExecutionListener)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#register(org.springframework.batch.core.StepExecutionListener)}
|
||||
* .
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new StepExecutionListenerSupport() {
|
||||
@@ -65,13 +67,14 @@ public class CompositeStepExecutionListenerTests extends TestCase {
|
||||
return ExitStatus.FAILED;
|
||||
}
|
||||
});
|
||||
assertFalse(listener.afterStep(null).isContinuable());
|
||||
assertEquals(ExitStatus.FAILED, listener.afterStep(null));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeStepExecutionListener#beforeStep(StepExecution)}
|
||||
* .
|
||||
*/
|
||||
public void testOpen() {
|
||||
listener.register(new StepExecutionListenerSupport() {
|
||||
|
||||
@@ -237,7 +237,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ExitStatus status = stepExecution.getExitStatus();
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals(ExitStatus.FINISHED, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ExitStatus status = stepExecution.getExitStatus();
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals(ExitStatus.FAILED.getExitCode(), status.getExitCode());
|
||||
String description = status.getExitDescription();
|
||||
assertTrue("Description does not include 'FOO': " + description, description.indexOf("FOO") >= 0);
|
||||
}
|
||||
@@ -323,9 +323,9 @@ public class TaskletStepTests {
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
step.execute(stepExecution);
|
||||
Throwable e = stepExecution.getFailureExceptions().get(0);
|
||||
Throwable e = stepExecution.getFailureExceptions().get(0);
|
||||
assertEquals("Fatal error detected during save of step execution context", e.getMessage());
|
||||
assertEquals("foo", e.getCause().getMessage());
|
||||
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
|
||||
@@ -452,7 +452,7 @@ public class TaskletStepTests {
|
||||
@Test
|
||||
public void testAfterStep() throws Exception {
|
||||
|
||||
final ExitStatus customStatus = new ExitStatus(false, "custom code");
|
||||
final ExitStatus customStatus = new ExitStatus("COMPLETED_CUSTOM");
|
||||
|
||||
step.setStepExecutionListeners(new StepExecutionListener[] { new StepExecutionListenerSupport() {
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
@@ -520,7 +520,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusForInterruptedException() throws Exception{
|
||||
public void testStatusForInterruptedException() throws Exception {
|
||||
|
||||
StepInterruptionPolicy interruptionPolicy = new StepInterruptionPolicy() {
|
||||
|
||||
@@ -551,7 +551,7 @@ public class TaskletStepTests {
|
||||
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertTrue("Message does not contain 'JobInterruptedException': " + msg, contains(msg,
|
||||
"JobInterruptedException"));
|
||||
"JobInterruptedException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -702,7 +702,7 @@ public class TaskletStepTests {
|
||||
// step.setLastExecution(stepExecution);
|
||||
|
||||
step.execute(stepExecution);
|
||||
// The job actually completed, but the streams couldn't be closed.
|
||||
// The job actually completed, but the streams couldn't be closed.
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertEquals("", msg);
|
||||
@@ -756,7 +756,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception in {@link StepExecutionListener#afterStep(StepExecution)}
|
||||
* Exception in {@link StepExecutionListener#afterStep(StepExecution)}
|
||||
* doesn't cause step failure.
|
||||
* @throws JobInterruptedException
|
||||
*/
|
||||
@@ -774,19 +774,18 @@ public class TaskletStepTests {
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModifyingExecutionContextMidProcessCausesException() throws Exception{
|
||||
public void testModifyingExecutionContextMidProcessCausesException() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
final ExecutionContext ec = stepExecution.getExecutionContext();
|
||||
step.setTasklet(new Tasklet(){
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
AttributeAccessor attributes) throws Exception {
|
||||
step.setTasklet(new Tasklet() {
|
||||
public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
ec.putString("test", "test");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
assertEquals(1, stepExecution.getFailureExceptions().size());
|
||||
@@ -810,11 +809,11 @@ public class TaskletStepTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class JobRepositoryFailedUpdateStub extends JobRepositorySupport {
|
||||
|
||||
|
||||
private int called = 0;
|
||||
|
||||
|
||||
public void update(StepExecution stepExecution) {
|
||||
called++;
|
||||
if (called == 3) {
|
||||
|
||||
@@ -157,9 +157,8 @@ public class ChunkMessageChannelItemWriter<T> extends StepExecutionListenerSuppo
|
||||
+ jobInstanceId + "] should have been [" + localState.getJobId() + "].");
|
||||
localState.actual++;
|
||||
// TODO: apply the skip count
|
||||
ExitStatus result = payload.getExitStatus();
|
||||
// TODO: check it can never be ExitStatus.FINISHED?
|
||||
if (!result.isContinuable()) {
|
||||
BatchStatus result = payload.getStatus();
|
||||
if (BatchStatus.COMPLETED!=result) {
|
||||
throw new AsynchronousFailureException("Failure or early completion detected in handler: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.batch.integration.chunk;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
@@ -45,12 +45,11 @@ public class ChunkProcessorChunkHandler<S> implements ChunkHandler<S>, Initializ
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.debug("Failed chunk", e);
|
||||
return new ChunkResponse(ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": "
|
||||
+ e.getMessage()), chunkRequest.getJobId(), skipCount);
|
||||
return new ChunkResponse(BatchStatus.FAILED, chunkRequest.getJobId(), skipCount);
|
||||
}
|
||||
|
||||
logger.debug("Completed chunk handling with " + skipCount + " skips");
|
||||
return new ChunkResponse(ExitStatus.EXECUTING, chunkRequest.getJobId(), skipCount);
|
||||
return new ChunkResponse(BatchStatus.COMPLETED, chunkRequest.getJobId(), skipCount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ package org.springframework.batch.integration.chunk;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
|
||||
public class ChunkResponse implements Serializable {
|
||||
|
||||
private final int skipCount;
|
||||
private final Long jobId;
|
||||
private final ExitStatus exitStatus;
|
||||
private final BatchStatus status;
|
||||
|
||||
public ChunkResponse(ExitStatus exitStatus, Long jobId, int skipCount) {
|
||||
this.exitStatus = exitStatus;
|
||||
public ChunkResponse(BatchStatus status, Long jobId, int skipCount) {
|
||||
this.status = status;
|
||||
this.jobId = jobId;
|
||||
this.skipCount = skipCount;
|
||||
}
|
||||
@@ -24,8 +24,8 @@ public class ChunkResponse implements Serializable {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
public ExitStatus getExitStatus() {
|
||||
return exitStatus;
|
||||
public BatchStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ public class ChunkResponse implements Serializable {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+": jobId="+jobId+", skipCount="+skipCount+", status="+exitStatus;
|
||||
return getClass().getSimpleName()+": jobId="+jobId+", skipCount="+skipCount+", status="+status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class ChunkProcessorChunkHandlerTests {
|
||||
@@ -27,7 +27,7 @@ public class ChunkProcessorChunkHandlerTests {
|
||||
12L, 10));
|
||||
assertEquals(0, response.getSkipCount());
|
||||
assertEquals(new Long(12L), response.getJobId());
|
||||
assertEquals(ExitStatus.EXECUTING, response.getExitStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, response.getStatus());
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public class SkipCheckingListener implements StepExecutionListener {
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
|
||||
&& stepExecution.getSkipCount() > 0) {
|
||||
return new ExitStatus(false, "COMPLETED WITH SKIPS");
|
||||
return new ExitStatus("COMPLETED WITH SKIPS");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user