From 7dd1a4eea393d4ced73abe6f6385e6c0390c7876 Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 29 Mar 2010 11:06:44 +0000 Subject: [PATCH] Add read from start to integration test --- .../JdbcPagingRestartIntegrationTests.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java index 94a3c4a32..9f547b3be 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java @@ -81,16 +81,38 @@ public class JdbcPagingRestartIntegrationTests { jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); } + @Test + public void testReaderFromStart() throws Exception { + + ItemReader reader = getItemReader(); + + int total = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"); + + ExecutionContext executionContext = new ExecutionContext(); + ((ItemStream) reader).open(executionContext); + + for (int i = 0; i < total; i++) { + Foo item = reader.read(); + logger.debug("Item: " + item); + assertNotNull(item); + } + + Foo item = reader.read(); + logger.debug("Item: " + item); + assertNull(item); + + } @Test - public void testReader() throws Exception { + public void testReaderOnRestart() throws Exception { ItemReader reader = getItemReader(); int total = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"); int count = (total / pageSize) * pageSize; - if (count >= pageSize) { - count -= pageSize; + int pagesToRead = Math.min(3, total/pageSize); + if (count >= pagesToRead*pageSize) { + count -= pagesToRead*pageSize; } ExecutionContext executionContext = new ExecutionContext();