aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 03:11:17 (EST)
committerWinston Prakash2011-12-01 20:47:06 (EST)
commit697f7b31b8aed1f91dabbb4840ac87ed44ec4613 (patch)
tree7f7e30e88d983f0069d2094053832ff5ed4fffa2
parent855eeb6d786fbc5e26301bd1ce61f462eadf5fec (diff)
downloadorg.eclipse.hudson.core-697f7b31b8aed1f91dabbb4840ac87ed44ec4613.zip
org.eclipse.hudson.core-697f7b31b8aed1f91dabbb4840ac87ed44ec4613.tar.gz
org.eclipse.hudson.core-697f7b31b8aed1f91dabbb4840ac87ed44ec4613.tar.bz2
Add connection timeout for UpdateCenter. Skip test if host is unreachable
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/test/java/hudson/model/UpdateCenterTest.java29
1 files changed, 21 insertions, 8 deletions
diff --git a/hudson-core/src/test/java/hudson/model/UpdateCenterTest.java b/hudson-core/src/test/java/hudson/model/UpdateCenterTest.java
index f6c9a9d..27d5774 100644
--- a/hudson-core/src/test/java/hudson/model/UpdateCenterTest.java
+++ b/hudson-core/src/test/java/hudson/model/UpdateCenterTest.java
@@ -1,6 +1,6 @@
/*******************************************************************************
*
- * Copyright (c) 2004-2009 Oracle Corporation.
+ * Copyright (c) 2004-2011 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,30 +9,43 @@
*
* Contributors:
*
-* Kohsuke Kawaguchi
+* Kohsuke Kawaguchi, Nikita Levyankov
*
*
*******************************************************************************/
package hudson.model;
-import junit.framework.TestCase;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
+import org.junit.Test;
-import java.io.IOException;
-import java.net.URL;
+import static junit.framework.Assert.assertTrue;
/**
* Quick test for {@link UpdateCenter}.
- *
+ *
* @author Kohsuke Kawaguchi
*/
-public class UpdateCenterTest extends TestCase {
+public class UpdateCenterTest {
+
+ @Test
public void testData() throws IOException {
// check if we have the internet connectivity. See HUDSON-2095
try {
- new URL("http://hudson-ci.org/").openStream();
+ HttpURLConnection con = (HttpURLConnection) new URL("http://hudson-ci.org/").openConnection();
+ con.setRequestMethod("HEAD");
+ con.setConnectTimeout(10000); //set timeout to 10 seconds
+ if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {
+ System.out.println("Skipping this test. Page doesn't exists");
+ return;
+ }
+ } catch (java.net.SocketTimeoutException e) {
+ System.out.println("Skipping this test. Timeout exception");
+ return;
} catch (IOException e) {
System.out.println("Skipping this test. No internet connectivity");
return;