BATCH-1654: fix StepExecution equals and hashcode

This commit is contained in:
Dave Syer
2010-11-18 12:08:48 +00:00
parent 01f91f166b
commit b4cdc4ab9f
2 changed files with 19 additions and 5 deletions

View File

@@ -477,7 +477,8 @@ public class StepExecution extends Entity {
}
StepExecution other = (StepExecution) obj;
return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId()));
return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId()))
&& getId().equals(other.getId());
}
/**
@@ -496,8 +497,9 @@ public class StepExecution extends Entity {
*/
public int hashCode() {
Object jobExecutionId = getJobExecutionId();
Long id = getId();
return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0);
}
public String toString() {

View File

@@ -188,6 +188,14 @@ public class StepExecutionTests {
assertEquals("bar", execution.getExecutionContext().getString("foo"));
}
@Test
public void testEqualsWithSameName() throws Exception {
Step step = new StepSupport("stepName");
Entity stepExecution1 = newStepExecution(step,11L,4L);
Entity stepExecution2 = newStepExecution(step,11L,5L);
assertFalse(stepExecution1.equals(stepExecution2));
}
@Test
public void testEqualsWithSameIdentifier() throws Exception {
Step step = new StepSupport("stepName");
@@ -291,9 +299,13 @@ public class StepExecutionTests {
assertEquals(BatchStatus.FAILED, execution.getStatus());
}
private StepExecution newStepExecution(Step step, Long long2) {
JobInstance job = new JobInstance(new Long(3), new JobParameters(), "testJob");
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, long2), new Long(4));
private StepExecution newStepExecution(Step step, Long jobExecutionId) {
return newStepExecution(step, jobExecutionId, 4);
}
private StepExecution newStepExecution(Step step, Long jobExecutionId, long stepExecutionId) {
JobInstance job = new JobInstance(3L, new JobParameters(), "testJob");
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId), stepExecutionId);
return execution;
}