Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.

This commit is contained in:
Simone Bordet 2019-04-16 11:50:01 +02:00
commit 8e48f516c4
3 changed files with 53 additions and 21 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.alpn.java.client;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.Security;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -39,6 +40,7 @@ import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -50,6 +52,11 @@ public class ConscryptHTTP2ClientTest
@Test
public void testConscryptHTTP2Client() throws Exception
{
String host = "webtide.com";
int port = 443;
Assumptions.assumeTrue(canConnectTo(host, port));
Security.insertProviderAt(new OpenSSLProvider(), 1);
SslContextFactory sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setProvider("Conscrypt");
@ -61,9 +68,6 @@ public class ConscryptHTTP2ClientTest
client.addBean(sslContextFactory);
client.start();
String host = "webtide.com";
int port = 443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(5, TimeUnit.SECONDS);
@ -93,11 +97,24 @@ public class ConscryptHTTP2ClientTest
}
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
finally
{
client.stop();
}
}
private boolean canConnectTo(String host, int port)
{
try
{
new Socket(host, port).close();
return true;
}
catch (Throwable x)
{
return false;
}
}
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.alpn.java.client;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -36,6 +37,7 @@ import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -45,17 +47,18 @@ public class JDK9HTTP2ClientTest
@Test
public void testJDK9HTTP2Client() throws Exception
{
SslContextFactory sslContextFactory = new SslContextFactory.Client();
String host = "webtide.com";
int port = 443;
Assumptions.assumeTrue(canConnectTo(host, port));
HTTP2Client client = new HTTP2Client();
try
{
SslContextFactory sslContextFactory = new SslContextFactory.Client();
client.addBean(sslContextFactory);
client.start();
String host = "webtide.com";
int port = 443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(5, TimeUnit.SECONDS);
@ -85,11 +88,24 @@ public class JDK9HTTP2ClientTest
}
});
latch.await(5, TimeUnit.SECONDS);
latch.await(15, TimeUnit.SECONDS);
}
finally
{
client.stop();
}
}
private boolean canConnectTo(String host, int port)
{
try
{
new Socket(host, port).close();
return true;
}
catch (Throwable x)
{
return false;
}
}
}

View File

@ -67,10 +67,11 @@ public class ExternalSiteTest
final CountDownLatch latch1 = new CountDownLatch(1);
client.newRequest(host, port).send(result ->
{
if (!result.isFailed() && result.getResponse().getStatus() == 200)
latch1.countDown();
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch1.countDown();
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertTrue(latch1.await(15, TimeUnit.SECONDS));
// Try again the same URI, but without specifying the port
final CountDownLatch latch2 = new CountDownLatch(1);
@ -80,17 +81,13 @@ public class ExternalSiteTest
assertEquals(200, result.getResponse().getStatus());
latch2.countDown();
});
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertTrue(latch2.await(15, TimeUnit.SECONDS));
}
@Tag("external")
@Test
public void testExternalSSLSite() throws Exception
{
client.stop();
client = new HttpClient();
client.start();
String host = "api-3t.paypal.com";
int port = 443;
@ -100,10 +97,11 @@ public class ExternalSiteTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest(host, port).scheme("https").path("/nvp").send(result ->
{
if (result.isSucceeded() && result.getResponse().getStatus() == 200)
latch.countDown();
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch.countDown();
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
@Tag("external")
@ -136,7 +134,7 @@ public class ExternalSiteTest
latch.countDown();
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
}
@ -153,6 +151,7 @@ public class ExternalSiteTest
ContentResponse response = client.newRequest(host, port)
.scheme(HttpScheme.HTTPS.asString())
.path("/twitter")
.timeout(15, TimeUnit.SECONDS)
.send();
assertEquals(200, response.getStatus());
}