RESOLVED - issue BATCH-88: StatisticsProvider is a leaky abstraction
http://jira.springframework.org/browse/BATCH-88
This commit is contained in:
@@ -58,24 +58,6 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics of injected ItemProcessors should be returned under keys prefixed with their list index.
|
||||
*/
|
||||
public void testStatistics() {
|
||||
final ItemProcessor p1 = new ItemProcessorStub();
|
||||
final ItemProcessor p2 = new ItemProcessorStub();
|
||||
|
||||
List itemProcessors = new ArrayList(){{
|
||||
add(p1);
|
||||
add(p2);
|
||||
}};
|
||||
|
||||
itemProcessor.setItemProcessors(itemProcessors);
|
||||
Properties stats = itemProcessor.getStatistics();
|
||||
assertEquals(String.valueOf(p1.hashCode()), stats.getProperty("0#" + ItemProcessorStub.STATS_KEY));
|
||||
assertEquals(String.valueOf(p2.hashCode()), stats.getProperty("1#" + ItemProcessorStub.STATS_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
* All Restartable processors should be restarted, not-Restartable processors should be ignored.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.processor.ItemWriterItemProcessor;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -56,14 +55,6 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
assertEquals("test:foo", list.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets statistics from the input template
|
||||
*/
|
||||
public void testGetStatistics() {
|
||||
Properties props = processor.getStatistics();
|
||||
assertEquals("b", props.getProperty("a"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets restart data from the input template
|
||||
*/
|
||||
@@ -111,15 +102,6 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets statistics from the input template
|
||||
*/
|
||||
public void testGetStatisticsWithoutStatisticsProvider() {
|
||||
processor.setItemWriter(null);
|
||||
Properties props = processor.getStatistics();
|
||||
assertEquals(null, props.getProperty("a"));
|
||||
}
|
||||
|
||||
public void testSkip() {
|
||||
processor.skip();
|
||||
|
||||
@@ -72,14 +72,6 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
assertSame("domain object is provided by the input template", this, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets statistics from the input template
|
||||
*/
|
||||
public void testGetStatistics() {
|
||||
Properties props = itemProvider.getStatistics();
|
||||
assertEquals("b", props.getProperty("a"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets restart data from the input template
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.statistics;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStatisticsServiceTests extends TestCase {
|
||||
|
||||
private SimpleStatisticsService service = new SimpleStatisticsService();
|
||||
|
||||
public void testRegistration() throws Exception {
|
||||
service.register("FOO", new StubStatisticsProvider());
|
||||
assertEquals("bar", service.getStatistics("FOO").getProperty("foo"));
|
||||
}
|
||||
|
||||
public void testAggregation() throws Exception {
|
||||
service.register("FOO", new StubStatisticsProvider());
|
||||
service.register("FOO", new StubStatisticsProvider("spam=bucket"));
|
||||
assertEquals("bar", service.getStatistics("FOO").getProperty("foo"));
|
||||
assertEquals("bucket", service.getStatistics("FOO").getProperty("spam"));
|
||||
}
|
||||
|
||||
public void testDoubleAggregationOrder() throws Exception {
|
||||
StubStatisticsProvider provider = new StubStatisticsProvider();
|
||||
service.register("FOO", provider);
|
||||
service.register("FOO", provider);
|
||||
assertEquals(1, service.getStatistics("FOO").size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private class StubStatisticsProvider implements StatisticsProvider {
|
||||
String values = "foo=bar";
|
||||
|
||||
public StubStatisticsProvider(String values) {
|
||||
super();
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public StubStatisticsProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Properties getStatistics() {
|
||||
return PropertiesConverter.stringToProperties(values);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user