[BATCH-383] Fixes to make Spring Batch 1.4 runtime compliant.

This commit is contained in:
nebhale
2008-03-11 13:49:17 +00:00
parent 32e25b081c
commit 9f7cc87c0d
40 changed files with 500 additions and 564 deletions

View File

@@ -30,7 +30,7 @@ public class DatasourceTests extends AbstractTransactionalDataSourceSpringContex
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
assertEquals(0, count);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] { Integer.valueOf(0),
"foo" });
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] { new Integer(0),
"foo" });
}
}

View File

@@ -58,19 +58,19 @@ public abstract class AbstractStaxEventReaderItemReaderTests extends TestCase {
Trade trade1 = (Trade) results.get(0);
assertEquals("XYZ0001", trade1.getIsin());
assertEquals(5, trade1.getQuantity());
assertEquals(BigDecimal.valueOf(11.39), trade1.getPrice());
assertEquals(new BigDecimal("11.39"), trade1.getPrice());
assertEquals("Customer1", trade1.getCustomer());
Trade trade2 = (Trade) results.get(1);
assertEquals("XYZ0002", trade2.getIsin());
assertEquals(2, trade2.getQuantity());
assertEquals(BigDecimal.valueOf(72.99), trade2.getPrice());
assertEquals(new BigDecimal("72.99"), trade2.getPrice());
assertEquals("Customer2", trade2.getCustomer());
Trade trade3 = (Trade) results.get(2);
assertEquals("XYZ0003", trade3.getIsin());
assertEquals(9, trade3.getQuantity());
assertEquals(BigDecimal.valueOf(99.99), trade3.getPrice());
assertEquals(new BigDecimal("99.99"), trade3.getPrice());
assertEquals("Customer3", trade3.getCustomer());
}

View File

