Attempt to refactor NFL so that it can be run from a command line launcher in Eclipse instead of a unit test

This commit is contained in:
dsyer
2007-10-04 15:36:50 +00:00
parent 3b2662a16b
commit 3f19eb2a7a
4 changed files with 21 additions and 25 deletions

View File

@@ -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.");
}
/**

View File

@@ -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);
}
/**

View File

@@ -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);

View File

@@ -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;