IN PROGRESS - issue BATCH-412: consistent ItemStream key prefixes

http://jira.springframework.org/browse/BATCH-412

added ExecutionContextUserSupport class as superclass for those who need to save data into ExecutionContext - removes the tons of copy-pastes used to handle naming and unique key generation
This commit is contained in:
robokaso
2008-03-05 10:28:48 +00:00
parent fcb5da0831
commit 2aa867c535
15 changed files with 199 additions and 128 deletions

View File

@@ -161,7 +161,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
// get restart data
reader.update(executionContext);
assertEquals(4, executionContext.getLong(
FlatFileItemReader.class.getName() + "." + FlatFileItemReader.READ_STATISTICS_NAME));
FlatFileItemReader.class.getSimpleName() + "." + FlatFileItemReader.READ_STATISTICS_NAME));
// close input
reader.close(executionContext);
@@ -175,7 +175,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
assertEquals("[testLine6]", reader.read().toString());
reader.update(executionContext);
assertEquals(6, executionContext.getLong(FlatFileItemReader.class.getName() + "." + FlatFileItemReader.READ_STATISTICS_NAME));
assertEquals(6, executionContext.getLong(FlatFileItemReader.class.getSimpleName() + "." + FlatFileItemReader.READ_STATISTICS_NAME));
}
}

View File

@@ -245,7 +245,7 @@ public class FlatFileItemWriterTests extends TestCase {
}
// 3 lines were written to the file after restart
assertEquals(3, executionContext.getLong(FlatFileItemWriter.class.getName() + "." + FlatFileItemWriter.WRITTEN_STATISTICS_NAME));
assertEquals(3, executionContext.getLong(FlatFileItemWriter.class.getSimpleName() + "." + FlatFileItemWriter.WRITTEN_STATISTICS_NAME));
}
@@ -269,7 +269,7 @@ public class FlatFileItemWriterTests extends TestCase {
inputSource.update(executionContext);
assertNotNull(executionContext);
assertEquals(3, executionContext.entrySet().size());
assertEquals(0, executionContext.getLong(FlatFileItemWriter.class.getName() + "." + FlatFileItemWriter.RESTART_DATA_NAME));
assertEquals(0, executionContext.getLong(FlatFileItemWriter.class.getSimpleName() + "." + FlatFileItemWriter.RESTART_DATA_NAME));
}
private void commit() throws Exception {

View File

@@ -119,7 +119,7 @@ public class StaxEventItemReaderTests extends TestCase {
source.read();
source.update(executionContext);
System.out.println(executionContext);
assertEquals(1, executionContext.getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME));
assertEquals(1, executionContext.getLong(StaxEventItemReader.class.getSimpleName() + "." + StaxEventItemReader.READ_COUNT_STATISTICS_NAME));
List expectedAfterRestart = (List) source.read();
source = createNewInputSouce();
@@ -134,7 +134,7 @@ public class StaxEventItemReaderTests extends TestCase {
*/
public void testInvalidRestore() {
ExecutionContext context = new ExecutionContext();
context.putLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME, 100000);
context.putLong(StaxEventItemReader.class.getSimpleName() + "." + StaxEventItemReader.READ_COUNT_STATISTICS_NAME, 100000);
try {
source.open(context);
fail("Expected StreamException");
@@ -214,7 +214,7 @@ public class StaxEventItemReaderTests extends TestCase {
}
private long extractRecordCount() {
return executionContext.getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
return executionContext.getLong(StaxEventItemReader.class.getSimpleName() + "." + StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
}
public void testCloseWithoutOpen() throws Exception {

View File

@@ -125,7 +125,7 @@ public class StaxEventItemWriterTests extends TestCase {
for (int i = 1; i <= NUMBER_OF_RECORDS; i++) {
writer.write(record);
writer.update(executionContext);
long writeStatistics = executionContext.getLong(StaxEventItemWriter.class.getName() + "." + StaxEventItemWriter.WRITE_STATISTICS_NAME);
long writeStatistics = executionContext.getLong(StaxEventItemWriter.class.getSimpleName() + "." + StaxEventItemWriter.WRITE_STATISTICS_NAME);
assertEquals(i, writeStatistics);
}

View File

@@ -0,0 +1,34 @@
package org.springframework.batch.item;
import junit.framework.TestCase;
/**
* Tests for {@link ExecutionContextUserSupport}.
*/
public class ExecutionContextUserSupportTests extends TestCase {
ExecutionContextUserSupport tested = new ExecutionContextUserSupport();
/**
* Regular usage scenario - prepends the name (supposed to be unique) to
* argument.
*/
public void testGetKey() {
tested.setName("uniqueName");
assertEquals("uniqueName.key", tested.getKey("key"));
}
/**
* Exception scenario - name must not be empty.
*/
public void testGetKeyWithNoNameSet() {
tested.setName("");
try {
tested.getKey("arbitrary string");
fail();
}
catch (IllegalArgumentException e) {
// expected
}
}
}