From 045e476ab5187b6d6e84dc9ecfc41231415c258d Mon Sep 17 00:00:00 2001 From: dsyer Date: Tue, 23 Oct 2007 13:04:16 +0000 Subject: [PATCH] IN PROGRESS - issue BATCH-159: JobExecutor should return a JobExecution (which itself contains the ExitStatus) http://opensource.atlassian.com/projects/spring/browse/BATCH-159 Use package access instead of reflection to get to registry inside facade --- .../batch/execution/facade/SimpleJobExecutorFacade.java | 7 ++++--- .../execution/facade/SimpleJobExecutorFacadeTests.java | 6 +----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java b/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java index d8b594bcc..d30758d7e 100644 --- a/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java +++ b/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java @@ -59,7 +59,8 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, private JobRepository jobRepository; - private Map jobExecutionRegistry = new HashMap(); + // Package access for unit testing... + Map jobExecutionRegistry = new HashMap(); // there is no sensible default for this private JobConfigurationLocator jobConfigurationLocator; @@ -141,7 +142,6 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, JobInstance job = jobRepository.findOrCreateJob(jobConfiguration, jobIdentifier); JobExecution jobExecution = new JobExecution(job); - jobExecutionRegistry.put(jobIdentifier, jobExecution); try { @@ -152,7 +152,6 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, } finally { this.after(jobExecution); - jobExecutionRegistry.remove(jobIdentifier); } @@ -169,6 +168,7 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, public void before(JobExecution execution) { synchronized (mutex) { running++; + jobExecutionRegistry.put(execution.getJobIdentifier(), execution); } for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = (JobExecutionListener) iterator @@ -195,6 +195,7 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, synchronized (mutex) { // assume execution is synchronous so when we get to here we are // not running any more + jobExecutionRegistry.remove(execution.getJobIdentifier()); running--; } } diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java index 1596f518f..cdc4d44db 100644 --- a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacadeTests.java @@ -16,7 +16,6 @@ package org.springframework.batch.execution.facade; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -36,7 +35,6 @@ import org.springframework.batch.core.runtime.SimpleJobIdentifier; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.context.RepeatContextSupport; -import org.springframework.util.ReflectionUtils; /** * SimpleBatchContainer unit tests. @@ -248,9 +246,7 @@ public class SimpleJobExecutorFacadeTests extends TestCase { private void registerExecution(SimpleJobIdentifier runtimeInformation, JobExecution execution) throws NoSuchFieldException, IllegalAccessException { - Field field = SimpleJobExecutorFacade.class.getDeclaredField("jobExecutionRegistry"); - ReflectionUtils.makeAccessible(field); - Map map = (Map) field.get(jobExecutorFacade); + Map map = (Map) jobExecutorFacade.jobExecutionRegistry; map.put(runtimeInformation, execution); }