diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java index 51b2b442b..38fafbedf 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java @@ -460,9 +460,9 @@ public class JdbcCursorItemReader extends ExecutionContextUserSupport implements public Object read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException { - - if(buffer.size() > currentIndex){ - currentIndex++; + currentIndex++; + // if the incremented index reaches out of the buffer, add next item from result set to buffer + if(buffer.size() == currentIndex){ try{ if(!rs.next()){ return null; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/CommonItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/CommonItemReaderTests.java index a8fd20c1e..abea1b0ef 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/CommonItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/CommonItemReaderTests.java @@ -1,10 +1,9 @@ package org.springframework.batch.item; -import org.springframework.batch.item.sample.Foo; -import org.springframework.util.Assert; - import junit.framework.TestCase; +import org.springframework.batch.item.sample.Foo; + /** * Common tests for {@link ItemReader} implementations. Expected input is five * {@link Foo} objects with values 1 to 5. @@ -50,18 +49,33 @@ public abstract class CommonItemReaderTests extends TestCase { */ public void testReset() throws Exception { Foo foo1 = (Foo) tested.read(); - + assertEquals(1, foo1.getValue()); + tested.mark(); Foo foo2 = (Foo) tested.read(); - Assert.state(!foo2.equals(foo1)); + assertEquals(2, foo2.getValue()); Foo foo3 = (Foo) tested.read(); - Assert.state(!foo2.equals(foo3)); + assertEquals(3, foo3.getValue()); tested.reset(); assertEquals(foo2, tested.read()); + + assertEquals(foo3, tested.read()); + + + Foo foo4 = (Foo) tested.read(); + assertEquals(4, foo4.getValue()); + + tested.mark(); + + Foo foo5 = (Foo) tested.read(); + assertEquals(5, foo5.getValue()); + + assertNull(tested.read()); + } }