/** * Pull a Tasklet out of a step. * @param step a TaskletStep * @return the Tasklet */ private Tasklet getTasklet(TaskletStep step) { return (Tasklet) getField(step, "tasklet"); }
@Override public void beforeStep(StepExecution stepExecution) { localState.setStepExecution(stepExecution); }
/** * Creates a {@link RemoteChunkingMasterStepBuilder} and initializes its job * repository and transaction manager. * * @param name the name of the step * @param <I> type of input items * @param <O> type of output items * @return a {@link RemoteChunkingMasterStepBuilder} */ public <I, O> RemoteChunkingMasterStepBuilder<I, O> get(String name) { return new RemoteChunkingMasterStepBuilder<I, O>(name) .repository(this.jobRepository) .transactionManager(this.transactionManager); }
@Bean public TaskletStep masterStep() { return this.masterStepBuilderFactory.get("masterStep") .<Integer, Integer>chunk(3) .reader(itemReader()) .outputChannel(requests()) .inputChannel(replies()) .build(); }
@Test public void inputChannelMustNotBeNull() { // given this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("inputChannel must not be null"); // when IntegrationFlow integrationFlow = new RemoteChunkingWorkerBuilder<String, String>() .inputChannel(null) .build(); // then // expected exception }
@Test public void messagingTemplateMustNotBeNull() { // given this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("messagingTemplate must not be null"); // when TaskletStep step = new RemoteChunkingMasterStepBuilder<String, String>("step") .messagingTemplate(null) .build(); // then // expected exception }
public <T> ChunkRequest<T> getRequest(List<? extends T> items) { return new ChunkRequest<>(current.incrementAndGet(), items, getJobId(), createStepContribution()); }
@Test public void testMandatoryPropertiesSet() throws Exception { MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(); interceptor.setMessageSource(new TestMessageSource("foo")); interceptor.afterPropertiesSet(); }
public Collection<StepContribution> getStepContributions() { List<StepContribution> contributions = new ArrayList<>(); for (ChunkResponse response : localState.pollChunkResponses()) { StepContribution contribution = response.getStepContribution(); if (logger.isDebugEnabled()) { logger.debug("Applying: " + response); } contributions.add(contribution); } return contributions; }
@Test public void testMandatoryPropertiesSetViaConstructor() throws Exception { MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(new TestMessageSource("foo")); interceptor.afterPropertiesSet(); }
@Test public void testPreReceive() throws Exception { MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(new TestMessageSource("foo")); QueueChannel channel = new QueueChannel(); assertTrue(interceptor.preReceive(channel)); assertEquals("foo", channel.receive(10L).getPayload()); }
@Override protected void write(StepContribution contribution, Chunk<T> inputs, Chunk<T> outputs) throws Exception { doWrite(outputs.getItems()); // Do not update the step contribution until the chunks are // actually processed updateStepContribution(contribution, stepContributionSource); } });
@Bean public <I,O> RemoteChunkingWorkerBuilder<I, O> remoteChunkingWorkerBuilder() { return new RemoteChunkingWorkerBuilder<>(); }
public void open(ExecutionContext executionContext) throws ItemStreamException { if (executionContext.containsKey(EXPECTED)) { localState.open(executionContext.getInt(EXPECTED), executionContext.getInt(ACTUAL)); if (!waitForResults()) { throw new ItemStreamException("Timed out waiting for back log on open"); } } }
@Test(expected = IllegalStateException.class) public void testMandatoryPropertiesUnset() throws Exception { MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(); interceptor.afterPropertiesSet(); }
public void close() throws ItemStreamException { localState.reset(); }
/** * Re-throws the original throwable if it is unchecked, wraps checked exceptions into * {@link AsynchronousFailureException}. */ private static AsynchronousFailureException wrapIfNecessary(Throwable throwable) { if (throwable instanceof Error) { throw (Error) throwable; } else if (throwable instanceof AsynchronousFailureException) { return (AsynchronousFailureException) throwable; } else { return new AsynchronousFailureException("Exception in remote process", throwable); } }
@Bean public RemoteChunkingMasterStepBuilderFactory remoteChunkingMasterStepBuilderFactory() { return new RemoteChunkingMasterStepBuilderFactory(this.jobRepository, this.transactionManager); }
/** * Pull out an item writer from a ChunkProcessor * @param chunkProcessor a ChunkProcessor * @return its ItemWriter */ @SuppressWarnings("unchecked") private ItemWriter<T> getItemWriter(ChunkProcessor<T> chunkProcessor) { return (ItemWriter<T>) getField(chunkProcessor, "itemWriter"); }
/** * Pull the ChunkProcessor out of a tasklet. * @param tasklet a ChunkOrientedTasklet * @return the ChunkProcessor */ @SuppressWarnings("unchecked") private ChunkProcessor<T> getChunkProcessor(ChunkOrientedTasklet<?> tasklet) { return (ChunkProcessor<T>) getField(tasklet, "chunkProcessor"); }