OPEN - issue BATCH-773: Refactor and extend ExportedJobLauncher to JobOperator
Removed old ExportedJobLauncher and replace where necessary
This commit is contained in:
@@ -6,16 +6,10 @@
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
<import resource="simple-job-launcher-context.xml" />
|
||||
|
||||
<bean class="org.springframework.jmx.export.MBeanExporter">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="spring:service=batch,bean=jobLauncher">
|
||||
<bean class="org.springframework.batch.core.launch.support.SimpleExportedJobLauncher">
|
||||
<property name="launcher" ref="jobLauncher" />
|
||||
<property name="jobLocator" ref="jobRegistry" />
|
||||
</bean>
|
||||
</entry>
|
||||
<entry key="spring:service=batch,bean=jobOperator" value-ref="jobOperator" />
|
||||
<entry key="spring:service=batch,bean=notificationPublisher" value-ref="notificationPublisher" />
|
||||
<entry key="spring:service=batch,bean=jobLoader" value-ref="loader" />
|
||||
</map>
|
||||
@@ -24,7 +18,7 @@
|
||||
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
|
||||
<property name="interfaceMappings">
|
||||
<map>
|
||||
<entry key="spring:service=batch,bean=jobLauncher" value="org.springframework.batch.core.launch.support.ExportedJobLauncher" />
|
||||
<entry key="spring:service=batch,bean=jobLauncher" value="org.springframework.batch.core.launch.JobOperator" />
|
||||
<entry key="spring:service=batch,bean=jobLoader" value="org.springframework.batch.sample.launch.JobLoader" />
|
||||
</map>
|
||||
</property>
|
||||
@@ -33,10 +27,20 @@
|
||||
</bean>
|
||||
<bean id="notificationPublisher" class="org.springframework.batch.sample.jmx.JobExecutionNotificationPublisher" />
|
||||
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
|
||||
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="taskExecutor">
|
||||
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
||||
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
|
||||
<property name="jobExplorer">
|
||||
<bean class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="databaseType" value="${environment}" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="jobRegistry" ref="jobRegistry" />
|
||||
<property name="jobLauncher">
|
||||
<bean parent="jobLauncher">
|
||||
<property name="taskExecutor">
|
||||
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="loader" class="org.springframework.batch.sample.launch.DefaultJobLoader">
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package org.springframework.batch.sample.launch;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,7 +29,8 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.launch.support.ExportedJobLauncher;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.core.launch.support.JobRegistryBackgroundJobRunner;
|
||||
import org.springframework.jmx.MBeanServerNotFoundException;
|
||||
import org.springframework.jmx.access.InvalidInvocationException;
|
||||
@@ -46,7 +47,7 @@ public class RemoteLauncherTests {
|
||||
|
||||
private static List<Exception> errors = new ArrayList<Exception>();
|
||||
|
||||
private static ExportedJobLauncher launcher;
|
||||
private static JobOperator launcher;
|
||||
|
||||
private static JobLoader loader;
|
||||
|
||||
@@ -61,21 +62,19 @@ public class RemoteLauncherTests {
|
||||
public void testLaunchBadJob() throws Exception {
|
||||
assertEquals(0, errors.size());
|
||||
assertTrue(isConnected());
|
||||
String result = launcher.run("foo");
|
||||
assertTrue("Should contain 'NoSuchJobException': " + result, result.indexOf("NoSuchJobException") >= 0);
|
||||
try {
|
||||
launcher.start("foo", "");
|
||||
fail("Expected NoSuchJobException");
|
||||
} catch (NoSuchJobException e) {
|
||||
//expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchAndStopRealJob() throws Exception {
|
||||
public void testAvailableJobs() throws Exception {
|
||||
assertEquals(0, errors.size());
|
||||
assertTrue(isConnected());
|
||||
String result = launcher.run("loopJob");
|
||||
assertTrue("Should contain 'JobExecution': " + result, result.indexOf("JobExecution: id=") >= 0);
|
||||
Thread.sleep(500);
|
||||
assertTrue(launcher.isRunning());
|
||||
launcher.stop();
|
||||
Thread.sleep(500);
|
||||
assertFalse(launcher.isRunning());
|
||||
assertTrue(launcher.getJobNames().contains("loopJob"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -112,9 +111,8 @@ public class RemoteLauncherTests {
|
||||
}
|
||||
if (launcher == null) {
|
||||
MBeanServerConnectionFactoryBean connectionFactory = new MBeanServerConnectionFactoryBean();
|
||||
connectionFactory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/batch-samples");
|
||||
try {
|
||||
launcher = (ExportedJobLauncher) getMBean(connectionFactory, "spring:service=batch,bean=jobLauncher", ExportedJobLauncher.class);
|
||||
launcher = (JobOperator) getMBean(connectionFactory, "spring:service=batch,bean=jobOperator", JobOperator.class);
|
||||
loader = (JobLoader) getMBean(connectionFactory, "spring:service=batch,bean=jobLoader", JobLoader.class);
|
||||
}
|
||||
catch (MBeanServerNotFoundException e) {
|
||||
@@ -123,7 +121,7 @@ public class RemoteLauncherTests {
|
||||
}
|
||||
}
|
||||
try {
|
||||
launcher.isRunning();
|
||||
launcher.getJobNames();
|
||||
connected = loader.getConfigurations().size()>0;
|
||||
logger.info("Configurations loaded: " + loader.getConfigurations());
|
||||
}
|
||||
@@ -139,7 +137,6 @@ public class RemoteLauncherTests {
|
||||
factory.setObjectName(objectName);
|
||||
factory.setProxyInterface(interfaceType);
|
||||
factory.setServer((MBeanServerConnection) connectionFactory.getObject());
|
||||
// factory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/batch-samples");
|
||||
factory.afterPropertiesSet();
|
||||
return factory.getObject();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user