@@ -19,6 +19,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.oxm.Marshaller;
import org.springframework.util.ClassUtils;
public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase {
@@ -30,12 +31,13 @@ public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase {
protected Resource expected = new ClassPathResource("expected-output.xml", getClass());
protected List objects = new ArrayList() {{
add(new Trade("isin1", 1, new BigDecimal(1.0), "customer1"));
add(new Trade("isin2", 2, new BigDecimal(2.0), "customer2"));
add(new Trade("isin3", 3, new BigDecimal(3.0), "customer3"));
}};
protected List objects = new ArrayList() {
{
add(new Trade("isin1", 1, new BigDecimal(1.0), "customer1"));
add(new Trade("isin2", 2, new BigDecimal(2.0), "customer2"));
add(new Trade("isin3", 3, new BigDecimal(3.0), "customer3"));
}
};
/**
* Write list of domain objects and check the output file.
@@ -50,16 +52,15 @@ public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase {
}
protected void setUp() throws Exception {
//File outputFile = File.createTempFile("AbstractStaxStreamWriterOutputSourceTests", "xml");
outputFile = File.createTempFile(this.getClass().getSimpleName(), ".xml");
// File outputFile = File.createTempFile("AbstractStaxStreamWriterOutputSourceTests", "xml");
outputFile = File.createTempFile(ClassUtils.getShortName(this.getClass()), ".xml");
resource = new FileSystemResource(outputFile);
writer.setResource(resource);
MarshallingEventWriterSerializer mapper = new MarshallingEventWriterSerializer(getMarshaller());
writer.setSerializer(mapper);
writer.open(new ExecutionContext());
}

View File

@@ -121,7 +121,7 @@ public class ExternalRetryInBatchTests extends AbstractDependencyInjectionSpring
// back. When it comes back for recovery this code is not
// executed...
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
throw new RuntimeException("Rollback!");
}
});
@@ -145,24 +145,20 @@ public class ExternalRetryInBatchTests extends AbstractDependencyInjectionSpring
});
return null;
}
catch (Exception e) {
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
}
catch (Exception e) {
} catch (Exception e) {
if (i == 0 || i == 2) {
assertEquals("Rollback!", e.getMessage());
}
else {
} else {
throw e;
}
}
finally {
} finally {
System.err.println(i + ": " + recovered);
}
}

View File

@@ -95,7 +95,7 @@ public class AsynchronousTests extends AbstractDependencyInjectionSpringContextT
list.add(message.toString());
String text = ((TextMessage) message).getText();
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
}
});

View File

@@ -85,7 +85,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
return new ExitStatus(text != null);
}
});
@@ -116,7 +116,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
return new ExitStatus(text != null);
}
});
@@ -146,7 +146,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
// The JmsTemplate is used elsewhere outside a transaction, so
// we need to use one here that is transaction aware.
final JmsTemplate jmsTemplate = new JmsTemplate((ConnectionFactory) applicationContext
.getBean("txAwareConnectionFactory"));
.getBean("txAwareConnectionFactory"));
jmsTemplate.setReceiveTimeout(100L);
jmsTemplate.setSessionTransacted(true);
@@ -156,7 +156,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
return new ExitStatus(text != null);
}
});
@@ -170,11 +170,9 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
try {
assertTrue("Not a SessionProxy - wrong spring version?", session instanceof SessionProxy);
((SessionProxy) session).getTargetSession().rollback();
}
catch (JMSException e) {
} catch (JMSException e) {
throw e;
}
catch (Exception e) {
} catch (Exception e) {
// swallow it
e.printStackTrace();
}

View File

@@ -94,8 +94,7 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
private List recovered = new ArrayList();
/**
* Message processing is successful on the second attempt but must receive
* the message again.
* Message processing is successful on the second attempt but must receive the message again.
*
* @throws Exception
*/
@@ -108,7 +107,7 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
final ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(final Object text) {
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -121,15 +120,13 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
public Object doInTransaction(TransactionStatus status) {
try {
return retryTemplate.execute(callback);
}
catch (Exception e) {
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
fail("Expected Exception");
}
catch (Exception e) {
} catch (Exception e) {
assertEquals("Rollback!", e.getMessage());
@@ -142,8 +139,7 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
public Object doInTransaction(TransactionStatus status) {
try {
return retryTemplate.execute(callback);
}
catch (Exception e) {
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
@@ -173,7 +169,7 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
final ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new AbstractItemWriter() {
public void write(final Object text) {
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
throw new RuntimeException("Rollback!");
}
});
@@ -186,14 +182,12 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
public Object doInTransaction(TransactionStatus status) {
try {
return retryTemplate.execute(callback);
}
catch (Exception e) {
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
}
catch (Exception e) {
} catch (Exception e) {
if (i < 3)
assertEquals("Rollback!", e.getMessage());
@@ -231,9 +225,9 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
}
return msgs;
}
private abstract class ItemReaderRecoverer extends AbstractItemReader implements ItemRecoverer {
}
}
}

View File

@@ -73,8 +73,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
List list = new ArrayList();
/**
* Message processing is successful on the second attempt without having to
* receive the message again.
* Message processing is successful on the second attempt without having to receive the message again.
*
* @throws Exception
*/
@@ -83,11 +82,9 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
assertInitialState();
/*
* We either want the JMS receive to be outside a transaction, or we
* need the database transaction in the retry to be PROPAGATION_NESTED.
* Otherwise JMS will roll back when the retry callback is eventually
* successful because of the previous exception.
* PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* We either want the JMS receive to be outside a transaction, or we need the database transaction in the retry
* to be PROPAGATION_NESTED. Otherwise JMS will roll back when the retry callback is eventually successful
* because of the previous exception. PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* transaction to fail and rollback the inner one.
*/
final String text = (String) jmsTemplate.receiveAndConvert("queue");
@@ -104,7 +101,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -133,8 +130,8 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt without having to
* receive the message again - uses JmsItemProvider internally.
* Message processing is successful on the second attempt without having to receive the message again - uses
* JmsItemProvider internally.
*
* @throws Exception
*/
@@ -158,7 +155,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -188,8 +185,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt without having to
* receive the message again.
* Message processing is successful on the second attempt without having to receive the message again.
*
* @throws Exception
*/
@@ -198,11 +194,9 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
assertInitialState();
/*
* We either want the JMS receive to be outside a transaction, or we
* need the database transaction in the retry to be PROPAGATION_NESTED.
* Otherwise JMS will roll back when the retry callback is eventually
* successful because of the previous exception.
* PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* We either want the JMS receive to be outside a transaction, or we need the database transaction in the retry
* to be PROPAGATION_NESTED. Otherwise JMS will roll back when the retry callback is eventually successful
* because of the previous exception. PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* transaction to fail and rollback the inner one.
*/
final String text = (String) jmsTemplate.receiveAndConvert("queue");
@@ -218,7 +212,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
return text;
}
@@ -247,8 +241,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt but must receive
* the message again.
* Message processing is successful on the second attempt but must receive the message again.
*
* @throws Exception
*/
@@ -273,7 +266,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
final String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -325,7 +318,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
final String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)",
new Object[] { Integer.valueOf(list.size()), text });
new Object[] { new Integer(list.size()), text });
throw new RuntimeException("Rollback!");
}
@@ -335,13 +328,12 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
});
/*
* N.B. the message can be re-directed to an error queue by setting
* an error destination in a JmsItemProvider.
* N.B. the message can be re-directed to an error queue by setting an error destination in a
* JmsItemProvider.
*/
fail("Expected RuntimeException");
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
assertEquals("Rollback!", e.getMessage());
// expected
}

