Author: ivol37 at gmail.com
Date: Wed Dec  1 09:19:29 2010
New Revision: 459

Log:
[AMDATU-189] Improved error logging to identify problem on Bamboo

Modified:
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
  (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
  Wed Dec  1 09:19:29 2010
@@ -133,7 +133,7 @@
         properties.put("org.apache.felix.log.storeDebug", "true");
         config.update(properties);
     }
-    
+
     public void addUserAdminConfig(ConfigurationAdmin configAdmin) throws 
IOException {
         Configuration config = 
configAdmin.getConfiguration("org.amdatu.core.useradminstore-fs", null);
         Properties properties = new Properties();
@@ -143,30 +143,38 @@
 
     /**
      * Wait until the service at the specified URL returns the specified 
response code with a timeout as specified.
+     * 
+     * @throws IOException
      */
-    public static boolean waitForURL(URL url, int responseCode, int timeout) {
+    public static boolean waitForURL(URL url, int responseCode, int timeout) 
throws IOException {
         long deadline = System.currentTimeMillis() + timeout;
         while (System.currentTimeMillis() < deadline) {
             try {
-                HttpURLConnection connection = (HttpURLConnection) 
url.openConnection();
-                connection.connect();
-                if (connection.getResponseCode() == responseCode) {
+                if (checkURL(url) == responseCode) {
                     return true;
                 }
-            }
-            catch (ClassCastException cce) {
-                throw new IllegalArgumentException("Expected url to be an HTTP 
url, not: " + url.toString(), cce);
-            }
-            catch (IOException ioe) {
-                // retry
-            }
-            try {
                 Thread.sleep(100);
             }
-            catch (InterruptedException ie) {
-                return false;
-            }
+            catch (InterruptedException ie) {}
+            catch (IOException e) {}
         }
         return false;
     }
+
+    /**
+     * Invokes a URL and returns the response code.
+     * 
+     * @throws IOException
+     */
+    public static int checkURL(URL url) throws IOException {
+        HttpURLConnection connection = (HttpURLConnection) 
url.openConnection();
+        int responseCode;
+        try {
+            connection.connect();
+            responseCode = connection.getResponseCode();
+        } finally {
+            connection.disconnect();
+        }
+        return responseCode;
+    }
 }

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
        (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
        Wed Dec  1 09:19:29 2010
@@ -160,7 +160,7 @@
        // Wait until the test servlet is available, for a maximum of 5 seconds
        String url = m_baseUrl + SERVLET_ALIAS;
         if (!ConfigProvider.waitForURL(new URL(url), HttpStatus.SC_OK, 5000)) {
-            throw new IllegalArgumentException("URL " + url + " is 
unreachable");
+            throw new IllegalArgumentException("URL " + url + " returns 
response code " + ConfigProvider.checkURL(new URL(url)));
         }
 
        // Wait for two seconds such that the Felix whiteboard service has the 
time to receive the filter added
@@ -209,7 +209,7 @@
         // Wait until the JSP servlet is available, for a maximum of 5 seconds
        String url = m_baseUrl + "/" + RESOURCE_ID + "/jsp/test.jsp";
         if (!ConfigProvider.waitForURL(new URL(url), HttpStatus.SC_OK, 5000)) {
-            throw new IllegalArgumentException("URL " + url + " is 
unreachable");
+            throw new IllegalArgumentException("URL " + url + " returns 
response code " + ConfigProvider.checkURL(new URL(url)));
         }
         
        // Wait for two seconds such that the Felix whiteboard service has the 
time to receive the filter added

Reply via email to