Half-hearted attempt to fix broken integration tests

This commit is contained in:
dsyer
2008-09-02 15:45:11 +00:00
parent b79a496626
commit 40b65bafb2
14 changed files with 233 additions and 192 deletions

View File

@@ -0,0 +1,34 @@
package org.springframework.batch.integration.chunk;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.StringUtils;
public class ChunkProcessorChunkHandlerTests {
private ChunkProcessorChunkHandler<Object> handler = new ChunkProcessorChunkHandler<Object>();
protected int count = 0;
@SuppressWarnings("unchecked")
@Test
public void testVanillaHandleChunk() {
handler.setChunkProcessor(new ChunkProcessor<Object>() {
public int process(Collection<? extends Object> items, int skipCount) throws Exception {
count+=items.size();
return 0;
}
});
ChunkResponse response = handler.handleChunk(new ChunkRequest(StringUtils.commaDelimitedListToSet("foo,bar"),
12L, 10));
assertEquals(0, response.getSkipCount());
assertEquals(new Long(12L), response.getJobId());
assertEquals(ExitStatus.CONTINUABLE, response.getExitStatus());
assertEquals(2, count);
}
}

View File

@@ -1,85 +0,0 @@
package org.springframework.batch.integration.chunk;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.batch.core.SkipListener;
import org.springframework.batch.core.listener.SkipListenerSupport;
import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.StringUtils;
public class ItemWriterChunkHandlerTests {
private ItemWriterChunkHandler<Object> handler = new ItemWriterChunkHandler<Object>();
protected int count = 0;
private SkipListenerSupport listener = new SkipListenerSupport() {
@Override
public void onSkipInWrite(Object item, Throwable t) {
count++;
}
};
@SuppressWarnings("unchecked")
@Test
public void testVanillaHandleChunk() {
handler.setItemWriter(new ItemWriter<Object>() {
public void write(List<? extends Object> items) throws Exception {
count+=items.size();
}
});
ChunkResponse response = handler.handleChunk(new ChunkRequest(StringUtils.commaDelimitedListToSet("foo,bar"),
12L, 10));
assertEquals(0, response.getSkipCount());
assertEquals(new Long(12L), response.getJobId());
assertEquals(ExitStatus.CONTINUABLE, response.getExitStatus());
assertEquals(2, count);
}
@SuppressWarnings("unchecked")
@Test
public void testSetItemSkipPolicy() {
handler.setItemWriter(new ItemWriter<Object>() {
public void write(List<? extends Object> items) throws Exception {
count+=items.size();
throw new RuntimeException("Planned failure");
}
});
handler.setItemSkipPolicy(new AlwaysSkipItemSkipPolicy());
ChunkResponse response = handler.handleChunk(new ChunkRequest(StringUtils.commaDelimitedListToSet("foo,bar"),
12L, 10));
assertEquals(2, response.getSkipCount());
assertEquals(new Long(12L), response.getJobId());
assertEquals(ExitStatus.CONTINUABLE, response.getExitStatus());
assertEquals(2, count);
}
@SuppressWarnings("unchecked")
@Test
public void testRegisterSkipListener() {
handler.setItemWriter(new ItemWriter<Object>() {
public void write(List<? extends Object> items) throws Exception {
count+=items.size();
throw new RuntimeException("Planned failure");
}
});
handler.setItemSkipPolicy(new AlwaysSkipItemSkipPolicy());
handler.registerSkipListener(listener);
ChunkResponse response = handler.handleChunk(new ChunkRequest(StringUtils.commaDelimitedListToSet("foo,bar"),
12L, 10));
assertEquals(2, response.getSkipCount());
assertEquals(4, count);
}
@Test
public void testSetSkipListeners() {
handler.setSkipListeners(new SkipListener[] { listener });
testRegisterSkipListener();
}
}

View File

@@ -10,8 +10,10 @@
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<message-bus auto-create-channels="true" />
<message-bus/>
<annotation-driven />
<direct-channel id="smokein"/>
<channel id="smokeout"/>
<channel id="smokein"/>
<channel id="smokeout">
<queue capacity="UNBOUNDED"/>
</channel>
</beans:beans>

View File

@@ -8,7 +8,7 @@
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<message-bus auto-create-channels="true" />
<message-bus/>
<channel id="jobs" />
</beans:beans>

View File

@@ -11,7 +11,7 @@
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<message-bus auto-create-channels="true" />
<message-bus/>
<annotation-driven />
@@ -22,9 +22,16 @@
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<tx:annotation-driven />
<beans:bean id="chunkHandler" class="org.springframework.batch.integration.chunk.ItemWriterChunkHandler">
<beans:property name="itemWriter">
<beans:bean class="org.springframework.batch.integration.chunk.TestItemWriter"></beans:bean>
<beans:bean id="chunkHandler" class="org.springframework.batch.integration.chunk.ChunkProcessorChunkHandler">
<beans:property name="chunkProcessor">
<beans:bean class="org.springframework.batch.integration.chunk.SimpleChunkProcessor">
<beans:property name="itemWriter">
<beans:bean class="org.springframework.batch.integration.chunk.TestItemWriter" />
</beans:property>
<beans:property name="itemProcessor">
<beans:bean class="org.springframework.batch.item.support.PassthroughItemProcessor" />
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>

View File

@@ -11,8 +11,10 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<integration:message-bus auto-create-channels="true" />
<integration:message-bus/>
<integration:annotation-driven/>
<integration:channel id="resources" />
<integration:channel id="requests" />
<integration:channel id="requests">
<integration:queue capacity="UNBOUNDED"/>
</integration:channel>
</beans>

View File

@@ -11,7 +11,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<integration:message-bus auto-create-channels="true" />
<integration:message-bus/>
<integration:channel id="requests" />
<bean id="itemWriter" class="org.springframework.batch.integration.item.MessageChannelItemWriter">
<property name="channel" ref="requests"/>

View File

@@ -15,14 +15,15 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<import resource="classpath:/simple-job-launcher-context.xml" />
<integration:annotation-driven/>
<integration:message-bus auto-create-channels="true" />
<integration:message-bus/>
<integration:channel id="requests" />
<integration:channel id="replies" />
<integration:channel id="replies">
<integration:queue capacity="UNBOUNDED"/>
</integration:channel>
<bean id="job" parent="simpleJob">
<property name="steps">
<bean
<bean id="stepController"
class="org.springframework.batch.integration.job.MessageOrientedStep">
<property name="name" value="TODO: I shouldn't have to set this"/>
<property name="target" ref="requests" />
<property name="source" ref="replies" />
<property name="jobRepository" ref="jobRepository" />

View File

@@ -14,13 +14,15 @@
<import resource="classpath:simple-job-launcher-context.xml" />
<integration:message-bus auto-create-channels="true" />
<integration:message-bus/>
<integration:annotation-driven />
<integration:direct-channel id="requests" />
<integration:direct-channel id="jobs" />
<integration:thread-local-channel id="response" />
<integration:channel id="requests" />
<integration:channel id="jobs" />
<integration:channel id="response">
<integration:queue capacity="UNBOUNDED"/>
</integration:channel>
<integration:service-activator input-channel="requests" ref="jobLaunchingHandler" return-address-overrides="true" />
<integration:service-activator input-channel="requests" ref="jobLaunchingHandler"/>
<integration:service-activator input-channel="none" output-channel="jobs" ref="jobRequestConverter" />
<bean id="jobRequestConverter" class="org.springframework.batch.integration.launch.JobRequestConverter" />