Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect step configuration when setting the taskExecutor before faultTolerant() #4438

Closed
Wood-Chopper opened this issue Aug 30, 2023 · 2 comments
Labels
for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line has: minimal-example Bug reports that provide a minimal complete reproducible example in: core type: bug
Milestone

Comments

@Wood-Chopper
Copy link

Hello,

I think I spotted an issue related to the StepBuilder. Depending on the order a developer build its step, the taskExecutor field will have different values.

Here is a minimal example to reproduce the issue:

step1 and step2 are exactly the same, except in one thing.

public class SpringBatchTest {

    private PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    private JobRepository jobRepository =  mock(JobRepository.class);
    private ItemReader itemReader = mock(ItemReader.class);
    private ItemProcessor itemProcessor = mock(ItemProcessor.class);
    private ItemWriter itemWriter = mock(ItemWriter.class);

    private SimpleAsyncTaskExecutor taskExecutor  = new SimpleAsyncTaskExecutor();

    @Test
    void test_inconsistent_behavior() {
        TaskletStep step1 = new StepBuilder("step-name", jobRepository)
                .chunk(10, transactionManager)
                .reader(itemReader)
                .processor(itemProcessor)
                .writer(itemWriter)
                .faultTolerant()
                .taskExecutor(taskExecutor)
                .build();
        TaskletStep step2 = new StepBuilder("step-name", jobRepository)
                .chunk(10, transactionManager)
                .taskExecutor(taskExecutor)// The task executor is set before faultTolerant()
                .reader(itemReader)
                .processor(itemProcessor)
                .writer(itemWriter)
                .faultTolerant()
                .build();

        RepeatTemplate stepOperations1 = (RepeatTemplate) ReflectionUtils
                .readFieldValue(TaskletStep.class, "stepOperations", step1).get();// TaskExecutorRepeatTemplate
        RepeatTemplate stepOperations2 = (RepeatTemplate) ReflectionUtils
                .readFieldValue(TaskletStep.class, "stepOperations", step2).get();// RepeatTemplate

        assertEquals(stepOperations1.getClass(), stepOperations2.getClass());// This fails
    }
}

In this example, step2 will use the default task executor instead of the provided one.

Looking at the code, the taskExecutor value is lost after setting faultTolerant().

I did not go too deep into the solution, but I think the issue comes from this constructor (see link). The taskExecutor value could be kept from there.

@fmbenhassine fmbenhassine added type: bug in: core has: minimal-example Bug reports that provide a minimal complete reproducible example labels Oct 13, 2023
@ilpyoyang
Copy link
Contributor

Hello @fmbenhassine may i handle this issue? please assign to me. i will make pr soon :)

@fmbenhassine fmbenhassine changed the title StepBuilder - issue when setting the taskExecutor before faultTolerant() Incorrect step configuration when setting the taskExecutor before faultTolerant() Feb 20, 2024
@fmbenhassine fmbenhassine added this to the 5.2.0 milestone Feb 20, 2024
@fmbenhassine fmbenhassine added for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line labels Feb 20, 2024
@fmbenhassine
Copy link
Contributor

@Wood-Chopper Thank you for reporting this issue!

Resolved in b9ba8ff.

This was referenced Feb 20, 2024
@fmbenhassine fmbenhassine modified the milestones: 5.2.0, 5.2.0-M1 Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line has: minimal-example Bug reports that provide a minimal complete reproducible example in: core type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants