BATCH-282: fix issue with bean factory initialization and concurrent modification
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package org.springframework.batch.core.scope;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public class JobStartupRunner {
|
||||
|
||||
private Step step;
|
||||
|
||||
public void setStep(Step step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void launch() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution("step", new JobExecution(1L), 0L);
|
||||
step.execute(stepExecution);
|
||||
// expect no errors
|
||||
}
|
||||
|
||||
}
|
||||
@@ -79,6 +79,10 @@ public class StepScopePlaceholderIntegrationTests implements BeanFactoryAware {
|
||||
@Test
|
||||
public void testSimpleProperty() throws Exception {
|
||||
assertEquals("bar", simple.getName());
|
||||
// Once the step context is set up it should be baked into the proxies
|
||||
// so changing it now should have no effect
|
||||
stepExecution.getExecutionContext().put("foo", "wrong!");
|
||||
assertEquals("bar", simple.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.batch.core.scope;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class StepScopeStartupIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testScopedProxyDuringStartup() throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,12 @@ public class TestStep implements Step {
|
||||
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException {
|
||||
context = StepSynchronizationManager.getContext();
|
||||
setContextFromCollaborator();
|
||||
stepExecution.getExecutionContext().put("foo", "changed but it shouldn't affect the collaborator");
|
||||
setContextFromCollaborator();
|
||||
}
|
||||
|
||||
private void setContextFromCollaborator() {
|
||||
if (context != null) {
|
||||
context.setAttribute("collaborator", collaborator.getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user