Update constructor for Chunk

This commit is contained in:
dsyer
2009-01-05 12:15:17 +00:00
parent f8d239e18d
commit 25e456e4f1
5 changed files with 23 additions and 18 deletions

View File

@@ -52,6 +52,13 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>org.springframework.batch.test
</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>com.springsource.javax.jms

View File

@@ -9,7 +9,6 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.core.step.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
@@ -21,12 +20,12 @@ public class ChunkMessageChannelItemWriter<T> extends StepExecutionListenerSuppo
private static final Log logger = LogFactory.getLog(ChunkMessageChannelItemWriter.class);
static final String ACTUAL = ChunkMessageChannelItemWriter.class.getName()+".ACTUAL";
static final String ACTUAL = ChunkMessageChannelItemWriter.class.getName() + ".ACTUAL";
static final String EXPECTED = ChunkMessageChannelItemWriter.class.getName()+".EXPECTED";
static final String EXPECTED = ChunkMessageChannelItemWriter.class.getName() + ".EXPECTED";
private static final long DEFAULT_THROTTLE_LIMIT = 6;
private MessagingGateway messagingGateway;
private LocalState localState = new LocalState();
@@ -56,7 +55,8 @@ public class ChunkMessageChannelItemWriter<T> extends StepExecutionListenerSuppo
if (!items.isEmpty()) {
logger.debug("Dispatching chunk: " + items);
ChunkRequest<T> request = new ChunkRequest<T>(new Chunk<T>(items), localState.getJobId(), localState.createStepContribution());
ChunkRequest<T> request = new ChunkRequest<T>(items, localState.getJobId(), localState
.createStepContribution());
messagingGateway.send(request);
localState.expected++;
@@ -141,8 +141,9 @@ public class ChunkMessageChannelItemWriter<T> extends StepExecutionListenerSuppo
+ jobInstanceId + "] should have been [" + localState.getJobId() + "].");
localState.actual++;
// TODO: apply the skip count
if (! payload.isSuccessful()) {
throw new AsynchronousFailureException("Failure or interrupt detected in handler: "+payload.getMessage());
if (!payload.isSuccessful()) {
throw new AsynchronousFailureException("Failure or interrupt detected in handler: "
+ payload.getMessage());
}
}
}

View File

@@ -1,6 +1,7 @@
package org.springframework.batch.integration.chunk;
import java.io.Serializable;
import java.util.Collection;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.item.Chunk;
@@ -11,8 +12,8 @@ public class ChunkRequest<T> implements Serializable {
private final Chunk<T> items;
private final StepContribution stepContribution;
public ChunkRequest(Chunk<T> items, Long jobId, StepContribution stepContribution) {
this.items = items;
public ChunkRequest(Collection<? extends T> items, Long jobId, StepContribution stepContribution) {
this.items = new Chunk<T>(items);
this.jobId = jobId;
this.stepContribution = stepContribution;
}

View File

@@ -27,7 +27,6 @@ import org.springframework.batch.core.repository.dao.MapJobExecutionDao;
import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.item.Chunk;
import org.springframework.batch.core.step.item.SimpleStepFactoryBean;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.support.ListItemReader;
@@ -192,8 +191,7 @@ public class ChunkMessageItemWriterIntegrationTests {
private GenericMessage<ChunkRequest> getSimpleMessage(String string, Long jobId) {
StepContribution stepContribution = new JobExecution(new JobInstance(0L, new JobParameters(), "job"), 1L)
.createStepExecution("step").createStepContribution();
ChunkRequest chunk = new ChunkRequest(new Chunk<String>(StringUtils.commaDelimitedListToSet(string)), jobId,
stepContribution);
ChunkRequest chunk = new ChunkRequest(StringUtils.commaDelimitedListToSet(string), jobId, stepContribution);
GenericMessage<ChunkRequest> message = new GenericMessage<ChunkRequest>(chunk);
return message;
}

View File

@@ -4,12 +4,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.item.Chunk;
import org.springframework.batch.core.step.item.ChunkProcessor;
import org.springframework.batch.test.MetaDataInstanceFactory;
import org.springframework.util.StringUtils;
public class ChunkProcessorChunkHandlerTests {
@@ -25,10 +23,10 @@ public class ChunkProcessorChunkHandlerTests {
count += chunk.size();
}
});
StepContribution stepContribution = new JobExecution(new JobInstance(0L, new JobParameters(), "job"), 1L).createStepExecution("step").createStepContribution();
StepContribution stepContribution = MetaDataInstanceFactory.createStepExecution().createStepContribution();
@SuppressWarnings("unchecked")
ChunkResponse response = handler.handleChunk(new ChunkRequest<Object>(new Chunk<Object>(StringUtils
.commaDelimitedListToSet("foo,bar")), 12L, stepContribution));
ChunkResponse response = handler.handleChunk(new ChunkRequest<Object>(StringUtils
.commaDelimitedListToSet("foo,bar"), 12L, stepContribution));
assertEquals(stepContribution, response.getStepContribution());
assertEquals(12, response.getJobId().longValue());
assertTrue(response.isSuccessful());