OPEN - issue BATCH-777: Parametrise RetryCallback and related interfaces
RetryCallback and RecoveryCallback done
This commit is contained in:
@@ -122,14 +122,14 @@ public class BatchMessageListenerContainerIntegrationTests {
|
||||
container.setMessageListener(new MessageListener() {
|
||||
public void onMessage(final Message msg) {
|
||||
try {
|
||||
RetryCallback callback = new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
RetryCallback<Message> callback = new RetryCallback<Message>() {
|
||||
public Message doWithRetry(RetryContext context) throws Exception {
|
||||
count++;
|
||||
throw new RuntimeException("planned failure: " + msg);
|
||||
}
|
||||
};
|
||||
RecoveryCallback recoveryCallback = new RecoveryCallback() {
|
||||
public Object recover(RetryContext context) {
|
||||
RecoveryCallback<Message> recoveryCallback = new RecoveryCallback<Message>() {
|
||||
public Message recover(RetryContext context) {
|
||||
recovered++;
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -82,13 +82,13 @@ public class ExternalRetryInBatchTests {
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
provider = new ItemReaderRecoverer() {
|
||||
public Object read() {
|
||||
public String read() {
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public Object recover(Object data, Throwable cause) {
|
||||
public String recover(String data, Throwable cause) {
|
||||
recovered.add(data);
|
||||
return data;
|
||||
}
|
||||
@@ -131,14 +131,14 @@ public class ExternalRetryInBatchTests {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
|
||||
final Object item = provider.read();
|
||||
final String item = provider.read();
|
||||
|
||||
if (item==null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
RetryCallback callback = new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
RetryCallback<String> callback = new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext context) throws Exception {
|
||||
// No need for transaction here: the whole batch will roll
|
||||
// back. When it comes back for recovery this code is not
|
||||
// executed...
|
||||
@@ -149,8 +149,8 @@ public class ExternalRetryInBatchTests {
|
||||
}
|
||||
};
|
||||
|
||||
RecoveryCallback recoveryCallback = new RecoveryCallback() {
|
||||
public Object recover(RetryContext context) {
|
||||
RecoveryCallback<String> recoveryCallback = new RecoveryCallback<String>() {
|
||||
public String recover(RetryContext context) {
|
||||
// aggressive commit on a recovery
|
||||
RepeatSynchronizationManager.setCompleteOnly();
|
||||
return provider.recover(item, context.getLastThrowable());
|
||||
@@ -212,7 +212,7 @@ public class ExternalRetryInBatchTests {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
private interface ItemReaderRecoverer extends ItemReader<Object>, ItemRecoverer {
|
||||
private interface ItemReaderRecoverer extends ItemReader<String>, ItemRecoverer<String,String> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ExternalRetryTests {
|
||||
return text;
|
||||
}
|
||||
|
||||
public Object recover(Object data, Throwable cause) {
|
||||
public String recover(String data, Throwable cause) {
|
||||
recovered.add(data);
|
||||
return data;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class ExternalRetryTests {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
try {
|
||||
final Object item = provider.read();
|
||||
RetryCallback callback = new RetryCallback() {
|
||||
RetryCallback<Object> callback = new RetryCallback<Object>() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
writer.write(Collections.singletonList(item));
|
||||
return null;
|
||||
@@ -153,8 +153,8 @@ public class ExternalRetryTests {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
try {
|
||||
final Object item = provider.read();
|
||||
RetryCallback callback = new RetryCallback() {
|
||||
final String item = provider.read();
|
||||
RetryCallback<Object> callback = new RetryCallback<Object>() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
writer.write(Collections.singletonList(item));
|
||||
return null;
|
||||
@@ -186,25 +186,25 @@ public class ExternalRetryTests {
|
||||
|
||||
assertInitialState();
|
||||
|
||||
final Object item = provider.read();
|
||||
final RetryCallback callback = new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
final String item = provider.read();
|
||||
final RetryCallback<String> callback = new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext context) throws Exception {
|
||||
simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), item);
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
};
|
||||
|
||||
final RecoveryCallback recoveryCallback = new RecoveryCallback() {
|
||||
public Object recover(RetryContext context) {
|
||||
final RecoveryCallback<String> recoveryCallback = new RecoveryCallback<String>() {
|
||||
public String recover(RetryContext context) {
|
||||
return provider.recover(item, context.getLastThrowable());
|
||||
}
|
||||
};
|
||||
|
||||
Object result = "start";
|
||||
String result = "start";
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
try {
|
||||
result = new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
result = (String) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
try {
|
||||
return retryTemplate.execute(callback, recoveryCallback, new RetryState(item));
|
||||
@@ -254,7 +254,7 @@ public class ExternalRetryTests {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
private interface ItemReaderRecoverer<T> extends ItemReader<T>, ItemRecoverer {
|
||||
private interface ItemReaderRecoverer<T> extends ItemReader<T>, ItemRecoverer<T,T> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -124,12 +124,12 @@ public class SynchronousTests {
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertNotNull(text);
|
||||
|
||||
retryTemplate.execute(new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext status) throws Exception {
|
||||
retryTemplate.execute(new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext status) throws Exception {
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_NESTED);
|
||||
return transactionTemplate.execute(new TransactionCallback() {
|
||||
return (String) transactionTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
list.add(text);
|
||||
@@ -146,7 +146,7 @@ public class SynchronousTests {
|
||||
}
|
||||
});
|
||||
|
||||
// Verify the state after stransactional processing is complete
|
||||
// Verify the state after transactional processing is complete
|
||||
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
@@ -174,12 +174,12 @@ public class SynchronousTests {
|
||||
|
||||
final Object item = provider.read();
|
||||
|
||||
retryTemplate.execute(new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
retryTemplate.execute(new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext context) throws Exception {
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_NESTED);
|
||||
return transactionTemplate.execute(new TransactionCallback() {
|
||||
return (String) transactionTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
list.add(item);
|
||||
@@ -235,12 +235,12 @@ public class SynchronousTests {
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
|
||||
try {
|
||||
retryTemplate.execute(new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext status) throws Exception {
|
||||
retryTemplate.execute(new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext status) throws Exception {
|
||||
|
||||
TransactionTemplate nestedTxTemplate = new TransactionTemplate(transactionManager);
|
||||
nestedTxTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_NESTED);
|
||||
return nestedTxTemplate.execute(new TransactionCallback() {
|
||||
return (String) nestedTxTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus nestedStatus) {
|
||||
|
||||
list.add(text);
|
||||
@@ -290,13 +290,13 @@ public class SynchronousTests {
|
||||
|
||||
assertInitialState();
|
||||
|
||||
retryTemplate.execute(new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext status) throws Exception {
|
||||
retryTemplate.execute(new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext status) throws Exception {
|
||||
|
||||
// use REQUIRES_NEW so that the retry executes in its own transaction
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
|
||||
return transactionTemplate.execute(new TransactionCallback() {
|
||||
return (String) transactionTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
// The receive is inside the retry and the
|
||||
@@ -338,16 +338,16 @@ public class SynchronousTests {
|
||||
|
||||
try {
|
||||
|
||||
retryTemplate.execute(new RetryCallback() {
|
||||
public Object doWithRetry(RetryContext status) throws Exception {
|
||||
retryTemplate.execute(new RetryCallback<String>() {
|
||||
public String doWithRetry(RetryContext status) throws Exception {
|
||||
|
||||
// use REQUIRES_NEW so that the retry executes in its own transaction
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
|
||||
return transactionTemplate.execute(new TransactionCallback() {
|
||||
return (String) transactionTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
// The receieve is inside the retry and the
|
||||
// The receive is inside the retry and the
|
||||
// transaction...
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
@@ -372,7 +372,7 @@ public class SynchronousTests {
|
||||
// expected
|
||||
}
|
||||
|
||||
// Verify the state after stransactional processing is complete
|
||||
// Verify the state after transactional processing is complete
|
||||
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user