-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add AbstractTaskletStepBuilder copy constructor #4471
Conversation
* copied, so it can be re-used. | ||
* @param parent a parent helper containing common step properties | ||
* | ||
* @author Ilpyo Yang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @author
should be located on L51
, not here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to L51
completed!
|
||
@Test | ||
void faultTolerantMethodTest() throws ReflectiveOperationException { | ||
simpleStepBuilder.taskExecutor(taskExecutor); // The task executor is set before faultTolerant() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertEquals(taskExecutor, afterTaskExecutor);
Can we check taskExecutor is copied well after faultTolerant()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it, thank you for the review.
e281868
to
a22d354
Compare
/** | ||
* Create a new builder initialized with any properties in the parent. The parent is | ||
* copied, so it can be re-used. | ||
* @param parent a parent helper containing common step properties | ||
*/ | ||
public AbstractTaskletStepBuilder(AbstractTaskletStepBuilder<?> parent) { | ||
super(parent); | ||
this.chunkListeners = parent.chunkListeners; | ||
this.stepOperations = parent.stepOperations; | ||
this.transactionManager = parent.transactionManager; | ||
this.transactionAttribute = parent.transactionAttribute; | ||
this.streams.addAll(parent.streams); | ||
this.exceptionHandler = parent.exceptionHandler; | ||
this.throttleLimit = parent.throttleLimit; | ||
this.taskExecutor = parent.taskExecutor; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() // after faultTolerant(), taskExecutor is not copied
// cause there's no copy constructor of AbstractTaskletStepBuilder!
.build();
Hi @fmbenhassine , me and @Ilpyo-Yang checked that there's no copy constructor of AbstractTaskletStepBuilder
, so SimpleStepBuilder.faultTolerant()
doesn't copy member variables of AbstractTaskletStepBuilder
well now.
All users who use SimpleStepBuilder.faultTolerant()
affected by this bug, so I think it's good to release this bug fix on next release.
So can you review this PR? thanks a lot! 🙇
this.stepOperations = parent.stepOperations; | ||
this.transactionManager = parent.transactionManager; | ||
this.transactionAttribute = parent.transactionAttribute; | ||
this.streams.addAll(parent.streams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.streams.addAll(parent.streams); | |
this.streams = parent.streams; |
Hmm maybe we can just use parent.streams
instead of addAll()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm maybe we can just use
parent.streams
instead ofaddAll()
?
To creating a copy constructor, it seems like the second option, this.streams = parents.streams
, is appropriate. Thank you for your comment @injae-kim!
But just curious.. was there any specific reason for initially declaring streams
as a final
variable?
* copied, so it can be re-used. | ||
* @param parent a parent helper containing common step properties | ||
*/ | ||
public AbstractTaskletStepBuilder(AbstractTaskletStepBuilder<?> parent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making it protected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I will try thanks!
@@ -0,0 +1,114 @@ | |||
package org.springframework.batch.test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think package line should be followed by copyright comments. (see also)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't recognize it.. I will updated it ;)
*/ | ||
@SpringBatchTest | ||
@SpringJUnitConfig | ||
public class AbstractTaskletStepBuilderTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test code should be placed somewhere in spring-batch-core/src/test/java....
spring-batch-test module is for providing test utils for spring batch users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm that is why this not merged.. I missed few things in contribute regulation. Thank you for kindness review. I will update all in this holiday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acktsap thanks for the detailed review, and I've incorporated the suggested changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see this class in the spring-batch-test
module. No problem, I will move it to the core module on merge.
a22d354
to
f5dd94c
Compare
Thank you for the PR! It fixes the issue 👍 However, for the test, there is no need to test the copy constructor itself. I think something like the test suggested in #4438 is enough to validate the fix and cover the code path for any future regression. Could you please update the test and rebase/squash the changes? It should then be good to merge. Thank you upfront! |
This commit includes tests for the copy constructor of AbstractTaskletStepBuilder and for the faultTolerant method, specifically after taskExecutor has been set.
Hello @fmbenhassine! |
Thank you for the updates, @Ilpyo-Yang ! I noticed that the tests pass even without the changes in the PR. I think we can simplify tests by checking that the type of the repeat template is correct whether the task executor is set before or after |
- Update tests - Move test class to the core module
- Update tests - Move test class to the core module (cherry picked from commit 4b8e504)
- Update tests - Move test class to the core module (cherry picked from commit 4b8e504)
Description
This PR adds a copy constructor to the AbstractTaskletStepBuilder to address an issue arising during the property setting process with taskExecutor.
Changes
Resolve #4438