From fd13361132a8e908597eab959e526b8f5a3a1aa1 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 9 Jan 2015 12:58:14 +0100 Subject: [PATCH] Fixed test assumption. --- .../jetty/client/ExternalSiteTest.java | 49 ++++++------------- .../jetty/proxy/ProxyTunnellingTest.java | 2 +- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java index 012f80ce193..51abf8ffe80 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.client; -import java.io.IOException; import java.net.Socket; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -63,14 +62,7 @@ public class ExternalSiteTest int port = 80; // Verify that we have connectivity - try - { - new Socket(host, port).close(); - } - catch (IOException x) - { - Assume.assumeNoException(x); - } + assumeCanConnectTo(host, port); final CountDownLatch latch1 = new CountDownLatch(1); client.newRequest(host, port).send(new Response.CompleteListener() @@ -110,14 +102,7 @@ public class ExternalSiteTest int port = 443; // Verify that we have connectivity - try - { - new Socket(host, port).close(); - } - catch (IOException x) - { - Assume.assumeNoException(x); - } + assumeCanConnectTo(host, port); final CountDownLatch latch = new CountDownLatch(1); client.newRequest(host, port).scheme("https").path("/nvp").send(new Response.CompleteListener() @@ -139,14 +124,7 @@ public class ExternalSiteTest int port = 22; // SSH port // Verify that we have connectivity - try - { - new Socket(host, port).close(); - } - catch (IOException x) - { - Assume.assumeNoException(x); - } + assumeCanConnectTo(host, port); for (int i = 0; i < 2; ++i) { @@ -186,14 +164,7 @@ public class ExternalSiteTest int port = 443; // Verify that we have connectivity - try - { - new Socket(host, port).close(); - } - catch (IOException x) - { - Assume.assumeNoException(x); - } + assumeCanConnectTo(host, port); ContentResponse response = client.newRequest(host, port) .scheme(HttpScheme.HTTPS.asString()) @@ -201,4 +172,16 @@ public class ExternalSiteTest .send(); Assert.assertEquals(200, response.getStatus()); } + + protected void assumeCanConnectTo(String host, int port) + { + try + { + new Socket(host, port).close(); + } + catch (Throwable x) + { + Assume.assumeNoException(x); + } + } } diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java index dd89a0715b1..a747a0a0025 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java @@ -386,7 +386,7 @@ public class ProxyTunnellingTest { new Socket(proxyHost, proxyPort).close(); } - catch (IOException x) + catch (Throwable x) { Assume.assumeNoException(x); }