RESOLVED - issue BATCH-467: Remove ExitStatusExceptionClassifier / Rewrite SimpleExitStatusExceptionClassifier as a JobListener
Removed the interface and implementation, checked that defautl behaviour is same using unit test ItemOrientedStepTests
This commit is contained in:
@@ -26,7 +26,6 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.step.ExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -126,8 +125,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
StepExecution execution = new StepExecution(step2, jobExecution, null);
|
||||
execution.setStatus(BatchStatus.STARTED);
|
||||
execution.setStartTime(new Date(System.currentTimeMillis()));
|
||||
execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
|
||||
"java.lang.Exception"));
|
||||
execution.setExitStatus(ExitStatus.FAILED.addExitDescription("java.lang.Exception"));
|
||||
stepExecutionDao.saveStepExecution(execution);
|
||||
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
|
||||
assertNotNull(retrievedExecution);
|
||||
@@ -140,8 +138,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
execution.setStatus(BatchStatus.STARTED);
|
||||
execution.setStartTime(new Date(System.currentTimeMillis()));
|
||||
execution.setExecutionContext(executionContext);
|
||||
execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
|
||||
"java.lang.Exception"));
|
||||
execution.setExitStatus(ExitStatus.FAILED.addExitDescription("java.lang.Exception"));
|
||||
stepExecutionDao.saveStepExecution(execution);
|
||||
stepExecutionDao.saveOrUpdateExecutionContext(execution);
|
||||
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
|
||||
@@ -159,8 +156,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
stepExecution.setCommitCount(5);
|
||||
stepExecution.setItemCount(5);
|
||||
stepExecution.setExecutionContext(new ExecutionContext());
|
||||
stepExecution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
|
||||
"java.lang.Exception"));
|
||||
stepExecution.setExitStatus(ExitStatus.FAILED.addExitDescription("java.lang.Exception"));
|
||||
stepExecutionDao.updateStepExecution(stepExecution);
|
||||
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step1);
|
||||
assertNotNull(retrievedExecution);
|
||||
|
||||
@@ -1,88 +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.core.step;
|
||||
|
||||
|
||||
import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.launch.support.ExitCodeMapper;
|
||||
import org.springframework.batch.core.repository.NoSuchJobException;
|
||||
import org.springframework.batch.core.step.ExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.core.step.SimpleExitStatusExceptionClassifier;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class SimpleExitStatusExceptionClassifierTests extends TestCase {
|
||||
|
||||
NullPointerException exception;
|
||||
|
||||
SimpleExitStatusExceptionClassifier classifier = new SimpleExitStatusExceptionClassifier();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
exception = new NullPointerException();
|
||||
}
|
||||
|
||||
public void testClassifyForExitCode() {
|
||||
ExitStatus exitStatus = classifier.classifyForExitCode(exception);
|
||||
assertEquals(exitStatus.getExitCode(), "FATAL_EXCEPTION");
|
||||
String description = exitStatus.getExitDescription();
|
||||
assertTrue("Description does not contain NullPointerException: "+description, description.indexOf("java.lang.NullPointerException")>=0);
|
||||
}
|
||||
|
||||
public void testClassify() {
|
||||
ExitStatus exitStatus = (ExitStatus)classifier.classify(exception);
|
||||
assertEquals(exitStatus.getExitCode(), "FATAL_EXCEPTION");
|
||||
String description = exitStatus.getExitDescription();
|
||||
assertTrue("Description does not contain NullPointerException: "+description, description.indexOf("java.lang.NullPointerException")>=0);
|
||||
}
|
||||
|
||||
public void testGetDefault() {
|
||||
ExitStatus exitStatus = (ExitStatus)classifier.getDefault();
|
||||
assertEquals(exitStatus.getExitCode(), "FATAL_EXCEPTION");
|
||||
assertEquals(exitStatus.getExitDescription(), "");
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempting to classify a null throwable should lead to a blank description, not a
|
||||
* null pointer exception.
|
||||
*/
|
||||
public void testClassifyNullThrowable(){
|
||||
ExitStatus exitStatus = (ExitStatus)classifier.classify(null);
|
||||
assertEquals(exitStatus.getExitCode(), "FATAL_EXCEPTION");
|
||||
assertEquals(exitStatus.getExitDescription(), "");
|
||||
}
|
||||
|
||||
public void testClassifyInterruptedException(){
|
||||
ExitStatus exitStatus = (ExitStatus)classifier.classifyForExitCode(new JobInterruptedException(""));
|
||||
assertEquals(exitStatus.getExitCode(), ExitStatusExceptionClassifier.JOB_INTERRUPTED);
|
||||
assertEquals(exitStatus.getExitDescription(),
|
||||
JobInterruptedException.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* a NoSuchJobException should lead to the related constant
|
||||
*/
|
||||
public void testClassifyNoSuchJobException() {
|
||||
ExitStatus exitStatus = (ExitStatus)classifier.classifyForExitCode(new NoSuchJobException(""));
|
||||
assertEquals(exitStatus.getExitCode(), ExitCodeMapper.NO_SUCH_JOB);
|
||||
assertEquals(exitStatus.getExitDescription(), "");
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.UnexpectedJobExecutionException;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobInterruptedException;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.UnexpectedJobExecutionException;
|
||||
import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.listener.StepListenerSupport;
|
||||
import org.springframework.batch.core.repository.dao.MapJobExecutionDao;
|
||||
@@ -40,18 +40,16 @@ import org.springframework.batch.core.repository.support.SimpleJobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.batch.core.step.StepInterruptionPolicy;
|
||||
import org.springframework.batch.core.step.item.ItemOrientedStep;
|
||||
import org.springframework.batch.core.step.item.SimpleItemHandler;
|
||||
import org.springframework.batch.item.AbstractItemReader;
|
||||
import org.springframework.batch.item.AbstractItemWriter;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemStreamSupport;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.MarkFailedException;
|
||||
import org.springframework.batch.item.ResetFailedException;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
@@ -215,6 +213,42 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testExitCodeCustomClassification() throws Exception {
|
||||
|
||||
ItemReader itemReader = new AbstractItemReader() {
|
||||
|
||||
public Object read() throws Exception {
|
||||
int counter = 0;
|
||||
counter++;
|
||||
|
||||
if (counter == 1) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
|
||||
itemOrientedStep.registerStepListener(new StepListenerSupport() {
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return ExitStatus.FAILED.addExitDescription("FOO");
|
||||
}
|
||||
});
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
try {
|
||||
itemOrientedStep.execute(stepExecution);
|
||||
} catch (Exception ex) {
|
||||
ExitStatus status = stepExecution.getExitStatus();
|
||||
assertFalse(status.isContinuable());
|
||||
String description = status.getExitDescription();
|
||||
assertTrue("Description does not include 'FOO': "+description, description.indexOf("FOO")>=0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* make sure a job that has never been executed before, but does have saveExecutionAttributes = true, doesn't have
|
||||
* restoreFrom called on it.
|
||||
@@ -586,7 +620,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
|
||||
try {
|
||||
itemOrientedStep.execute(stepExecution);
|
||||
fail("Expected BatchCriticalException");
|
||||
fail("Expected UnexpectedJobExecutionException");
|
||||
} catch (UnexpectedJobExecutionException ex) {
|
||||
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
|
||||
Reference in New Issue
Block a user