@Override protected void doExecutionRegistration(StepExecution stepExecution) { StepSynchronizationManager.register(stepExecution, propertyContext); } }
public static <T> T doInStepScope(StepExecution stepExecution, Callable<T> callable) throws Exception { try { StepSynchronizationManager.register(stepExecution); return callable.call(); } finally { StepSynchronizationManager.close(); } }
@Around("execution(void org.springframework.batch.core.Step+.execute(*)) && target(step) && args(stepExecution)") public void execute(Step step, StepExecution stepExecution) throws JobInterruptedException { StepSynchronizationManager.register(stepExecution); try { step.execute(stepExecution); } finally { StepSynchronizationManager.release(); } }
public void init(Class<?>... config) throws Exception { Class<?>[] configs = new Class<?>[config.length + 1]; System.arraycopy(config, 0, configs, 1, config.length); configs[0] = DataSourceConfiguration.class; AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(configs); context.refresh(); this.context = context; StepSynchronizationManager.register(stepExecution); }
@Test public void testXmlStepScopeWithInheritance() throws Exception { context = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/annotation/StepScopeConfigurationTestsInheritance-context.xml"); StepSynchronizationManager.register(stepExecution); SimpleHolder value = (SimpleHolder) context.getBean("child"); assertEquals("STEP", value.call()); }
@Test public void testRegisterTwice() { StepSynchronizationManager.register(stepExecution); StepSynchronizationManager.register(stepExecution); StepSynchronizationManager.close(); // if someone registers you have to assume they are going to close, so // the last thing you want is for the close to remove another context // that someone else has registered assertNotNull(StepSynchronizationManager.getContext()); StepSynchronizationManager.close(); assertNull(StepSynchronizationManager.getContext()); }
@Before public void start() throws Exception { int count = doTest("vanilla", "warmup"); logger.info("Item count: "+count); StepSynchronizationManager.close(); StepSynchronizationManager.register(new StepExecution("step", new JobExecution(0L),1L)); }
@Test public void testGetContext() { assertNull(StepSynchronizationManager.getContext()); StepSynchronizationManager.register(stepExecution); assertNotNull(StepSynchronizationManager.getContext()); }
@Test public void testRegisterNull() { assertNull(StepSynchronizationManager.getContext()); StepSynchronizationManager.register(null); assertNull(StepSynchronizationManager.getContext()); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString("inputFile", "file:./build/test-outputs/fixedLengthOutput.txt").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString("inputFile", "file:./build/test-outputs/delimitedOutput.csv").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString( "input.file.path", "file:build/test-outputs/multiResourceOutput.csv.*").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addDouble("credit", 0.) .toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
private void start(String foo) { StepSynchronizationManager.close(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", foo); executionContext.put("type", TestCollaborator.class.getName()); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Test public void testGetContextWithBatchProperties() { StepContext context = StepSynchronizationManager.getContext(); assertNull(context); StepSynchronizationManager.register(stepExecution, propertyContext); context = StepSynchronizationManager.getContext(); assertNotNull(context); assertEquals(stepExecution, context.getStepExecution()); }
@Test public void testSimpleProperty() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 123L); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); StepSynchronizationManager.register(stepExecution); assertEquals("bar", simple.getName()); }
@Test public void testInitialCreationSingleThreadUsingStepScope() throws Exception { factoryBean.setBatchPropertyContext(propertyContext); StepSynchronizationManager.register(new StepExecution("step1", new JobExecution(5L))); JobContext jobContext = factoryBean.getObject(); assertEquals(5L, jobContext.getExecutionId()); StepSynchronizationManager.close(); }
private void start(String foo) { StepSynchronizationManager.close(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", foo); executionContext.put("parent", bar); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Before public void start() { StepSynchronizationManager.close(); TestStep.reset(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", "bar"); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); beanCount = beanFactory.getBeanDefinitionCount(); }
@Test public void testCompoundPropertyTwice() throws Exception { assertEquals("bar-bar", compound.getName()); StepSynchronizationManager.close(); stepExecution = new StepExecution("foo", new JobExecution(11L), 123L); ExecutionContext executionContext = new ExecutionContext(); executionContext.put("foo", "spam"); stepExecution.setExecutionContext(executionContext); StepSynchronizationManager.register(stepExecution); assertEquals("spam-bar", compound.getName()); }