Clear context to job name mapping when clearing contexts BATCH-2347
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user