OPEN - issue BATCH-789: Remove mark/reset from ItemReader
Removed all code from mark() and reset() implementations
This commit is contained in:
@@ -49,51 +49,6 @@ public abstract class CommonItemReaderTests {
|
||||
assertNull(tested.read());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback scenario - reader resets to last marked point. Note the commit
|
||||
* interval can change dynamically.
|
||||
*/
|
||||
@Test
|
||||
public void testReset() throws Exception {
|
||||
Foo foo1 = tested.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
tested.mark();
|
||||
|
||||
Foo foo2 = tested.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
Foo foo3 = tested.read();
|
||||
assertEquals(3, foo3.getValue());
|
||||
|
||||
tested.reset();
|
||||
|
||||
assertEquals(foo2, tested.read());
|
||||
|
||||
tested.mark();
|
||||
|
||||
assertEquals(foo3, tested.read());
|
||||
|
||||
tested.reset();
|
||||
|
||||
assertEquals(foo3, tested.read());
|
||||
|
||||
Foo foo4 = tested.read();
|
||||
assertEquals(4, foo4.getValue());
|
||||
|
||||
tested.mark();
|
||||
|
||||
Foo foo5 = tested.read();
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
tested.reset();
|
||||
|
||||
assertEquals(foo5, tested.read());
|
||||
|
||||
assertNull(tested.read());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty input should be handled gracefully - null is returned on first
|
||||
* read.
|
||||
|
||||
@@ -77,14 +77,10 @@ public abstract class CommonItemStreamItemReaderTests extends CommonItemReaderTe
|
||||
Foo foo2 = tested.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
tested.mark();
|
||||
testedAsStream().update(executionContext);
|
||||
|
||||
Foo foo3 = tested.read();
|
||||
assertEquals(3, foo3.getValue());
|
||||
|
||||
tested.reset();
|
||||
|
||||
testedAsStream().update(executionContext);
|
||||
|
||||
// create new input source
|
||||
tested = getItemReader();
|
||||
|
||||
@@ -149,28 +149,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
assertEquals(1, foo.getValue());
|
||||
}
|
||||
|
||||
/*
|
||||
* Rollback scenario - input source rollbacks to last commit point.
|
||||
*/
|
||||
@Transactional @Test
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo1 = reader.read();
|
||||
|
||||
commit();
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
|
||||
Foo foo3 = reader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
assertEquals(foo2, reader.read());
|
||||
}
|
||||
|
||||
/*
|
||||
* Rollback scenario with restart - input source rollbacks to last
|
||||
* commit point.
|
||||
@@ -182,7 +160,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
Foo foo1 = reader.read();
|
||||
|
||||
commit();
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
@@ -190,10 +168,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
Foo foo3 = reader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
// create new input source
|
||||
reader = createItemReader();
|
||||
|
||||
@@ -220,10 +194,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
Foo foo3 = reader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
// create new input source
|
||||
reader = createItemReader();
|
||||
|
||||
@@ -238,9 +208,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
|
||||
Foo foo1 = reader.read();
|
||||
|
||||
commit();
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
@@ -248,10 +219,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
Foo foo3 = reader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
// create new input source
|
||||
reader = createItemReader();
|
||||
|
||||
@@ -262,8 +229,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
commit();
|
||||
|
||||
// create new input source
|
||||
reader = createItemReader();
|
||||
|
||||
@@ -275,14 +240,6 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
assertEquals(5, foo5.getValue());
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
reader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
reader.reset();
|
||||
}
|
||||
|
||||
private ItemStream getAsItemStream(ItemReader<Foo> source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
@@ -144,36 +144,6 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
assertEquals(1, foo.getValue());
|
||||
}
|
||||
|
||||
/*
|
||||
* Rollback scenario.
|
||||
*/
|
||||
@Transactional @Test
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
Foo foo1 = itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
Foo foo2 = itemReader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
|
||||
Foo foo3 = itemReader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
assertEquals(foo2, itemReader.read());
|
||||
}
|
||||
|
||||
|
||||
private void commit() {
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
private ItemStream getAsItemStream(ItemReader<Foo> source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
@@ -135,28 +134,6 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
assertEquals(1, foo.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback scenario.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(itemReader).open(new ExecutionContext());
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
Foo foo2 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo1));
|
||||
|
||||
Foo foo3 = (Foo) itemReader.read();
|
||||
Assert.state(!foo2.equals(foo3));
|
||||
|
||||
rollback();
|
||||
|
||||
assertEquals(foo2, itemReader.read());
|
||||
}
|
||||
|
||||
public void testRetriveZeroKeys() {
|
||||
|
||||
itemReader.setKeyCollector(new KeyCollector<Foo>() {
|
||||
@@ -176,14 +153,6 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
itemReader.reset();
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader<Foo> source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
@@ -7,8 +9,6 @@ import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
class FooItemReader implements ItemStream, ItemReader<Foo>, DisposableBean, InitializingBean {
|
||||
|
||||
DrivingQueryItemReader<?> itemReader;
|
||||
@@ -62,7 +62,6 @@ class FooItemReader implements ItemStream, ItemReader<Foo>, DisposableBean, Init
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
*/
|
||||
public void mark() {
|
||||
itemReader.mark();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -70,6 +69,5 @@ class FooItemReader implements ItemStream, ItemReader<Foo>, DisposableBean, Init
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
*/
|
||||
public void reset() {
|
||||
itemReader.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.CommonItemStreamItemReaderTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.CommonItemStreamItemReaderTests;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JpaPagingItemReaderCommonTests extends CommonItemStreamItemReaderTests {
|
||||
@@ -41,34 +40,4 @@ public class JpaPagingItemReaderCommonTests extends CommonItemStreamItemReaderTe
|
||||
reader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
super.testRestart();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetAndRestart() throws Exception {
|
||||
super.testResetAndRestart();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReopen() throws Exception {
|
||||
super.testReopen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
super.testRead();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset() throws Exception {
|
||||
super.testReset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyInput() throws Exception {
|
||||
super.testEmptyInput();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.batch.item.file;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -80,58 +78,6 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
|
||||
return new ByteArrayResource(input.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test rollback functionality
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void testReset() throws Exception {
|
||||
|
||||
reader.close(null);
|
||||
reader.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
|
||||
reader.open(executionContext);
|
||||
|
||||
// read some records
|
||||
reader.read(); // #1
|
||||
reader.read(); // #2
|
||||
// commit them
|
||||
reader.mark();
|
||||
// read next record
|
||||
reader.read(); // # 3
|
||||
// read next records
|
||||
reader.reset();
|
||||
|
||||
// we should now process all records after first commit point
|
||||
assertEquals("[testLine3]", reader.read().toString());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test skip and skipRollback functionality
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void testFailOnFirstChunk() throws Exception {
|
||||
|
||||
reader.close(null);
|
||||
reader.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
|
||||
reader.open(executionContext);
|
||||
|
||||
// read some records
|
||||
reader.read(); // #1
|
||||
reader.read(); // #2
|
||||
reader.read(); // #3
|
||||
// rollback
|
||||
reader.reset();
|
||||
// read next record
|
||||
reader.read(); // should be #1
|
||||
|
||||
// we should now process all records after first commit point, that are
|
||||
// not marked as skipped
|
||||
assertEquals("[testLine2]", reader.read().toString());
|
||||
|
||||
}
|
||||
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
reader.close(null);
|
||||
@@ -141,9 +87,6 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
|
||||
// read some records
|
||||
reader.read();
|
||||
reader.read();
|
||||
// commit them
|
||||
reader.mark();
|
||||
// read next two records
|
||||
reader.read();
|
||||
reader.read();
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
|
||||
tested.setComparator(new Comparator<Resource>() {
|
||||
public int compare(Resource o1, Resource o2) {
|
||||
return 0; // do not change ordering
|
||||
}});
|
||||
}
|
||||
});
|
||||
tested.setResources(new Resource[] { r1, r2, r3, r4, r5 });
|
||||
}
|
||||
|
||||
@@ -67,40 +68,67 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
|
||||
tested.close(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read items with a couple of rollbacks, requiring to jump back to items
|
||||
* from previous resources.
|
||||
*/
|
||||
public void testReset() throws Exception {
|
||||
public void testRestartWhenStateNotSaved() throws Exception {
|
||||
|
||||
tested.setSaveState(false);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("1", readItem());
|
||||
|
||||
tested.mark();
|
||||
tested.update(ctx);
|
||||
|
||||
assertEquals("2", readItem());
|
||||
assertEquals("3", readItem());
|
||||
|
||||
tested.reset();
|
||||
tested.close(ctx);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("1", readItem());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Read items with a couple of rollbacks, requiring to jump back to items
|
||||
* from previous resources.
|
||||
*/
|
||||
public void testRestartAcrossResourceBoundary() throws Exception {
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("1", readItem());
|
||||
|
||||
tested.update(ctx);
|
||||
|
||||
assertEquals("2", readItem());
|
||||
assertEquals("3", readItem());
|
||||
|
||||
tested.close(ctx);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("2", readItem());
|
||||
assertEquals("3", readItem());
|
||||
assertEquals("4", readItem());
|
||||
|
||||
tested.reset();
|
||||
tested.close(ctx);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("2", readItem());
|
||||
assertEquals("3", readItem());
|
||||
assertEquals("4", readItem());
|
||||
assertEquals("5", readItem());
|
||||
|
||||
tested.mark();
|
||||
tested.update(ctx);
|
||||
|
||||
assertEquals("6", readItem());
|
||||
assertEquals("7", readItem());
|
||||
|
||||
tested.reset();
|
||||
tested.close(ctx);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("6", readItem());
|
||||
assertEquals("7", readItem());
|
||||
@@ -116,9 +144,6 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
itemReader.setSaveState(true);
|
||||
tested.setSaveState(true);
|
||||
|
||||
tested.open(ctx);
|
||||
|
||||
assertEquals("1", readItem());
|
||||
@@ -146,14 +171,13 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
|
||||
* Resources are ordered according to injected comparator.
|
||||
*/
|
||||
public void testResourceOrderingWithCustomComparator() {
|
||||
|
||||
|
||||
Resource r1 = new ByteArrayResource("".getBytes(), "b");
|
||||
Resource r2 = new ByteArrayResource("".getBytes(), "a");
|
||||
Resource r3 = new ByteArrayResource("".getBytes(), "c");
|
||||
|
||||
|
||||
Resource[] resources = new Resource[] {r1, r2, r3};
|
||||
|
||||
|
||||
Resource[] resources = new Resource[] { r1, r2, r3 };
|
||||
|
||||
Comparator<Resource> comp = new Comparator<Resource>() {
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,10 +107,11 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
* Save restart data and restore from it.
|
||||
*/
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
source.open(executionContext);
|
||||
source.read();
|
||||
source.update(executionContext);
|
||||
System.out.println(executionContext);
|
||||
|
||||
assertEquals(1, executionContext.getLong(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count"));
|
||||
List<XMLEvent> expectedAfterRestart = source.read();
|
||||
|
||||
@@ -118,48 +119,14 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
source.open(executionContext);
|
||||
List<XMLEvent> afterRestart = source.read();
|
||||
assertEquals(expectedAfterRestart.size(), afterRestart.size());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Restore point must not exceed end of file, input source must not be
|
||||
// already initialised when restoring.
|
||||
// */
|
||||
// public void testInvalidRestore() {
|
||||
// ExecutionContext context = new ExecutionContext();
|
||||
// context.putLong(ClassUtils.getShortName(StaxEventItemReader.class) +
|
||||
// ".item.count", 100000);
|
||||
// try {
|
||||
// source.open(context);
|
||||
// fail("Expected StreamException");
|
||||
// } catch (Exception e) {
|
||||
// // expected
|
||||
// String message = e.getMessage();
|
||||
// assertTrue("Wrong message: " + message, contains(message,
|
||||
// "must be before"));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void testRestoreWorksFromClosedStream() throws Exception {
|
||||
source.close(executionContext);
|
||||
source.update(executionContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback to last commited record.
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
source.open(executionContext);
|
||||
// rollback between deserializing records
|
||||
List<XMLEvent> first = source.read();
|
||||
source.mark();
|
||||
List<XMLEvent> second = source.read();
|
||||
assertFalse(first.equals(second));
|
||||
source.reset();
|
||||
|
||||
assertEquals(second, source.read());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics return the current record count. Calling read after end of
|
||||
* input does not increase the counter.
|
||||
|
||||
Reference in New Issue
Block a user