IN PROGRESS - issue BATCH-366: Do we still need StepInstance?

http://jira.springframework.org/browse/BATCH-366

Killed StepInstance - test coverage temporarily low due to commenting obsolete tests (but sample jobs work fine).
This commit is contained in:
robokaso
2008-02-19 15:41:26 +00:00
parent d7b9cf9d92
commit 96c48bcbc5
54 changed files with 665 additions and 1321 deletions

View File

@@ -143,8 +143,8 @@ public class JobExecution extends Entity {
*
* @param stepExecution
*/
public StepExecution createStepExecution(StepInstance stepInstance) {
StepExecution stepExecution = new StepExecution(stepInstance, this, null);
public StepExecution createStepExecution(String stepName) {
StepExecution stepExecution = new StepExecution(stepName, this, null);
this.stepExecutions.add(stepExecution);
return stepExecution;
}

View File

@@ -31,7 +31,7 @@ import java.util.List;
*/
public class JobInstance extends Entity {
private List stepInstances = new ArrayList();
private List stepNames = new ArrayList();
private JobParameters jobParameters;
@@ -59,16 +59,16 @@ public class JobInstance extends Entity {
return lastExecution;
}
public List getStepInstances() {
return stepInstances;
public List getStepNames() {
return stepNames;
}
public void setStepInstances(List stepInstances) {
this.stepInstances = stepInstances;
public void setStepNames(List stepInstances) {
this.stepNames = stepInstances;
}
public void addStepInstance(StepInstance stepInstance) {
this.stepInstances.add(stepInstance);
public void addStepName(String stepName) {
this.stepNames.add(stepName);
}
public int getJobExecutionCount() {

View File

@@ -36,8 +36,8 @@ import org.springframework.batch.repeat.ExitStatus;
public class StepExecution extends Entity {
private JobExecution jobExecution;
private StepInstance step;
private String stepName;
private BatchStatus status = BatchStatus.STARTING;
@@ -75,9 +75,9 @@ public class StepExecution extends Entity {
* @param jobExecution the current job execution
* @param id the id of this execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution, Long id) {
public StepExecution(String stepName, JobExecution jobExecution, Long id) {
super(id);
this.step = step;
this.stepName = stepName;
this.jobExecution = jobExecution;
}
@@ -87,8 +87,8 @@ public class StepExecution extends Entity {
* @param step the step to which this execution belongs
* @param jobExecution the current job execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution) {
this(step, jobExecution, null);
public StepExecution(String stepName, JobExecution jobExecution) {
this(stepName, jobExecution, null);
}
/**
@@ -232,15 +232,10 @@ public class StepExecution extends Entity {
}
/**
* Returns the id for this step
*
* @return the id for this step
* @return the name of the step
*/
public Long getStepId() {
if (step != null) {
return step.getId();
}
return null;
public String getStepName() {
return stepName;
}
/**
@@ -261,16 +256,16 @@ public class StepExecution extends Entity {
* @see org.springframework.batch.container.common.domain.Entity#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
Object stepId = getStepId();
//TODO make sure the equality makes sense
Object jobExecutionId = getJobExecutionId();
if (stepId == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
if (stepName == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
return super.equals(obj);
}
StepExecution other = (StepExecution) obj;
if (stepId == null) {
if (stepName == null) {
return jobExecutionId.equals(other.getJobExecutionId());
}
return stepId.equals(other.getStepId())
return stepName.equals(other.getStepName())
&& (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId()));
}
@@ -280,21 +275,16 @@ public class StepExecution extends Entity {
* @see org.springframework.batch.container.common.domain.Entity#hashCode()
*/
public int hashCode() {
Object stepId = getStepId();
Object jobExecutionId = getJobExecutionId();
return super.hashCode() + 31 * (stepId != null ? stepId.hashCode() : 0) + 91
return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
}
public String toString() {
return super.toString() + ", name=" + getName() + ", taskCount=" + taskCount + ", commitCount=" + commitCount
return super.toString() + ", name=" + stepName + ", taskCount=" + taskCount + ", commitCount=" + commitCount
+ ", rollbackCount=" + rollbackCount;
}
private String getName() {
return step == null ? null : step.getName();
}
/**
* @param exitStatus
*/
@@ -309,15 +299,6 @@ public class StepExecution extends Entity {
return exitStatus;
}
/**
* Accessor for the step governing this execution.
*
* @return the step
*/
public StepInstance getStep() {
return step;
}
/**
* Accessor for the execution context information of the enclosing job.
*

View File

@@ -1,108 +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.domain;
/**
* <p>
* Batch domain entity representing a step which is sequentially executed by a
* job. Logically, steps are identified as a function of a job plus each step's
* name. For example, job 'TestJob' which has 2 steps: "TestStep1" and
* "TestStep2". The first step can be thought of as identified by
* "TestJob.TestStep1". In relational terms this may be represented by a foreign
* key on the Job's ID. Therefore, Each step instance is uniquely identified by
* it's ID, which is obtained from a JobRepository. Two steps with the same name
* and same job can be considered the same step.
* </p>
*
* <p>
* Because each step represents a runnable batch artifact with it's own
* lifecycle, each step contains status and an execution count. Status
* represents the status of each step's last execution (such as started,
* completed, failed, etc) and execution count is the count of executions for
* this individual step. It should be noted that a restartable job will create a
* new step instance (the same logical step, with a different ID) for every run.
* </p>
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class StepInstance extends Entity {
private JobInstance jobInstance;
private StepExecution lastExecution;
private int stepExecutionCount = 0;
private String name;
/**
* Package private constructor for Hibernate only
*/
StepInstance() {
this(null);
}
public StepInstance(Long stepId) {
this(null, null, stepId);
}
public StepInstance(JobInstance job, String name) {
this(job, name, null);
}
public StepInstance(JobInstance job, String name, Long stepId) {
setId(stepId);
this.jobInstance = job;
this.name = name;
}
public int getStepExecutionCount() {
return stepExecutionCount;
}
public void setStepExecutionCount(int stepExecutionCount) {
this.stepExecutionCount = stepExecutionCount;
}
public JobInstance getJobInstance() {
return jobInstance;
}
public String getName() {
return name;
}
public Long getJobId() {
return jobInstance==null ? null : jobInstance.getId();
}
public void setLastExecution(StepExecution lastExecution) {
this.lastExecution = lastExecution;
}
public StepExecution getLastExecution() {
return lastExecution;
}
// @Override
public String toString() {
return super.toString() + ", name=" + name + " in " + jobInstance;
}
}

View File

@@ -92,4 +92,15 @@ public interface JobRepository {
*/
public void saveOrUpdate(StepExecution stepExecution);
/**
* @return the last execution of step for the given job instance.
*/
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName);
/**
* @return the execution count of the step within the given job instance.
*/
public int getStepExecutionCount(JobInstance jobInstance, String stepName);
}

View File

@@ -130,7 +130,7 @@ public class JobExecutionTests extends TestCase {
public void testAddAndRemoveStepExecution() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
execution.createStepExecution(new StepInstance(null, null));
execution.createStepExecution(null);
assertEquals(1, execution.getStepExecutions().size());
}

View File

@@ -35,20 +35,20 @@ public class JobInstanceTests extends TestCase {
}
/**
* Test method for {@link org.springframework.batch.core.domain.JobInstance#getStepInstances()}.
* Test method for {@link org.springframework.batch.core.domain.JobInstance#getStepNames()}.
*/
public void testGetSteps() {
assertEquals(0, instance.getStepInstances().size());
instance.setStepInstances(Collections.singletonList(new StepInstance()));
assertEquals(1, instance.getStepInstances().size());
assertEquals(0, instance.getStepNames().size());
instance.setStepNames(Collections.singletonList(""));
assertEquals(1, instance.getStepNames().size());
}
/**
* Test method for {@link org.springframework.batch.core.domain.JobInstance#addStepInstance(org.springframework.batch.core.domain.StepInstance)}.
* Test method for {@link org.springframework.batch.core.domain.JobInstance#addStepName(org.springframework.batch.core.domain.StepInstance)}.
*/
public void testAddStep() {
instance.addStepInstance(new StepInstance());
assertEquals(1, instance.getStepInstances().size());
instance.addStepName("");
assertEquals(1, instance.getStepNames().size());
}
/**

View File

@@ -61,7 +61,7 @@ public class JobSupportTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.core.domain.JobSupport#setSteps(java.util.List)}.
* {@link org.springframework.batch.core.domain.JobSupport#setStepNames(java.util.List)}.
*/
public void testSetSteps() {
job.setSteps(Collections.singletonList(new StepSupport("step")));
@@ -70,7 +70,7 @@ public class JobSupportTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.core.domain.JobSupport#addStepInstance(org.springframework.batch.core.configuration.StepConfiguration)}.
* {@link org.springframework.batch.core.domain.JobSupport#addStepName(org.springframework.batch.core.configuration.StepConfiguration)}.
*/
public void testAddStep() {
job.addStep(new StepSupport("step"));

View File

@@ -31,7 +31,7 @@ import org.springframework.batch.support.PropertiesConverter;
*/
public class StepExecutionTests extends TestCase {
private StepExecution execution = newStepExecution(new Long(11),
private StepExecution execution = newStepExecution("stepName",
new Long(23));
/**
@@ -157,18 +157,6 @@ public class StepExecutionTests extends TestCase {
execution.setRollbackCount(123);
assertEquals(123, execution.getRollbackCount().intValue());
}
/**
* Test method for
* {@link org.springframework.batch.core.domain.StepExecution#getStepId()}.
*/
public void testGetStepId() {
assertEquals(11, execution.getStepId().longValue());
}
public void testGetStep() throws Exception {
assertNotNull(execution.getStep());
}
public void testGetJobExecution() throws Exception {
assertNotNull(execution.getJobExecution());
@@ -210,18 +198,18 @@ public class StepExecutionTests extends TestCase {
}
public void testEqualsWithSameIdentifier() throws Exception {
Entity step1 = newStepExecution(new Long(100), new Long(11));
Entity step2 = newStepExecution(new Long(100), new Long(11));
Entity step1 = newStepExecution("stepName", new Long(11));
Entity step2 = newStepExecution("stepName", new Long(11));
assertEquals(step1, step2);
}
public void testEqualsWithNull() throws Exception {
Entity step = newStepExecution(new Long(100), new Long(11));
Entity step = newStepExecution("stepName", new Long(11));
assertFalse(step.equals(null));
}
public void testEqualsWithNullIdentifiers() throws Exception {
Entity step = newStepExecution(new Long(100), new Long(11));
Entity step = newStepExecution("stepName", new Long(11));
assertFalse(step.equals(new StepExecution()));
}
@@ -231,7 +219,7 @@ public class StepExecutionTests extends TestCase {
}
public void testEqualsWithNullStep() throws Exception {
Entity step = newStepExecution(new Long(11), null);
Entity step = newStepExecution("stepName", null);
assertFalse(step.equals(new StepExecution()));
}
@@ -240,13 +228,13 @@ public class StepExecutionTests extends TestCase {
}
public void testEqualsWithDifferent() throws Exception {
Entity step = newStepExecution(new Long(43), new Long(13));
Entity step = newStepExecution("foo", new Long(13));
assertFalse(execution.equals(step));
}
public void testEqualsWithNullStepId() throws Exception {
execution = newStepExecution(null, new Long(31));
assertEquals(null, execution.getStepId());
assertEquals(null, execution.getStepName());
StepExecution step = newStepExecution(null, new Long(31));
assertEquals(step.getJobExecutionId(), execution.getJobExecutionId());
assertTrue(execution.equals(step));
@@ -271,10 +259,9 @@ public class StepExecutionTests extends TestCase {
assertTrue(set.contains(execution));
}
private StepExecution newStepExecution(Long long1, Long long2) {
private StepExecution newStepExecution(String stepName, Long long2) {
JobInstance job = new JobInstance(new Long(3), new JobParameters());
StepInstance step = new StepInstance(job, "foo", long1);
StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4));
StepExecution execution = new StepExecution(stepName, new JobExecution(job, long2), new Long(4));
return execution;
}

View File

@@ -1,98 +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.domain;
import junit.framework.TestCase;
/**
* @author Dave Syer
*
*/
public class StepInstanceTests extends TestCase {
StepInstance instance = new StepInstance(new Long(13));
/**
* Test method for {@link org.springframework.batch.core.domain.StepInstance#StepInstance()}.
*/
public void testStepInstance() {
assertNull(new StepInstance().getId());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepInstance#getStepExecutionCount()}.
*/
public void testGetStepExecutionCount() {
assertEquals(0, instance.getStepExecutionCount());
instance.setStepExecutionCount(23);
assertEquals(23, instance.getStepExecutionCount());
}
public void testLastExecution(){
StepExecution lastExecution = new StepExecution();
assertNull(instance.getLastExecution());
instance.setLastExecution(lastExecution);
assertEquals(lastExecution, instance.getLastExecution());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepInstance#getJobInstance()}.
*/
public void testGetJobInstance() {
assertEquals(null, instance.getJobInstance());
JobInstance jobInstance = new JobInstance(new Long(1), new JobParameters());
instance = new StepInstance(jobInstance, null);
assertEquals(jobInstance, instance.getJobInstance());
}
public void testGetJob(){
Job job = new JobSupport("job");
JobInstance jobInstance = new JobInstance(new Long(2), new JobParameters(), job);
instance = new StepInstance(jobInstance, null);
assertEquals(job, instance.getJobInstance().getJob());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepInstance#getName()}.
*/
public void testGetName() {
assertEquals(null, instance.getName());
instance = new StepInstance(null, "foo");
assertEquals("foo", instance.getName());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepInstance#getJobId()}.
*/
public void testGetJobId() {
assertEquals(null, instance.getJobId());
instance = new StepInstance(new JobInstance(new Long(23), new JobParameters()), null);
assertEquals(23, instance.getJobId().longValue());
}
public void testEqualsWithSameIdentifier() throws Exception {
JobInstance job = new JobInstance(new Long(100), new JobParameters());
StepInstance step1 = new StepInstance(job, "foo", new Long(0));
StepInstance step2 = new StepInstance(job, "foo", new Long(0));
assertEquals(step1, step2);
}
public void testToString() throws Exception {
assertTrue("Should contain name", instance.toString().indexOf("name=")>=0);
}
}