diff --git a/execution/src/main/java/org/springframework/batch/execution/bootstrap/AbstractJobLauncher.java b/execution/src/main/java/org/springframework/batch/execution/bootstrap/AbstractJobLauncher.java index 1543002c0..8f882f07e 100644 --- a/execution/src/main/java/org/springframework/batch/execution/bootstrap/AbstractJobLauncher.java +++ b/execution/src/main/java/org/springframework/batch/execution/bootstrap/AbstractJobLauncher.java @@ -188,6 +188,9 @@ public abstract class AbstractJobLauncher implements JobLauncher, * @throws NoSuchJobConfigurationException */ public ExitStatus run(String name) throws NoSuchJobConfigurationException { + if (name==null) { + throw new NoSuchJobConfigurationException("Null job name cannot be located."); + } JobIdentifier runtimeInformation = jobRuntimeInformationFactory .getJobIdentifier(name); return this.run(runtimeInformation); @@ -210,7 +213,7 @@ public abstract class AbstractJobLauncher implements JobLauncher, if (jobConfigurationName != null) { return this.run(jobConfigurationName); } - return ExitStatus.FAILED; + throw new NoSuchJobConfigurationException("Null default job name cannot be located."); } /** diff --git a/execution/src/main/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncher.java b/execution/src/main/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncher.java index 8226f1a3a..83e30eac2 100644 --- a/execution/src/main/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncher.java +++ b/execution/src/main/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncher.java @@ -16,8 +16,6 @@ package org.springframework.batch.execution.bootstrap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.configuration.JobConfiguration; import org.springframework.batch.core.configuration.NoSuchJobConfigurationException; import org.springframework.batch.core.runtime.JobIdentifier; @@ -43,8 +41,6 @@ import org.springframework.util.Assert; */ public class SimpleJobLauncher implements JobLauncher { - private static final Log logger = LogFactory.getLog(SimpleJobLauncher.class); - private volatile Thread processingThread; private volatile boolean running = false; @@ -114,6 +110,9 @@ public class SimpleJobLauncher implements JobLauncher { * @throws NoSuchJobConfigurationException */ public ExitStatus run(String name) throws NoSuchJobConfigurationException { + if (name==null) { + throw new NoSuchJobConfigurationException("Null job name cannot be located."); + } JobIdentifier runtimeInformation = jobIdentifierFactory.getJobIdentifier(name); return this.run(runtimeInformation); } @@ -127,20 +126,11 @@ public class SimpleJobLauncher implements JobLauncher { * @see #setJobIdentifierFactory(JobIdentifierFactory) * @see org.springframework.context.Lifecycle#start() */ - public ExitStatus run(){ + public ExitStatus run() throws NoSuchJobConfigurationException{ if (jobConfigurationName==null) { - return new ExitStatus(false, JOB_CONFIGURATION_NOT_PROVIDED, "No JobConfiguration was " + - "provided to the launcher."); - } - try { - return this.run(jobConfigurationName); - } - catch (NoSuchJobConfigurationException e) { - logger.error("JobExecutorFacade failed to find a JobConfiguration" + - " for the provided JobIdentifier", e); - return new ExitStatus(false, NO_SUCH_JOB_CONFIGURATION, "JobExecutor Facade failed" + - "to find a JobConfiguration for the provided JobIdentifier"); + throw new NoSuchJobConfigurationException("Null default job name cannot be located."); } + return this.run(jobConfigurationName); } /** diff --git a/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/BatchCommandLineLauncher.java b/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/BatchCommandLineLauncher.java index 90f18eee5..238c4b53e 100644 --- a/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/BatchCommandLineLauncher.java +++ b/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/BatchCommandLineLauncher.java @@ -259,7 +259,7 @@ public class BatchCommandLineLauncher { String name = System.getProperty(JOB_NAME_KEY); String parentKey = System.getProperty(BATCH_EXECUTION_ENVIRONMENT_KEY, DEFAULT_PARENT_KEY); - + BatchCommandLineLauncher command = new BatchCommandLineLauncher(); int result = command.start(path, name, parentKey); command.exit(result); diff --git a/execution/src/test/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncherTests.java b/execution/src/test/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncherTests.java index 65553d929..ee501038f 100644 --- a/execution/src/test/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncherTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/bootstrap/SimpleJobLauncherTests.java @@ -19,6 +19,7 @@ package org.springframework.batch.execution.bootstrap; import junit.framework.TestCase; import org.springframework.batch.core.configuration.JobConfiguration; +import org.springframework.batch.core.configuration.NoSuchJobConfigurationException; import org.springframework.batch.core.runtime.JobIdentifier; import org.springframework.batch.core.runtime.SimpleJobIdentifierFactory; import org.springframework.batch.execution.facade.JobExecutorFacade; @@ -45,9 +46,10 @@ public class SimpleJobLauncherTests extends TestCase { try { launcher.run(); // should do nothing + fail("Expected NoSuchJobConfigurationException"); } - catch (Exception e) { - fail("Unexpected IllegalStateException"); + catch (NoSuchJobConfigurationException e) { + assertTrue("Message should mention null job name: "+e.getMessage(), e.getMessage().toLowerCase().indexOf("null")>=0); } } @@ -75,16 +77,18 @@ public class SimpleJobLauncherTests extends TestCase { TaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); Runnable launcherRunnable = new Runnable() { public void run() { - System.out.println("run called"); - launcher.run(); - System.out.println("run finished."); + try { + launcher.run(); + } catch (NoSuchJobConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } }; taskExecutor.execute(launcherRunnable); // give the thread a second to start up - System.out.println("first sleep"); Thread.sleep(100); assertTrue(launcher.isRunning()); launcher.stop(); @@ -112,7 +116,6 @@ public class SimpleJobLauncherTests extends TestCase { try { // 1 seconds should be long enough to allow the thread to be // run and for interrupt to be called; - System.out.println("Facade sleep called."); Thread.sleep(300); //return ExitStatus.FAILED;