qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agazzar...@apache.org
Subject svn commit: r744850 - in /qpid/trunk/qpid/java/management/client: build.xml src/test/java/org/apache/qpid/management/wsdm/ServerThread.java src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
Date Mon, 16 Feb 2009 08:08:57 GMT
Author: agazzarini
Date: Mon Feb 16 08:08:56 2009
New Revision: 744850

URL: http://svn.apache.org/viewvc?rev=744850&view=rev
Log:
QPID-1663 : WsDmAdapterTest fix. A preliminary search is made in order to find an available
port for embedded Web Server.

Modified:
    qpid/trunk/qpid/java/management/client/build.xml
    qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
    qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java

Modified: qpid/trunk/qpid/java/management/client/build.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/build.xml?rev=744850&r1=744849&r2=744850&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/build.xml (original)
+++ qpid/trunk/qpid/java/management/client/build.xml Mon Feb 16 08:08:56 2009
@@ -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"/>
 

Modified: qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java?rev=744850&r1=744849&r2=744850&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
(original)
+++ qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/ServerThread.java
Mon Feb 16 08:08:56 2009
@@ -37,11 +37,13 @@
  * 
  * @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 @@
 			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 @@
             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 @@
 	 * 
 	 * @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();
+	}
+	
 }

Modified: qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java?rev=744850&r1=744849&r2=744850&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
(original)
+++ qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/wsdm/WsDmAdapterTest.java
Mon Feb 16 08:08:56 2009
@@ -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 @@
 	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 @@
 			}
 		};
 		
-		private ServerThread server;
 		
 		/**
 		 * Builds a new test setup with for the given test.
@@ -125,15 +128,15 @@
 			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 @@
 		@Override
 		protected void tearDown() throws Exception
 		{
-			server.shutdown();
+			_server.shutdown();
 		}
 	};
 	
@@ -212,7 +215,7 @@
 	 * <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 @@
 	 */
 	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 @@
 			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



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message