diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo')
4 files changed, 83 insertions, 70 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java b/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java index 75bc0c915d3..66b3da06ff2 100644 --- a/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java +++ b/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java @@ -26,6 +26,7 @@ class JsonConnectionLogWriterTest { List.of( new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("javax.net.ssl.SSLHandshakeException", "message"), new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("java.io.IOException", "cause message")))) + .withSslSubjectAlternativeNames(List.of("sandns", "sanemail")) .build(); String expectedJson = "{" + "\"id\":\""+id.toString()+"\"," + @@ -34,7 +35,7 @@ class JsonConnectionLogWriterTest { "\"ssl\":{\"handshake-failure\":{\"exception\":[" + "{\"cause\":\"javax.net.ssl.SSLHandshakeException\",\"message\":\"message\"}," + "{\"cause\":\"java.io.IOException\",\"message\":\"cause message\"}" + - "],\"type\":\"UNKNOWN\"}}}"; + "],\"type\":\"UNKNOWN\"},\"san\":[\"sandns\",\"sanemail\"]}}"; JsonConnectionLogWriter writer = new JsonConnectionLogWriter(); ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java index 93261a2401f..bb736122867 100644 --- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java @@ -8,6 +8,8 @@ import com.yahoo.jdisc.http.ssl.impl.ConfiguredSslContextFactoryProvider; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import javax.servlet.http.HttpServletRequest; @@ -16,46 +18,73 @@ import java.io.IOException; import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; /** * @author Einar M R Rosenvinge + * @author bjorncs */ public class ConnectorFactoryTest { - @Test - public void requireThatServerCanBindChannel() throws Exception { - Server server = new Server(); + private Server server; + + @Before + public void createServer() { + server = new Server(); + } + + @After + public void stopServer() { try { - ConnectorConfig config = new ConnectorConfig(new ConnectorConfig.Builder()); - ConnectorFactory factory = createConnectorFactory(config); - JettyConnectionLogger connectionLogger = new JettyConnectionLogger( - new ServerConfig.ConnectionLog.Builder().enabled(false).build(), - new VoidConnectionLog()); - DummyMetric metric = new DummyMetric(); - var connectionMetricAggregator = new ConnectionMetricAggregator(new ServerConfig(new ServerConfig.Builder()), metric); - JDiscServerConnector connector = - (JDiscServerConnector)factory.createConnector(metric, server, connectionLogger, connectionMetricAggregator); - server.addConnector(connector); - server.setHandler(new HelloWorldHandler()); - server.start(); - - SimpleHttpClient client = new SimpleHttpClient(null, connector.getLocalPort(), false); - SimpleHttpClient.RequestExecutor ex = client.newGet("/blaasdfnb"); - SimpleHttpClient.ResponseValidator val = ex.execute(); - val.expectContent(equalTo("Hello world")); - } finally { - try { - server.stop(); - } catch (Exception e) { - //ignore - } + server.stop(); + server = null; + } catch (Exception e) { + //ignore } } + @Test + public void requireThatServerCanBindChannel() throws Exception { + ConnectorConfig config = new ConnectorConfig(new ConnectorConfig.Builder()); + ConnectorFactory factory = createConnectorFactory(config); + JDiscServerConnector connector = createConnectorFromFactory(factory); + server.addConnector(connector); + server.setHandler(new HelloWorldHandler()); + server.start(); + + SimpleHttpClient client = new SimpleHttpClient(null, connector.getLocalPort(), false); + SimpleHttpClient.RequestExecutor ex = client.newGet("/blaasdfnb"); + SimpleHttpClient.ResponseValidator val = ex.execute(); + val.expectContent(equalTo("Hello world")); + } + + @Test + public void constructed_connector_is_based_on_jdisc_connector_config() { + ConnectorConfig config = new ConnectorConfig.Builder() + .idleTimeout(25) + .name("my-server-name") + .listenPort(12345) + .build(); + ConnectorFactory factory = createConnectorFactory(config); + JDiscServerConnector connector = createConnectorFromFactory(factory); + assertEquals(25000, connector.getIdleTimeout()); + assertEquals(12345, connector.listenPort()); + assertEquals("my-server-name", connector.getName()); + } + private static ConnectorFactory createConnectorFactory(ConnectorConfig config) { return new ConnectorFactory(config, new ConfiguredSslContextFactoryProvider(config)); } + private JDiscServerConnector createConnectorFromFactory(ConnectorFactory factory) { + JettyConnectionLogger connectionLogger = new JettyConnectionLogger( + new ServerConfig.ConnectionLog.Builder().enabled(false).build(), + new VoidConnectionLog()); + DummyMetric metric = new DummyMetric(); + var connectionMetricAggregator = new ConnectionMetricAggregator(new ServerConfig(new ServerConfig.Builder()), metric); + return (JDiscServerConnector)factory.createConnector(metric, server, connectionLogger, connectionMetricAggregator); + } + private static class HelloWorldHandler extends AbstractHandler { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerConformanceTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerConformanceTest.java index 2183098da2b..4c45319daf6 100644 --- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerConformanceTest.java +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerConformanceTest.java @@ -12,12 +12,11 @@ import com.yahoo.jdisc.http.server.jetty.testutils.ConnectorFactoryRegistryModul import com.yahoo.jdisc.test.ServerProviderConformanceTest; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.hamcrest.Description; @@ -27,6 +26,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -64,6 +65,8 @@ public class HttpServerConformanceTest extends ServerProviderConformanceTest { @SuppressWarnings("LoggerInitializedWithForeignClass") private static Logger httpRequestDispatchLogger = Logger.getLogger(HttpRequestDispatch.class.getName()); private static Level httpRequestDispatchLoggerOriginalLevel; + private static CloseableHttpClient httpClient; + private static ExecutorService executorService; /* * Reduce logging of every stack trace for {@link ServerProviderConformanceTest.ConformanceException} thrown. @@ -73,11 +76,16 @@ public class HttpServerConformanceTest extends ServerProviderConformanceTest { public static void reduceExcessiveLogging() { httpRequestDispatchLoggerOriginalLevel = httpRequestDispatchLogger.getLevel(); httpRequestDispatchLogger.setLevel(Level.SEVERE); + httpClient = HttpClientBuilder.create().build(); + executorService = Executors.newSingleThreadExecutor(); } @AfterClass - public static void restoreExcessiveLogging() { + public static void restoreExcessiveLogging() throws IOException, InterruptedException { httpRequestDispatchLogger.setLevel(httpRequestDispatchLoggerOriginalLevel); + httpClient.close(); + executorService.shutdownNow(); + executorService.awaitTermination(30, TimeUnit.SECONDS); } @AfterClass @@ -742,20 +750,12 @@ public class HttpServerConformanceTest extends ServerProviderConformanceTest { } } - private class TestRunner implements Adapter<JettyHttpServer, ClientProxy, Future<HttpResponse>> { + private class TestRunner implements Adapter<JettyHttpServer, Integer, Future<HttpResponse>> { private Matcher<ResponseGist> expectedResponse = null; - HttpVersion requestVersion; - private final ExecutorService executorService = Executors.newSingleThreadExecutor(); void execute() throws Throwable { - requestVersion = HttpVersion.HTTP_1_0; runTest(this); - - requestVersion = HttpVersion.HTTP_1_1; - runTest(this); - - executorService.shutdown(); } TestRunner expect(final Matcher<ResponseGist> matcher) { @@ -790,30 +790,27 @@ public class HttpServerConformanceTest extends ServerProviderConformanceTest { } @Override - public ClientProxy newClient(final JettyHttpServer server) throws Throwable { - return new ClientProxy(server.getListenPort(), requestVersion); + public Integer newClient(final JettyHttpServer server) throws Throwable { + return server.getListenPort(); } @Override public Future<HttpResponse> executeRequest( - final ClientProxy client, + final Integer listenPort, final boolean withRequestContent) throws Throwable { final HttpUriRequest request; - final URI requestUri = URI.create("http://localhost:" + client.listenPort + "/status.html"); + final URI requestUri = URI.create("http://localhost:" + listenPort + "/status.html"); if (!withRequestContent) { HttpGet httpGet = new HttpGet(requestUri); - httpGet.setProtocolVersion(client.requestVersion); + httpGet.setProtocolVersion(HttpVersion.HTTP_1_1); request = httpGet; } else { final HttpPost post = new HttpPost(requestUri); post.setEntity(new StringEntity(REQUEST_CONTENT, StandardCharsets.UTF_8)); - post.setProtocolVersion(client.requestVersion); + post.setProtocolVersion(HttpVersion.HTTP_1_1); request = post; } - log.fine(() -> "executorService:" - + " .isShutDown()=" + executorService.isShutdown() - + " .isTerminated()=" + executorService.isTerminated()); - return executorService.submit(() -> client.delegate.execute(request)); + return executorService.submit(() -> httpClient.execute(request)); } @Override @@ -831,17 +828,4 @@ public class HttpServerConformanceTest extends ServerProviderConformanceTest { assertThat(responseGist, expectedResponse); } } - - private static class ClientProxy { - - final HttpClient delegate; - final int listenPort; - final ProtocolVersion requestVersion; - - ClientProxy(final int listenPort, final HttpVersion requestVersion) { - this.delegate = HttpClientBuilder.create().build(); - this.requestVersion = requestVersion; - this.listenPort = listenPort; - } - } } diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java index 0dec711f4c0..0f625b5c3df 100644 --- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java @@ -41,6 +41,7 @@ import org.apache.hc.client5.http.entity.mime.FormBodyPart; import org.apache.hc.client5.http.entity.mime.FormBodyPartBuilder; import org.apache.hc.client5.http.entity.mime.StringBody; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder; import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; @@ -969,14 +970,12 @@ public class HttpServerTest { private static CloseableHttpAsyncClient createHttp2Client(JettyTestDriver driver) { TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create() - .setSslContext(driver.sslContext()) - .build(); - var client = HttpAsyncClientBuilder.create() - .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2) - .disableConnectionState() - .disableAutomaticRetries() - .setConnectionManager(PoolingAsyncClientConnectionManagerBuilder.create().setTlsStrategy(tlsStrategy).build()) - .build(); + .setSslContext(driver.sslContext()) + .build(); + var client = H2AsyncClientBuilder.create() + .disableAutomaticRetries() + .setTlsStrategy(tlsStrategy) + .build(); client.start(); return client; } |