BATCH-282: fix issue with bean factory initialization and concurrent modification

This commit is contained in:
dsyer
2008-11-20 08:34:53 +00:00
parent 41e22f08b9
commit 892e037f1d
9 changed files with 173 additions and 69 deletions

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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 {
}
}

View File

@@ -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());
}