View File

@@ -70,8 +70,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
List list = new ArrayList();
/**
* Message processing is successful on the second attempt without having to
* receive the message again.
* Message processing is successful on the second attempt without having to receive the message again.
*
* @throws Exception
*/
@@ -80,11 +79,9 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
assertInitialState();
/*
* We either want the JMS receive to be outside a transaction, or we
* need the database transaction in the retry to be PROPAGATION_NESTED.
* Otherwise JMS will roll back when the retry callback is eventually
* successful because of the previous exception.
* PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* We either want the JMS receive to be outside a transaction, or we need the database transaction in the retry
* to be PROPAGATION_NESTED. Otherwise JMS will roll back when the retry callback is eventually successful
* because of the previous exception. PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* transaction to fail and rollback the inner one.
*/
final String text = (String) jmsTemplate.receiveAndConvert("queue");
@@ -100,7 +97,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -129,8 +126,8 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt without having to
* receive the message again - uses JmsItemProvider internally.
* Message processing is successful on the second attempt without having to receive the message again - uses
* JmsItemProvider internally.
*
* @throws Exception
*/
@@ -154,7 +151,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -184,8 +181,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt without having to
* receive the message again.
* Message processing is successful on the second attempt without having to receive the message again.
*
* @throws Exception
*/
@@ -194,11 +190,9 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
assertInitialState();
/*
* We either want the JMS receive to be outside a transaction, or we
* need the database transaction in the retry to be PROPAGATION_NESTED.
* Otherwise JMS will roll back when the retry callback is eventually
* successful because of the previous exception.
* PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* We either want the JMS receive to be outside a transaction, or we need the database transaction in the retry
* to be PROPAGATION_NESTED. Otherwise JMS will roll back when the retry callback is eventually successful
* because of the previous exception. PROPAGATION_REQUIRES_NEW is wrong because it doesn't allow the outer
* transaction to fail and rollback the inner one.
*/
final String text = (String) jmsTemplate.receiveAndConvert("queue");
@@ -214,7 +208,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
list.add(text);
System.err.println("Inserting: [" + list.size() + "," + text + "]");
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
return text;
}
@@ -243,8 +237,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
}
/**
* Message processing is successful on the second attempt but must receive
* the message again.
* Message processing is successful on the second attempt but must receive the message again.
*
* @throws Exception
*/
@@ -269,7 +262,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
final String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
Integer.valueOf(list.size()), text });
new Integer(list.size()), text });
if (list.size() == 1) {
throw new RuntimeException("Rollback!");
}
@@ -321,7 +314,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
final String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)",
new Object[] { Integer.valueOf(list.size()), text });
new Object[] { new Integer(list.size()), text });
throw new RuntimeException("Rollback!");
}
@@ -332,8 +325,7 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
fail("Expected RuntimeException");
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
assertEquals("Rollback!", e.getMessage());
// expected
}