integration-test: retry on ECONNREFUSED 88/60388/1
authorIsaku Yamahata <isaku.yamahata@intel.com>
Fri, 14 Jul 2017 16:16:05 +0000 (09:16 -0700)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Fri, 14 Jul 2017 16:17:57 +0000 (09:17 -0700)
If ECONNREFUSED, retry again instead of test failure.

Change-Id: Ib5d14e17f2d4a78f6c3ea230f70c8e82222099e2
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronNetworkTests.java

index 292d2a36115d22a3533927d6d6fbf42878e00573..7175f50133b83ef86ad4c93fe4ba0010da0028de 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.neutron.e2etest;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import java.io.IOException;
+import java.net.ConnectException;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import org.junit.Assert;
@@ -34,7 +35,16 @@ public class NeutronNetworkTests {
         for (int retry = 0; retry < TIMEOUT; retry++) {
             URL url = new URL(urlS);
             HttpURLConnection httpConn = ITNeutronE2E.httpURLConnectionFactoryGet(url);
-            if (httpConn.getResponseCode() != 200) {
+            int responseCode;
+            try {
+                responseCode = httpConn.getResponseCode();
+            } catch (ConnectException e) {
+                LOG.info("connection " + Integer.toString(retry) + ": failed", e);
+                Thread.sleep(1000);
+                continue;
+            }
+
+            if (responseCode != 200) {
                 LOG.info("trial " + Integer.toString(retry) + ": failed with: "
                         + Integer.toString(httpConn.getResponseCode()));
                 Thread.sleep(1000);