OPEN - issue BATCH-87: Recoverable is a nasty abstraction - encourages stateful Tasklets.
http://opensource.atlassian.com/projects/spring/browse/BATCH-87 Remove recover method from AbstractItemProvider.
This commit is contained in:
@@ -18,21 +18,18 @@ package org.springframework.batch.item;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
|
||||
public class ItemRecoveryHandlerTests extends TestCase {
|
||||
|
||||
ItemRecoverer recoverer = new AbstractItemProvider() {
|
||||
public Object next() {
|
||||
return "foo";
|
||||
ItemRecoverer recoverer = new ItemRecoverer() {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public void testRecover() throws Exception {
|
||||
try {
|
||||
recoverer.recover("foo", null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
fail("Unexpected Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.retry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
|
||||
public class ListItemProviderRecoverer extends ListItemProvider implements ItemProvider, ItemRecoverer {
|
||||
|
||||
/**
|
||||
* Delegate to super class constructor.
|
||||
* @param list
|
||||
*/
|
||||
public ListItemProviderRecoverer(List list) {
|
||||
super(list);
|
||||
}
|
||||
/**
|
||||
* Do nothing. Subclassses should override to implement recovery behaviour.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProvider#recover(java.lang.Object,
|
||||
* Throwable)
|
||||
*
|
||||
* @return false if nothing can be done (the default), or true if the item
|
||||
* can now safely be ignored or committed.
|
||||
*/
|
||||
public boolean recover(Object item, Throwable cause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.exception.RetryException;
|
||||
@@ -46,13 +47,12 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
template = new RetryTemplate();
|
||||
provider = new ListItemProvider(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
calls.add(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object getKey(Object item) {
|
||||
return "key" + (count++);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
@@ -50,7 +51,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
super.setUp();
|
||||
// The list simulates a failed delivery, redelivery of the same message,
|
||||
// then a new message...
|
||||
provider = new ListItemProvider(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
list.add(data);
|
||||
|
||||
Reference in New Issue
Block a user