Clear context to job name mapping when clearing contexts BATCH-2347

This commit is contained in:
Michael Minella
2015-03-06 11:54:44 -06:00
parent acbe718d78
commit 8b32462072
2 changed files with 22 additions and 6 deletions

View File

@@ -15,8 +15,15 @@
*/
package org.springframework.batch.core.configuration.support;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.DuplicateJobException;
@@ -30,12 +37,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Default implementation of {@link JobLoader}. Uses a {@link JobRegistry} to
* manage a population of loaded jobs and clears them up when asked. An optional
@@ -118,6 +119,7 @@ public class DefaultJobLoader implements JobLoader, InitializingBean {
doUnregister(jobName);
}
contexts.clear();
contextToJobNames.clear();
}
@Override

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.batch.core.Job;
@@ -35,6 +36,7 @@ import org.springframework.batch.core.step.NoSuchStepException;
import org.springframework.batch.core.step.StepLocator;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.util.ReflectionTestUtils;
/**
* @author Dave Syer
@@ -57,6 +59,18 @@ public class DefaultJobLoaderTests {
private DefaultJobLoader jobLoader = new DefaultJobLoader(jobRegistry, stepRegistry);
@Test
public void testClear() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(new ByteArrayResource(
JOB_XML.getBytes()));
jobLoader.load(factory);
assertEquals(1, ((Map) ReflectionTestUtils.getField(jobLoader, "contexts")).size());
assertEquals(1, ((Map) ReflectionTestUtils.getField(jobLoader, "contextToJobNames")).size());
jobLoader.clear();
assertEquals(0, ((Map) ReflectionTestUtils.getField(jobLoader, "contexts")).size());
assertEquals(0, ((Map) ReflectionTestUtils.getField(jobLoader, "contextToJobNames")).size());
}
@Test
public void testLoadWithExplicitName() throws Exception {
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(new ByteArrayResource(