summaryrefslogtreecommitdiff
path: root/qpid/java/management
diff options
context:
space:
mode:
authorAndrea Gazzarini <agazzarini@apache.org>2009-02-16 08:08:56 +0000
committerAndrea Gazzarini <agazzarini@apache.org>2009-02-16 08:08:56 +0000
commit5420d85fc6a07e0b068389b97f099d4b6e3a621e (patch)
treebbc065e9535a897b4cd1a495096dff8b76a5a074 /qpid/java/management
parent8abf714563c14066fab3e715dfb057d23adae73d (diff)
downloadqpid-python-5420d85fc6a07e0b068389b97f099d4b6e3a621e.tar.gz
QPID-1663 : WsDmAdapterTest fix. A preliminary search is made in order to find an available port for embedded Web Server.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@744850 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/management')
-rw-r--r--qpid/java/management/client/build.xml1
-rw-r--r--qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java30
-rw-r--r--qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java37
3 files changed, 49 insertions, 19 deletions
diff --git a/qpid/java/management/client/build.xml b/qpid/java/management/client/build.xml
index 15c9e6e6ba..6543a569ee 100644
--- a/qpid/java/management/client/build.xml
+++ b/qpid/java/management/client/build.xml
@@ -22,7 +22,6 @@
<property name="module.depends" value="client common"/>
<property name="module.test.depends" value="client common"/>
-<property name="module.test.excludes" value="**/WsDmAdapterTest.java"/>
<import file="../../module.xml"/>
diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
index 395fe657c0..6574c278ff 100644
--- a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
+++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
@@ -37,11 +37,13 @@ import org.mortbay.start.Monitor;
*
* @author Andrea Gazzarini
*/
-public class ServerThread extends Thread
+class ServerThread extends Thread
{
private final Listener _lifecycleListener;
private Server _server;
+ private SelectChannelConnector _connector;
+
/**
* Builds a new server thread with the given lifecycle listener.
*
@@ -63,14 +65,13 @@ public class ServerThread extends Thread
Monitor.monitor();
_server = new Server();
_server.setStopAtShutdown(true);
+
+ _connector=new SelectChannelConnector();
+ _connector.setPort(Integer.parseInt(System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME)));
+ _connector.setHost(System.getProperty(Names.ADAPTER_HOST_PROPERTY_NAME));
- Connector connector=new SelectChannelConnector();
- connector.setPort(
- Integer.parseInt(
- System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME)));
- connector.setHost(System.getProperty(Names.ADAPTER_HOST_PROPERTY_NAME));
- _server.setConnectors(new Connector[]{connector});
+ _server.setConnectors(new Connector[]{_connector});
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/qman");
@@ -85,7 +86,9 @@ public class ServerThread extends Thread
webapp.addLifeCycleListener(_lifecycleListener);
_server.setHandler(webapp);
_server.start();
+ System.setProperty(Names.ADAPTER_PORT_PROPERTY_NAME,String.valueOf( _connector.getLocalPort()));
_server.join();
+
} catch(Exception exception)
{
throw new RuntimeException(exception);
@@ -97,8 +100,19 @@ public class ServerThread extends Thread
*
* @throws Exception when a problem is encountered during shutdown.
*/
- public void shutdown() throws Exception
+ void shutdown() throws Exception
{
_server.stop();
}
+
+ /**
+ * Returns the port number where the server is running.
+ *
+ * @return the port number where the server is running.
+ */
+ int getPort()
+ {
+ return _connector.getLocalPort();
+ }
+
}
diff --git a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
index 1e0bc4c131..a181a8652f 100644
--- a/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
+++ b/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
@@ -20,9 +20,11 @@
*/
package org.apache.qpid.management.wsdm;
+import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
+import java.net.ServerSocket;
import java.net.URI;
import java.util.Arrays;
import java.util.Date;
@@ -76,6 +78,8 @@ public class WsDmAdapterTest extends TestCase {
private Map<String, ProxyHandler> _invocationHandlers = createInvocationHandlers();
final Long retCodeOk = new Long(0);
+ private static ServerThread _server;
+
/**
* Test case wide set up.
* Provides Server startup & shutdown global procedure.
@@ -97,7 +101,6 @@ public class WsDmAdapterTest extends TestCase {
}
};
- private ServerThread server;
/**
* Builds a new test setup with for the given test.
@@ -125,15 +128,15 @@ public class WsDmAdapterTest extends TestCase {
SerializerRegistry.getInstance().registerSerializer(Result.class, new InvocationResultSerializer());
System.setProperty(
- Names.ADAPTER_PORT_PROPERTY_NAME,
- String.valueOf(Protocol.DEFAULT_QMAN_PORT_NUMBER));
-
- System.setProperty(
Names.ADAPTER_HOST_PROPERTY_NAME,
Protocol.DEFAULT_QMAN_HOSTNAME);
+
+ System.setProperty(
+ Names.ADAPTER_PORT_PROPERTY_NAME,
+ String.valueOf(getFreePort()));
- server = new ServerThread(listener);
- server.start();
+ _server = new ServerThread(listener);
+ _server.start();
synchronized(_serverMonitor) {
_serverMonitor.wait();
@@ -143,7 +146,7 @@ public class WsDmAdapterTest extends TestCase {
@Override
protected void tearDown() throws Exception
{
- server.shutdown();
+ _server.shutdown();
}
};
@@ -212,7 +215,7 @@ public class WsDmAdapterTest extends TestCase {
* <br>precondition : a ws resource exists and is registered.
* <br>postcondition : property values coming from WS-DM resource are the same of the JMX interface.
*/
- public void testGeResourcePropertiesOK() throws Exception
+ public void testGetResourcePropertiesOK() throws Exception
{
MBeanAttributeInfo [] attributesMetadata = _mbeanInfo.getAttributes();
for (MBeanAttributeInfo attributeMetadata : attributesMetadata)
@@ -787,7 +790,9 @@ public class WsDmAdapterTest extends TestCase {
*/
private ServiceGroupClient getServiceGroupClient()
{
- URI address = URI.create(Protocol.DEFAULT_ENDPOINT_URI);
+ URI address = URI.create(
+ Protocol.DEFAULT_ENDPOINT_URI.replaceFirst("8080",System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME)));
+ System.out.println(address);
return new ServiceGroupClient(new EndpointReference(address));
}
@@ -1018,4 +1023,16 @@ public class WsDmAdapterTest extends TestCase {
assertEquals(expected,result);
}
}
+
+ public static int getFreePort() throws IOException {
+ ServerSocket server = null;
+ try
+ {
+ server = new ServerSocket(0);
+ return server.getLocalPort();
+ } finally
+ {
+ server.close();
+ }
+ }
} \ No newline at end of file