RESOLVED - issue BATCH-552: Fix smaples-14 CI build (MBeanServer not automatically created in Java 1.4)

Added MBeanServer and a connector
This commit is contained in:
dsyer
2008-04-03 12:22:38 +00:00
parent 1b659fe744
commit fcca799608
3 changed files with 51 additions and 18 deletions

View File

@@ -230,7 +230,13 @@
<dependency>
<groupId>mx4j</groupId>
<artifactId>mx4j</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mx4j</groupId>
<artifactId>mx4j-remote</artifactId>
<version>3.0.2</version>
<optional>true</optional>
</dependency>
<dependency>

View File

@@ -9,7 +9,15 @@
<!-- For Java 1.4 we need to ceate teh mbean server explicitly -->
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true"/>
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="1099" />
</bean>
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl" value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/batch-samples" />
<property name="server" ref="mbeanServer" />
</bean>
<bean class="org.springframework.jmx.export.MBeanExporter">
<property name="server" ref="mbeanServer" />

View File

@@ -18,53 +18,59 @@ package org.springframework.batch.sample.launch;
import java.util.ArrayList;
import java.util.List;
import javax.management.MBeanServerConnection;
import junit.framework.TestCase;
import org.springframework.batch.core.launch.support.ExportedJobLauncher;
import org.springframework.jmx.MBeanServerNotFoundException;
import org.springframework.jmx.access.InvalidInvocationException;
import org.springframework.jmx.access.MBeanProxyFactoryBean;
import org.springframework.jmx.support.MBeanServerConnectionFactoryBean;
/**
* @author Dave Syer
*
*
*/
public class RemoteLauncherTests extends TestCase {
private static List errors = new ArrayList();
private static Thread thread;
private static ExportedJobLauncher launcher;
private static MBeanProxyFactoryBean factory;
public void testConnect() throws Exception {
doLaunch();
assertEquals(0, errors.size());
assertTrue(isConnected());
}
public void testLaunchBadJob() throws Exception {
doLaunch();
assertEquals(0, errors.size());
assertTrue(isConnected());
String result = launcher.run("foo");
assertTrue("Should contain 'NoSuchJobException': "+result, result.indexOf("NoSuchJobException")>=0);
assertTrue("Should contain 'NoSuchJobException': " + result, result.indexOf("NoSuchJobException") >= 0);
}
public void testLaunchAndStopRealJob() throws Exception {
doLaunch();
assertEquals(0, errors.size());
assertTrue(isConnected());
String result = launcher.run("loopJob");
assertTrue("Should contain 'JobExecution': "+result, result.indexOf("JobExecution: id=")>=0);
assertTrue("Should contain 'JobExecution': " + result, result.indexOf("JobExecution: id=") >= 0);
Thread.sleep(500);
assertTrue(launcher.isRunning());
launcher.stop();
assertFalse(launcher.isRunning());
}
/**
* @throws Exception
/*
* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
private static void doLaunch() throws Exception {
if (launcher!=null) {
protected void setUp() throws Exception {
if (launcher != null) {
return;
}
System.setProperty("com.sun.management.jmxremote", "");
@@ -79,13 +85,15 @@ public class RemoteLauncherTests extends TestCase {
}
});
thread.start();
MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
MBeanServerConnectionFactoryBean connectionFactory = new MBeanServerConnectionFactoryBean();
connectionFactory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/batch-samples");
factory = new MBeanProxyFactoryBean();
factory.setObjectName("spring:service=batch,bean=jobLauncher");
factory.setProxyInterface(ExportedJobLauncher.class);
factory.afterPropertiesSet();
launcher = (ExportedJobLauncher) factory.getObject();
factory.setServer((MBeanServerConnection) connectionFactory.getObject());
// factory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/batch-samples");
int count = 0;
while (!isConnected() && count ++<10) {
while (!isConnected() && count++ < 10) {
Thread.sleep(1000);
}
}
@@ -98,10 +106,21 @@ public class RemoteLauncherTests extends TestCase {
if (!TaskExecutorLauncher.getErrors().isEmpty()) {
throw (RuntimeException) TaskExecutorLauncher.getErrors().get(0);
}
if (launcher == null) {
try {
factory.afterPropertiesSet();
launcher = (ExportedJobLauncher) factory.getObject();
}
catch (MBeanServerNotFoundException e) {
// ignore
return false;
}
}
try {
launcher.isRunning();
connected = true;
} catch (InvalidInvocationException e) {
}
catch (InvalidInvocationException e) {
// ignore
}
return connected;