IN PROGRESS - issue BATCH-894: RFC: move ExitStatus up into Core?
Replaced infrastrucure status with local enum and moved ExitStatus into core. TODO: maybe get rid of continuable.
This commit is contained in:
@@ -1,255 +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.repeat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ExitStatusTests {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusBooleanInt() {
|
||||
ExitStatus status = new ExitStatus(true, "10");
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("10", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsContinuable() {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE;
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("CONTINUABLE", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testExitStatusConstantsFinished() {
|
||||
ExitStatus status = ExitStatus.FINISHED;
|
||||
assertFalse(status.isContinuable());
|
||||
assertEquals("COMPLETED", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test equality of exit statuses.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsWithSameProperties() throws Exception {
|
||||
assertEquals(ExitStatus.CONTINUABLE, new ExitStatus(true, "CONTINUABLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsSelf() {
|
||||
ExitStatus status = new ExitStatus(true, "test");
|
||||
assertEquals(status, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertEquals(new ExitStatus(true, "test"), new ExitStatus(true, "test"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test equality of exit statuses.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsWithNull() throws Exception {
|
||||
assertFalse(ExitStatus.CONTINUABLE.equals(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test equality of exit statuses.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testHashcode() throws Exception {
|
||||
assertEquals(ExitStatus.CONTINUABLE.toString().hashCode(), ExitStatus.CONTINUABLE.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(boolean)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAndBoolean() {
|
||||
assertTrue(ExitStatus.CONTINUABLE.and(true).isContinuable());
|
||||
assertFalse(ExitStatus.CONTINUABLE.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.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusStillContinuable() {
|
||||
assertTrue(ExitStatus.CONTINUABLE.and(ExitStatus.CONTINUABLE).isContinuable());
|
||||
assertFalse(ExitStatus.CONTINUABLE.and(ExitStatus.FINISHED).isContinuable());
|
||||
assertTrue(ExitStatus.CONTINUABLE.and(ExitStatus.CONTINUABLE).getExitCode().equals(
|
||||
ExitStatus.CONTINUABLE.getExitCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenFinishedAddedToContinuable() {
|
||||
assertEquals(ExitStatus.FINISHED.getExitCode(), ExitStatus.CONTINUABLE.and(ExitStatus.FINISHED).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenContinuableAddedToFinished() {
|
||||
assertEquals(ExitStatus.FINISHED.getExitCode(), ExitStatus.FINISHED.and(ExitStatus.CONTINUABLE).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomContinuableAddedToContinuable() {
|
||||
assertEquals("CUSTOM", ExitStatus.CONTINUABLE.and(ExitStatus.CONTINUABLE.replaceExitCode("CUSTOM"))
|
||||
.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusFailedPlusFinished() {
|
||||
assertEquals("FAILED", ExitStatus.FINISHED.and(ExitStatus.FAILED).getExitCode());
|
||||
assertEquals("FAILED", ExitStatus.FAILED.and(ExitStatus.FINISHED).getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAndExitStatusWhenCustomContinuableAddedToFinished() {
|
||||
assertEquals(ExitStatus.FINISHED.getExitCode(), ExitStatus.FINISHED.and(
|
||||
ExitStatus.CONTINUABLE.replaceExitCode("CUSTOM")).getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitCode() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.replaceExitCode("FOO");
|
||||
assertTrue(ExitStatus.CONTINUABLE != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitCodeToExistingStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.replaceExitCode("FOO").replaceExitCode("BAR");
|
||||
assertTrue(ExitStatus.CONTINUABLE != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("BAR", status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitCodeToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.replaceExitCode(ExitStatus.CONTINUABLE.getExitCode());
|
||||
assertTrue(ExitStatus.CONTINUABLE != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals(ExitStatus.CONTINUABLE.getExitCode(), status.getExitCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitDescription() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.CONTINUABLE != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitDescriptionToSameStatus() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.addExitDescription("Foo").addExitDescription("Foo");
|
||||
assertTrue(ExitStatus.CONTINUABLE != status);
|
||||
assertTrue(status.isContinuable());
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEmptyExitDescription() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.addExitDescription("Foo").addExitDescription(null);
|
||||
assertEquals("Foo", status.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExitCodeWithDescription() throws Exception {
|
||||
ExitStatus status = new ExitStatus(true, "BAR", "Bar").replaceExitCode("FOO");
|
||||
assertEquals("FOO", status.getExitCode());
|
||||
assertEquals("Bar", status.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnkownIsRunning() throws Exception {
|
||||
assertTrue(ExitStatus.UNKNOWN.isRunning());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializable() throws Exception {
|
||||
ExitStatus status = ExitStatus.CONTINUABLE.replaceExitCode("FOO");
|
||||
byte[] bytes = SerializationUtils.serialize(status);
|
||||
Object object = SerializationUtils.deserialize(bytes);
|
||||
assertTrue(object instanceof ExitStatus);
|
||||
ExitStatus restored = (ExitStatus) object;
|
||||
assertTrue(restored.isContinuable());
|
||||
assertEquals(status.getExitCode(), restored.getExitCode());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.callback;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
@@ -29,12 +29,12 @@ public class NestedRepeatCallbackTests extends TestCase {
|
||||
|
||||
public void testExecute() throws Exception {
|
||||
NestedRepeatCallback callback = new NestedRepeatCallback(new RepeatTemplate(), new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return new ExitStatus(count <= 1);
|
||||
return RepeatStatus.continueIf(count <= 1);
|
||||
}
|
||||
});
|
||||
ExitStatus result = callback.doInIteration(null);
|
||||
RepeatStatus result = callback.doInIteration(null);
|
||||
assertEquals(2, count);
|
||||
assertFalse(result.isContinuable()); // False because processing has finished
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatException;
|
||||
import org.springframework.batch.repeat.RepeatOperations;
|
||||
@@ -68,7 +68,7 @@ public class RepeatOperationsInterceptorTests extends TestCase {
|
||||
public void testSetTemplate() throws Exception {
|
||||
final List<Object> calls = new ArrayList<Object>();
|
||||
interceptor.setRepeatOperations(new RepeatOperations() {
|
||||
public ExitStatus iterate(RepeatCallback callback) {
|
||||
public RepeatStatus iterate(RepeatCallback callback) {
|
||||
try {
|
||||
Object result = callback.doInIteration(null);
|
||||
calls.add(result);
|
||||
@@ -76,7 +76,7 @@ public class RepeatOperationsInterceptorTests extends TestCase {
|
||||
catch (Exception e) {
|
||||
throw new RepeatException("Encountered exception in repeat.", e);
|
||||
}
|
||||
return ExitStatus.CONTINUABLE;
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
});
|
||||
((Advised) service).addAdvice(interceptor);
|
||||
@@ -87,9 +87,9 @@ public class RepeatOperationsInterceptorTests extends TestCase {
|
||||
public void testCallbackNotExecuted() throws Exception {
|
||||
final List<Object> calls = new ArrayList<Object>();
|
||||
interceptor.setRepeatOperations(new RepeatOperations() {
|
||||
public ExitStatus iterate(RepeatCallback callback) {
|
||||
public RepeatStatus iterate(RepeatCallback callback) {
|
||||
calls.add(null);
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
((Advised) service).addAdvice(interceptor);
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatListener;
|
||||
@@ -46,9 +46,9 @@ public class RepeatListenerTests extends TestCase {
|
||||
}
|
||||
} });
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return new ExitStatus(count <= 1);
|
||||
return RepeatStatus.continueIf(count <= 1);
|
||||
}
|
||||
});
|
||||
// 2 calls: the second time there is no processing
|
||||
@@ -69,9 +69,9 @@ public class RepeatListenerTests extends TestCase {
|
||||
}
|
||||
});
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
assertEquals(0, count);
|
||||
@@ -83,18 +83,18 @@ public class RepeatListenerTests extends TestCase {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<Object>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("2");
|
||||
}
|
||||
} });
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return new ExitStatus(count <= 1);
|
||||
return RepeatStatus.continueIf(count <= 1);
|
||||
}
|
||||
});
|
||||
// 2 calls to the callback, and the second one had no processing...
|
||||
@@ -117,9 +117,9 @@ public class RepeatListenerTests extends TestCase {
|
||||
}
|
||||
} });
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return ExitStatus.CONTINUABLE;
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
});
|
||||
assertEquals(0, count);
|
||||
@@ -135,10 +135,10 @@ public class RepeatListenerTests extends TestCase {
|
||||
}
|
||||
});
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
context.setCompleteOnly();
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
assertEquals(1, count);
|
||||
@@ -158,9 +158,9 @@ public class RepeatListenerTests extends TestCase {
|
||||
}
|
||||
} });
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return new ExitStatus(count < 2);
|
||||
return RepeatStatus.continueIf(count < 2);
|
||||
}
|
||||
});
|
||||
// Test that more than one call comes in to the callback...
|
||||
@@ -184,7 +184,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
} });
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
throw new IllegalStateException("Bogus");
|
||||
}
|
||||
});
|
||||
@@ -201,7 +201,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<Object>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
@@ -211,7 +211,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
} });
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
throw new IllegalStateException("Bogus");
|
||||
}
|
||||
});
|
||||
@@ -231,7 +231,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
final List<Object> calls = new ArrayList<Object>();
|
||||
final List<Object> fails = new ArrayList<Object>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
public void after(RepeatContext context, ExitStatus result) {
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
@@ -242,7 +242,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
} });
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
throw new IllegalStateException("Bogus");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.batch.repeat.policy;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
public class CompositeCompletionPolicyTests extends TestCase {
|
||||
@@ -59,7 +59,7 @@ public class CompositeCompletionPolicyTests extends TestCase {
|
||||
CompositeCompletionPolicy policy = new CompositeCompletionPolicy();
|
||||
policy.setPolicies(new CompletionPolicy[] { new MockCompletionPolicySupport(),
|
||||
new MockCompletionPolicySupport() {
|
||||
public boolean isComplete(RepeatContext context, ExitStatus result) {
|
||||
public boolean isComplete(RepeatContext context, RepeatStatus result) {
|
||||
return true;
|
||||
}
|
||||
} });
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CountingCompletionPolicyTests extends TestCase {
|
||||
};
|
||||
policy.setMaxCount(10);
|
||||
RepeatContext context = policy.start(null);
|
||||
assertTrue(policy.isComplete(context, ExitStatus.FINISHED));
|
||||
assertTrue(policy.isComplete(context, RepeatStatus.FINISHED));
|
||||
}
|
||||
|
||||
public void testDefaultBehaviourWithUpdate() throws Exception {
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
public class SimpleCompletionPolicyTests extends TestCase {
|
||||
@@ -27,7 +27,7 @@ public class SimpleCompletionPolicyTests extends TestCase {
|
||||
|
||||
RepeatContext context;
|
||||
|
||||
ExitStatus dummy = ExitStatus.CONTINUABLE;
|
||||
RepeatStatus dummy = RepeatStatus.CONTINUABLE;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.batch.repeat.policy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
public class TimeoutCompletionPolicyTests {
|
||||
@@ -43,7 +44,7 @@ public class TimeoutCompletionPolicyTests {
|
||||
@Test
|
||||
public void testNonContinuableResult() throws Exception {
|
||||
TimeoutTerminationPolicy policy = new TimeoutTerminationPolicy();
|
||||
ExitStatus result = new ExitStatus(false, "non-continuable exit status");
|
||||
RepeatStatus result = RepeatStatus.FINISHED;
|
||||
assertTrue(policy.isComplete(policy.start(null), result));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -42,7 +42,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final Set<String> threadNames = new HashSet<String>();
|
||||
|
||||
final RepeatCallback callback = new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
Thread.sleep(100);
|
||||
@@ -50,7 +50,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
if (item!=null) {
|
||||
processor.write(Collections.singletonList(item));
|
||||
}
|
||||
return new ExitStatus(item!=null);
|
||||
return RepeatStatus.continueIf(item!=null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final Set<String> threadNames = new HashSet<String>();
|
||||
|
||||
final RepeatCallback stepCallback = new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
Thread.sleep(100);
|
||||
@@ -86,9 +86,9 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
}
|
||||
};
|
||||
RepeatCallback jobCallback = new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
stepTemplate.iterate(stepCallback);
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.repeat.support;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
|
||||
@@ -51,9 +51,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
// once
|
||||
chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
|
||||
ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
|
||||
RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++; // for test assertion
|
||||
return super.doInIteration(context);
|
||||
}
|
||||
@@ -86,9 +86,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
chunkTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
|
||||
ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
|
||||
RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++; // for test assertion
|
||||
return super.doInIteration(context);
|
||||
}
|
||||
@@ -158,8 +158,8 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
chunker.reset();
|
||||
template.iterate(new ItemReaderRepeatCallback<Trade>(truncated, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
RepeatStatus result = super.doInIteration(context);
|
||||
if (!result.isContinuable() && chunker.first()) {
|
||||
chunker.set();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Collections;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
@@ -44,13 +44,13 @@ public class ItemReaderRepeatCallback<T> implements RepeatCallback {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.RepeatCallback#doInIteration(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
T item = reader.read();
|
||||
if (item==null) {
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
writer.write(Collections.singletonList(item));
|
||||
return ExitStatus.CONTINUABLE;
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
|
||||
|
||||
public class RepeatSynchronizationManagerTests extends TestCase {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.batch.repeat.support;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatException;
|
||||
@@ -73,7 +73,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
throw new IllegalStateException("foo!");
|
||||
}
|
||||
@@ -109,9 +109,9 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}
|
||||
});
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
return new ExitStatus(count < 1);
|
||||
return RepeatStatus.continueIf(count < 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -143,7 +143,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
throw new RuntimeException("foo");
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
throw new RuntimeException("foo");
|
||||
}
|
||||
@@ -198,10 +198,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContext() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
RepeatStatus result = super.doInIteration(context);
|
||||
if (processor.count >= 2) {
|
||||
context.setCompleteOnly();
|
||||
// If we return null the batch will terminate anyway
|
||||
@@ -226,10 +226,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContextTerminated() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
RepeatStatus result = super.doInIteration(context);
|
||||
if (processor.count >= 2) {
|
||||
context.setTerminateOnly();
|
||||
// If we return null the batch will terminate anyway
|
||||
@@ -251,15 +251,15 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
RepeatTemplate outer = getRepeatTemplate();
|
||||
RepeatTemplate inner = getRepeatTemplate();
|
||||
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
assertNotNull(context);
|
||||
assertNotSame("Nested batch should have new session", context, context.getParent());
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
return super.doInIteration(context);
|
||||
@@ -272,14 +272,14 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
RepeatTemplate outer = getRepeatTemplate();
|
||||
RepeatTemplate inner = getRepeatTemplate();
|
||||
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
assertEquals(2, count);
|
||||
fail("Nested batch should not have been executed");
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
context.setCompleteOnly();
|
||||
return super.doInIteration(context);
|
||||
@@ -293,19 +293,19 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
outer.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
RepeatTemplate inner = getRepeatTemplate();
|
||||
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
assertNotNull(context);
|
||||
assertNotSame("Nested batch should have new session", context, context.getParent());
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
return ExitStatus.FINISHED;
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
super.doInIteration(context);
|
||||
return ExitStatus.CONTINUABLE;
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
});
|
||||
assertEquals(4, count);
|
||||
@@ -316,7 +316,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testResult() throws Exception {
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor));
|
||||
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor));
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
// We are complete - do not expect to be called again
|
||||
assertFalse(result.isContinuable());
|
||||
@@ -326,10 +326,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
if (count < 2) {
|
||||
return ExitStatus.CONTINUABLE;
|
||||
return RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
throw new RuntimeException("Barf second try count=" + count);
|
||||
}
|
||||
@@ -352,13 +352,13 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(4));
|
||||
|
||||
ExitStatus result = ExitStatus.FINISHED;
|
||||
RepeatStatus result = RepeatStatus.FINISHED;
|
||||
|
||||
try {
|
||||
result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
RepeatStatus result = super.doInIteration(context);
|
||||
if (processor.count >= 2) {
|
||||
context.setCompleteOnly();
|
||||
throw new RuntimeException("Barf second try count=" + processor.count);
|
||||
@@ -383,20 +383,6 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
}
|
||||
|
||||
public void testCustomExitCode() {
|
||||
|
||||
ExitStatus status = template.iterate(new RepeatCallback() {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus exitStatus = new ExitStatus(false, "CUSTOM_CODE");
|
||||
return exitStatus;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
assertEquals("CUSTOM_CODE", status.getExitCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checked exceptions are wrapped into runtime RepeatException.
|
||||
* RepeatException should be unwrapped before before it is passed to
|
||||
@@ -438,7 +424,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
try {
|
||||
template.iterate(new RepeatCallback() {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
throw new RepeatException("typically thrown by nested repeat template", exception);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.batch.repeat.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user