aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 03:11:17 (EST)
committerWinston Prakash2011-12-01 20:47:06 (EST)
commitcf5b0cf1c0dde47c1e1af520a253f98d97dff809 (patch)
tree59db9d7f71e615876f64f0fbbbce6c322409639a
parent02fa9541031c439b2108727747a284b76e148b38 (diff)
downloadorg.eclipse.hudson.core-cf5b0cf1c0dde47c1e1af520a253f98d97dff809.zip
org.eclipse.hudson.core-cf5b0cf1c0dde47c1e1af520a253f98d97dff809.tar.gz
org.eclipse.hudson.core-cf5b0cf1c0dde47c1e1af520a253f98d97dff809.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;