Skip to content

Commit

Permalink
Update test dependencies to latest
Browse files Browse the repository at this point in the history
Daily build
upgrade slf4j to 2.0.11
  • Loading branch information
nhenneaux committed Jan 9, 2024
1 parent 6673c9a commit a5c2dad
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Java CI

on: [ push ]
on:
push:
schedule:
- cron: '0 5 */1 * *'


jobs:
build:
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.nhenneaux.jersey.connector.httpclient</groupId>
<artifactId>jersey-httpclient-connector</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>

<name>Jersey Connector using java.net.http.HttpClient</name>
<description>A Jersey connector using java.net.http.HttpClient and supporting HTTP/1.1 and HTTP/2.0 with the same
Expand All @@ -25,9 +25,9 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<jersey.version>3.1.3</jersey.version>
<jetty.version>11.0.17</jetty.version>
<jetty.version>11.0.19</jetty.version>
<weld-se-core.version>5.1.2.Final</weld-se-core.version>
<log4j.version>2.20.0</log4j.version>
<log4j.version>2.22.1</log4j.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -111,7 +111,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
<version>2.0.11</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -345,7 +364,7 @@ void testConcurrent() throws Exception {
}

@Test
@Timeout(60)
@Timeout(120)
void testConcurrentHttp1() throws Exception {
testConcurrent(new ClientConfig());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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<Throwable> thrown = new ArrayList<>();
Thread.setDefaultUncaughtExceptionHandler((t1, e) -> {
thrown.add(e);
e.printStackTrace();
});
final Set<Thread> threads = IntStream
.range(0, nThreads)
.mapToObj(i -> runnable)
Expand All @@ -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());

}
Expand All @@ -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());
}
}
Expand Down

0 comments on commit a5c2dad

Please sign in to comment.