From a5c2dad41a7fc34990e152df50d96ca1300c4558 Mon Sep 17 00:00:00 2001 From: Nicolas Henneaux Date: Tue, 9 Jan 2024 19:52:29 +0100 Subject: [PATCH] Update test dependencies to latest Daily build upgrade slf4j to 2.0.11 --- .github/workflows/main.yml | 6 ++- pom.xml | 8 +-- .../connector/httpclient/JettyServer.java | 9 ++-- .../connector/httpclient/JettyServerTest.java | 54 +++++++++++++++---- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b14fa5..c90af75 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,10 @@ name: Java CI -on: [ push ] +on: + push: + schedule: + - cron: '0 5 */1 * *' + jobs: build: diff --git a/pom.xml b/pom.xml index e8e3730..866328f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.nhenneaux.jersey.connector.httpclient jersey-httpclient-connector - 1.1.13 + 1.1.14 Jersey Connector using java.net.http.HttpClient A Jersey connector using java.net.http.HttpClient and supporting HTTP/1.1 and HTTP/2.0 with the same @@ -25,9 +25,9 @@ https://sonarcloud.io 3.1.3 - 11.0.17 + 11.0.19 5.1.2.Final - 2.20.0 + 2.22.1 @@ -111,7 +111,7 @@ org.slf4j slf4j-api - 2.0.9 + 2.0.11 test diff --git a/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServer.java b/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServer.java index 7dea420..bd300f2 100644 --- a/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServer.java +++ b/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServer.java @@ -10,6 +10,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.MultiException; @@ -45,13 +46,15 @@ public class JettyServer implements AutoCloseable { JettyServer(int port, TlsSecurityConfiguration tlsSecurityConfiguration, Class... serviceClasses) { this.server = new Server(); + var contexts = new ContextHandlerCollection(); + server.setHandler(contexts); ServerConnector http2Connector = new ServerConnector(server, getConnectionFactories(tlsSecurityConfiguration)); http2Connector.setPort(port); server.addConnector(http2Connector); - ServletContextHandler context = new ServletContextHandler(server, "/"); - + ServletContextHandler context = new ServletContextHandler(server,"/"); + contexts.addHandler(context); final ResourceConfig resourceConfig = new ResourceConfig(); for (Class serviceClass : serviceClasses) { resourceConfig.register(serviceClass); @@ -70,7 +73,7 @@ public class JettyServer implements AutoCloseable { MultiException multiException = new MultiException(); multiException.add(e); multiException.add(closeException); - throw new IllegalStateException(multiException); + multiException.ifExceptionThrowRuntime(); } throw new IllegalStateException(e); } diff --git a/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServerTest.java b/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServerTest.java index 571b161..8530b98 100644 --- a/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServerTest.java +++ b/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServerTest.java @@ -11,14 +11,18 @@ import jakarta.ws.rs.core.Response; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; +import org.hamcrest.Matchers; +import org.jboss.weld.environment.se.Weld; +import org.jboss.weld.environment.se.WeldContainer; +import org.junit.jupiter.api.*; import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; import java.net.http.HttpClient; import java.security.KeyStore; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -27,6 +31,7 @@ import java.util.stream.IntStream; import static com.github.nhenneaux.jersey.connector.httpclient.JettyServer.TlsSecurityConfiguration.getKeyStore; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -35,6 +40,20 @@ class JettyServerTest { static final int PORT = 2223; private static final String PING = "/ping"; + @BeforeEach + void setUp(TestInfo testInfo) { + var testClass = testInfo.getTestClass().orElseThrow(); + var testMethod = testInfo.getTestMethod().orElseThrow(); + System.out.println(testClass.getSimpleName() + "::" + testMethod.getName() + " test has started."); + } + + @AfterEach + void tearDown(TestInfo testInfo) { + var testClass = testInfo.getTestClass().orElseThrow(); + var testMethod = testInfo.getTestMethod().orElseThrow(); + System.out.println(testClass.getSimpleName() + "::" + testMethod.getName() + " test has finished."); + } + private static WebTarget getClient(int port, KeyStore trustStore, ClientConfig clientConfig) { return ClientBuilder.newBuilder() .trustStore(trustStore) @@ -345,7 +364,7 @@ void testConcurrent() throws Exception { } @Test - @Timeout(60) + @Timeout(120) void testConcurrentHttp1() throws Exception { testConcurrent(new ClientConfig()); } @@ -395,14 +414,14 @@ private void testConcurrent(ClientConfig clientConfig, String method, String pat .trustStore(truststore) .withConfig(clientConfig) .build(); - client.target("https://localhost:" + port).path(path).request().method(method).close(); + final var webTarget = client.target("https://localhost:" + port).path(path); + webTarget.request().method(method).close(); AtomicInteger counter = new AtomicInteger(); final Runnable runnable = () -> { long start = System.nanoTime(); for (int i = 0; i < iterations; i++) { - try (Response response = client - .target("https://localhost:" + port).path(path).request().method(method)) { + try (Response response = webTarget.request().method(method)) { response.readEntity(InputStream.class).readAllBytes(); response.getStatus(); counter.incrementAndGet(); @@ -411,12 +430,23 @@ private void testConcurrent(ClientConfig clientConfig, String method, String pat System.out.println(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) * 1.0 / reportEveryRequests); start = System.nanoTime(); } - } catch (IOException e) { + } catch (ProcessingException | IOException e) { + if (e.getMessage().contains("GOAWAY") + || e.getMessage().contains("Broken pipe") // The HTTP sending process failed with error, Broken pipe + || e.getMessage().contains("EOF reached while reading") + || e.getMessage().contains(" cancelled")) {// The HTTP sending process failed with error, Stream 673 cancelled + i--; + } else { throw new IllegalStateException(e); } } + } }; - Thread.setDefaultUncaughtExceptionHandler((t1, e) -> e.printStackTrace()); + List thrown = new ArrayList<>(); + Thread.setDefaultUncaughtExceptionHandler((t1, e) -> { + thrown.add(e); + e.printStackTrace(); + }); final Set threads = IntStream .range(0, nThreads) .mapToObj(i -> runnable) @@ -429,7 +459,7 @@ private void testConcurrent(ClientConfig clientConfig, String method, String pat for (Thread thread : threads) { thread.join(); } - + assertThat(thrown, Matchers.empty()); assertEquals((long) nThreads * iterations, counter.get()); } @@ -441,8 +471,10 @@ void shouldWorkInLoop() throws Exception { int port = PORT; JettyServer.TlsSecurityConfiguration tlsSecurityConfiguration = tlsConfig(); for (int i = 0; i < 100; i++) { - try (var ignored = jerseyServer(port, tlsSecurityConfiguration, DummyRestService.class); - var head = getClient(port).path(PING).request().head()) { + try ( + var ignored = jerseyServer(port, tlsSecurityConfiguration, DummyRestService.class); + final var head = getClient(port).path(PING).request().head() + ) { assertEquals(204, head.getStatus()); } }