jochen      2005/04/11 07:31:31

  Modified:    src/test/org/apache/xmlrpc ClientServerRpcTest.java
                        LocalServerRpcTest.java
               src/java/org/apache/xmlrpc WebServer.java
  Log:
  The test suite is running on a random port now. It used to use port 8080, 
which caused problems, if the port was reused too fast, or if that port was 
blocked by another server.
  
  Revision  Changes    Path
  1.17      +26 -26    
ws-xmlrpc/src/test/org/apache/xmlrpc/ClientServerRpcTest.java
  
  Index: ClientServerRpcTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/test/org/apache/xmlrpc/ClientServerRpcTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ClientServerRpcTest.java  17 Jun 2004 01:40:14 -0000      1.16
  +++ ClientServerRpcTest.java  11 Apr 2005 14:31:31 -0000      1.17
  @@ -123,18 +123,6 @@
           server = new XmlRpcServer();
           server.addHandler(HANDLER_NAME, new TestHandler());
   
  -        InetAddress localhost = null;
  -        try
  -        {
  -            // localhost will be a random network interface on a
  -            // multi-homed host.
  -            localhost = InetAddress.getLocalHost();
  -        }
  -        catch (UnknownHostException e)
  -        {
  -            fail(e.toString());
  -        }
  -
           // Setup system handler
           SystemHandler webServerSysHandler = new SystemHandler();
           webServerSysHandler.addSystemHandler("multicall", new MultiCall());
  @@ -142,19 +130,6 @@
           // WebServer (contains its own XmlRpcServer instance)
           setUpWebServer();
           webServer.addHandler("system", webServerSysHandler);
  -
  -        // XML-RPC client(s)
  -        try
  -        {
  -            String hostName = localhost.getHostName();
  -            client = new XmlRpcClient(hostName, SERVER_PORT);
  -            //liteClient = new XmlRpcClientLite(hostName, SERVER_PORT);
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            fail(e.toString());
  -        }
       }
   
       /**
  @@ -179,6 +154,31 @@
               e.printStackTrace();
               fail(e.toString());
           }
  +
  +        InetAddress localhost = null;
  +        try
  +        {
  +            // localhost will be a random network interface on a
  +            // multi-homed host.
  +            localhost = InetAddress.getLocalHost();
  +        }
  +        catch (UnknownHostException e)
  +        {
  +            fail(e.toString());
  +        }
  +
  +             // XML-RPC client(s)
  +        try
  +        {
  +            String hostName = localhost.getHostName();
  +            client = new XmlRpcClient(hostName, SERVER_PORT);
  +            //liteClient = new XmlRpcClientLite(hostName, SERVER_PORT);
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            fail(e.toString());
  +        }
       }
      
       /**
  
  
  
  1.2       +5 -14     
ws-xmlrpc/src/test/org/apache/xmlrpc/LocalServerRpcTest.java
  
  Index: LocalServerRpcTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-xmlrpc/src/test/org/apache/xmlrpc/LocalServerRpcTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalServerRpcTest.java   26 Jan 2003 02:31:08 -0000      1.1
  +++ LocalServerRpcTest.java   11 Apr 2005 14:31:31 -0000      1.2
  @@ -78,7 +78,7 @@
        */
       protected static final String REQUEST_PARAM_VALUE = "foobar";
   
  -    protected static final int SERVER_PORT;
  +     protected static int SERVER_PORT;
   
       /**
        * The value to use in our request parameter.
  @@ -100,16 +100,6 @@
           super(message);
       }
       
  -    /**
  -     * Static constructor
  -     * - initializes test port
  -     * 
  -     * TODO: can we initialize this from a properties file?
  -     */
  -    static {
  -        SERVER_PORT = 8081;
  -    }
  -
       protected WebServer webServer;
   
       /**
  @@ -117,7 +107,7 @@
        *
        * @param port Port to use for the WebServer
        */
  -    private void setUpWebServer(int port) {
  +     private void setUpWebServer(int port) {
           webServer = new WebServer(port);
           webServer.addHandler(HANDLER_NAME, new TestHandler());
       }
  @@ -126,7 +116,7 @@
        * Sets up the @link WebServer with the default port.
        */
       protected void setUpWebServer() {
  -        setUpWebServer(SERVER_PORT);
  +             setUpWebServer(SERVER_PORT);
       }
   
       /**
  @@ -134,6 +124,7 @@
        */
       protected void startWebServer() {
           webServer.start();
  +             SERVER_PORT = webServer.serverSocket.getLocalPort();
       }
       
       /**
  
  
  
  1.27      +11 -11    ws-xmlrpc/src/java/org/apache/xmlrpc/WebServer.java
  
  Index: WebServer.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/WebServer.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- WebServer.java    17 Jun 2004 01:49:10 -0000      1.26
  +++ WebServer.java    11 Apr 2005 14:31:31 -0000      1.27
  @@ -304,6 +304,17 @@
        */
       public void start()
       {
  +        try
  +        {
  +            setupServerSocket(50);
  +        }
  +        catch (Exception e)
  +        {
  +            listener = null;
  +            e.printStackTrace();
  +            throw new RuntimeException(e.getMessage());
  +        }
  +
           // The listener reference is released upon shutdown().
           if (listener == null)
           {
  @@ -470,17 +481,6 @@
       {
           try
           {
  -            setupServerSocket(50);
  -        }
  -        catch (Exception e)
  -        {
  -            listener = null;
  -            e.printStackTrace();
  -            throw new RuntimeException(e.getMessage());
  -        }
  -
  -        try
  -        {
               while (listener != null)
               {
                   try
  
  
  

Reply via email to