RESOLVED - BATCH-29: All domain entities and scoping abstractions (RepeatContext in particular) need to be Serializable
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
@@ -24,7 +25,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
* @author Lucas Ward
|
||||
* @since 1.0
|
||||
*/
|
||||
public class JobParameters {
|
||||
public class JobParameters implements Serializable {
|
||||
|
||||
private final Map stringMap;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
@@ -153,4 +154,10 @@ public class JobExecutionTests extends TestCase {
|
||||
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);
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
|
||||
assertEquals(execution, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,38 +15,51 @@
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author dsyer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobInstanceTests extends TestCase {
|
||||
|
||||
private JobInstance instance = new JobInstance(new Long(11), new JobParameters(), "job");
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
*/
|
||||
public void testGetName() {
|
||||
instance = new JobInstance(new Long(1), new JobParameters(), "foo");
|
||||
assertEquals("foo", instance.getJobName());
|
||||
}
|
||||
|
||||
public void testGetJob(){
|
||||
|
||||
public void testGetJob() {
|
||||
assertEquals("job", instance.getJobName());
|
||||
}
|
||||
|
||||
public void testCreateWithNulls(){
|
||||
public void testCreateWithNulls() {
|
||||
try {
|
||||
new JobInstance(null, null, null);
|
||||
fail("job instance can't exist without job specified");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
// expected
|
||||
}
|
||||
instance = new JobInstance(null, null, "testJob");
|
||||
assertEquals("testJob", instance.getJobName());
|
||||
assertEquals(0, instance.getJobParameters().getParameters().size());
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
instance = new JobInstance(new Long(1), new JobParametersBuilder().addDouble("doubleKey", Double.valueOf(5.1))
|
||||
.toJobParameters(), "jobName");
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(instance);
|
||||
|
||||
assertEquals(instance, SerializationUtils.deserialize(serialized));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -245,4 +247,12 @@ public class JobParametersTests extends TestCase {
|
||||
int code = getNewParameters().hashCode();
|
||||
assertEquals(code, parameters.hashCode());
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
JobParameters params = getNewParameters();
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(params);
|
||||
|
||||
assertEquals(params, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -221,6 +222,19 @@ public class StepExecutionTests extends TestCase {
|
||||
execution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
assertTrue(set.contains(execution));
|
||||
}
|
||||
|
||||
public void testSerialization() throws Exception {
|
||||
|
||||
ExitStatus status = ExitStatus.NOOP;
|
||||
execution.setExitStatus(status);
|
||||
execution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
StepExecution deserialized = (StepExecution) SerializationUtils.deserialize(serialized);
|
||||
|
||||
assertEquals(execution, deserialized);
|
||||
assertEquals(status, deserialized.getExitStatus());
|
||||
}
|
||||
|
||||
private StepExecution newStepExecution(Step step, Long long2) {
|
||||
JobInstance job = new JobInstance(new Long(3), new JobParameters(), "testJob");
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.Assert;
|
||||
* @author Lucas Ward
|
||||
* @author Douglas Kaminsky
|
||||
*/
|
||||
public class ExecutionContext {
|
||||
public class ExecutionContext implements Serializable {
|
||||
|
||||
private boolean dirty = false;
|
||||
|
||||
|
||||
@@ -15,8 +15,14 @@
|
||||
*/
|
||||
package org.springframework.batch.item;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
@@ -103,4 +109,42 @@ public class ExecutionContextTests extends TestCase{
|
||||
context.put("1", null);
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
|
||||
TestSerializable s = new TestSerializable();
|
||||
s.value = 7;
|
||||
|
||||
context.putString("1", "testString1");
|
||||
context.putString("2", "testString2");
|
||||
context.putLong("3", 3);
|
||||
context.putDouble("4", 4.4);
|
||||
context.put("5", s);
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(context);
|
||||
|
||||
ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized);
|
||||
|
||||
assertEquals(context, deserialized);
|
||||
assertEquals(7, ((TestSerializable)deserialized.get("5")).value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Value object for testing serialization
|
||||
*/
|
||||
private static class TestSerializable implements Serializable {
|
||||
|
||||
int value;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user