RESOLVED - issue BATCH-517: item writers need to handle empty flush gracefully
http://jira.springframework.org/browse/BATCH-517 BatchSqlUpdateItemWriter no longer asserts there are items bound to transaction
This commit is contained in:
@@ -47,7 +47,7 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
protected List list = new ArrayList();
|
||||
|
||||
|
||||
private RepeatContext context = new RepeatContextSupport(null);
|
||||
|
||||
private PreparedStatement ps;
|
||||
@@ -149,7 +149,7 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.database.BatchSqlUpdateItemWriter#flush()}.
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteAndFlush() throws Exception {
|
||||
assertTrue(TransactionSynchronizationManager.hasResource(BatchSqlUpdateItemWriter.ITEMS_PROCESSED));
|
||||
@@ -159,16 +159,6 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
assertEquals(3, list.size());
|
||||
assertTrue(list.contains("SQL"));
|
||||
}
|
||||
|
||||
public void testFlushWithFailure() throws Exception{
|
||||
tearDown();
|
||||
try {
|
||||
writer.flush();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
assertTrue("Message should contain hint about transaction: "+e.getMessage(), e.getMessage().indexOf("transaction")>=0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testWriteAndFlushWithFailure() throws Exception {
|
||||
final RuntimeException ex = new RuntimeException("bar");
|
||||
@@ -180,13 +170,14 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
});
|
||||
ps.addBatch();
|
||||
control.setVoidCallable();
|
||||
control.expectAndReturn(ps.executeBatch(), new int[] {123});
|
||||
control.expectAndReturn(ps.executeBatch(), new int[] { 123 });
|
||||
control.replay();
|
||||
writer.write("foo");
|
||||
try {
|
||||
writer.flush();
|
||||
fail("Expected RuntimeException");
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("bar", e.getMessage());
|
||||
}
|
||||
assertFalse(TransactionSynchronizationManager.hasResource(BatchSqlUpdateItemWriter.ITEMS_PROCESSED));
|
||||
@@ -205,4 +196,13 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
|
||||
assertTrue(context.isCompleteOnly());
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushing without writing items previously should be handled gracefully.
|
||||
*/
|
||||
public void testEmptyFlush() {
|
||||
// items are bound on write, so we unbind them first
|
||||
TransactionSynchronizationManager.unbindResource(BatchSqlUpdateItemWriter.ITEMS_PROCESSED);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user