Skip to content

Commit 6871d9d

Browse files
authored
Backwards merge of 3.x into 3.1
2 parents f995dde + 85e26dc commit 6871d9d

File tree

35 files changed

+1129
-29
lines changed

35 files changed

+1129
-29
lines changed

connectors/grizzly-connector/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<!--
33
4-
Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at

containers/grizzly2-http/pom.xml

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,7 +17,8 @@
1717
1818
-->
1919

20-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2122
<modelVersion>4.0.0</modelVersion>
2223

2324
<parent>
@@ -32,6 +33,14 @@
3233

3334
<description>Grizzly 2 Http Container.</description>
3435

36+
<properties>
37+
<!-- alternatives: JerseyHttpClientThread, JettyClientThread in the same package -->
38+
<client>JdkHttpClientThread</client>
39+
<clientImplPackage>org.glassfish.jersey.grizzly2.httpserver.test.tools</clientImplPackage>
40+
<clientImpl>${clientImplPackage}.${client}</clientImpl>
41+
<testMemory>-Xms160m -Xmx160m -Xss512k</testMemory>
42+
</properties>
43+
3544
<dependencies>
3645
<dependency>
3746
<groupId>jakarta.inject</groupId>
@@ -46,6 +55,40 @@
4655
<artifactId>hamcrest-library</artifactId>
4756
<scope>test</scope>
4857
</dependency>
58+
59+
<dependency>
60+
<groupId>org.glassfish.grizzly</groupId>
61+
<artifactId>grizzly-http2</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.glassfish.grizzly</groupId>
66+
<artifactId>grizzly-npn-api</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.eclipse.jetty</groupId>
72+
<artifactId>jetty-client</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.eclipse.jetty.http2</groupId>
77+
<artifactId>http2-http-client-transport</artifactId>
78+
<version>${jetty.version}</version>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.bouncycastle</groupId>
84+
<artifactId>bcprov-jdk15on</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.bouncycastle</groupId>
89+
<artifactId>bcmail-jdk15on</artifactId>
90+
<scope>test</scope>
91+
</dependency>
4992
</dependencies>
5093

5194
<build>
@@ -65,7 +108,87 @@
65108
<artifactId>maven-bundle-plugin</artifactId>
66109
<inherited>true</inherited>
67110
</plugin>
111+
112+
<plugin>
113+
<artifactId>maven-surefire-plugin</artifactId>
114+
<configuration>
115+
<!--
116+
memory settings:
117+
- to avoid unstable JVM process; fail fast, don't produce dump
118+
- memory sizes must reflect count of clients!
119+
test time:
120+
- must not affect stability of the server; if it does, the test detected a bug
121+
- 10 seconds should be enough to process thousands of requests, if there would
122+
be some leak, it should be visible
123+
client count:
124+
- each client is reusable to produce parallel requests, but each also consumes
125+
significiant amount of memory, in this case shared with the server.
126+
-->
127+
<argLine>
128+
${testMemory} -XX:+CrashOnOutOfMemoryError -XX:-HeapDumpOnOutOfMemoryError
129+
-DtestTime=10 -DclientCount=30
130+
-DclientImpl=${clientImpl}
131+
</argLine>
132+
<trimStackTrace>false</trimStackTrace>
133+
<parallel>methods</parallel>
134+
<threadCountMethods>3</threadCountMethods>
135+
</configuration>
136+
</plugin>
68137
</plugins>
69138
</build>
70139

140+
<profiles>
141+
<profile>
142+
<id>jdk11</id>
143+
<activation>
144+
<jdk>[11,)</jdk>
145+
</activation>
146+
<build>
147+
<pluginManagement>
148+
<plugins>
149+
<plugin>
150+
<artifactId>maven-compiler-plugin</artifactId>
151+
<executions>
152+
<execution>
153+
<id>default-testCompile</id>
154+
<configuration>
155+
<source>11</source>
156+
<target>11</target>
157+
</configuration>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
</plugins>
162+
</pluginManagement>
163+
</build>
164+
</profile>
165+
<profile>
166+
<id>jdk8</id>
167+
<activation>
168+
<jdk>1.8</jdk>
169+
</activation>
170+
<build>
171+
<pluginManagement>
172+
<plugins>
173+
<plugin>
174+
<artifactId>maven-compiler-plugin</artifactId>
175+
<executions>
176+
<execution>
177+
<id>default-testCompile</id>
178+
<configuration>
179+
<!--
180+
Jetty client is not compatible with JDK8, older versions need different setup
181+
JDK HTTP client is not in JDK8 at all
182+
Jersey Client doesn't support HTTP/2 (at least not directly)
183+
-->
184+
<skip>true</skip>
185+
</configuration>
186+
</execution>
187+
</executions>
188+
</plugin>
189+
</plugins>
190+
</pluginManagement>
191+
</build>
192+
</profile>
193+
</profiles>
71194
</project>

containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* Copyright (c) 2021, 2022 Payara Foundation and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package org.glassfish.jersey.grizzly2.httpserver;
17+
18+
import java.lang.reflect.Constructor;
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.List;
22+
import java.util.concurrent.atomic.AtomicInteger;
23+
import java.util.concurrent.atomic.AtomicReference;
24+
25+
import org.glassfish.jersey.grizzly2.httpserver.test.tools.ClientThread;
26+
import org.glassfish.jersey.grizzly2.httpserver.test.tools.ClientThread.ClientThreadSettings;
27+
import org.glassfish.jersey.grizzly2.httpserver.test.tools.JdkHttpClientThread;
28+
import org.glassfish.jersey.grizzly2.httpserver.test.tools.ServerManager;
29+
import org.junit.After;
30+
import org.junit.Before;
31+
import org.junit.BeforeClass;
32+
import org.junit.Rule;
33+
import org.junit.Test;
34+
import org.junit.rules.TestName;
35+
36+
import static org.junit.Assert.assertNotNull;
37+
import static org.junit.Assert.assertTrue;
38+
39+
40+
/**
41+
* Test verifying stability of the {@link GrizzlyHttpContainer} having to serve many requests
42+
* and also giving several examples of how to configure HTTP, HTTPS and HTTP/2 clients.
43+
* <p>
44+
* Created as an attempt to reproduce Grizzly's issue #2125 (GitHub)
45+
*
46+
* @author David Matejcek
47+
*/
48+
public class GrizzlyHttpServerTest {
49+
50+
private static final String CLIENT_IMPLEMENTATION = System.getProperty("clientImpl",
51+
JdkHttpClientThread.class.getCanonicalName());
52+
private static final long TIME_IN_MILLIS = Long.getLong("testTime", 10L) * 1000L;
53+
private static final int COUNT_OF_CLIENTS = Integer.getInteger("clientCount", 20);
54+
55+
private final List<ClientThread> clients = new ArrayList<>(COUNT_OF_CLIENTS);
56+
private AtomicReference<Throwable> error = new AtomicReference<>();
57+
private AtomicInteger counter;
58+
private ServerManager server;
59+
60+
@Rule
61+
public TestName testName = new TestName();
62+
63+
@BeforeClass
64+
public static void printSettings() {
65+
System.out.println("Client implementation: " + CLIENT_IMPLEMENTATION);
66+
System.out.println("Count of clients: " + COUNT_OF_CLIENTS);
67+
System.out.println("Test duration: " + TIME_IN_MILLIS / 1000 + " s");
68+
}
69+
70+
71+
@Before
72+
public void init() {
73+
this.counter = new AtomicInteger();
74+
}
75+
76+
77+
@After
78+
public void cleanup() {
79+
error = null;
80+
System.out.println(String.format("Server processed %s requests of test %s.", counter, testName.getMethodName()));
81+
if (server != null) {
82+
server.close();
83+
}
84+
}
85+
86+
87+
/**
88+
* Test for unsecured HTTP 1.1 protocol.
89+
*
90+
* @throws Throwable
91+
*/
92+
@Test
93+
public void http() throws Throwable {
94+
final boolean secured = false;
95+
final boolean useHttp2 = false;
96+
this.server = new ServerManager(secured, useHttp2);
97+
this.clients.addAll(createClients(secured, useHttp2));
98+
executeTest();
99+
}
100+
101+
102+
/**
103+
* Test for HTTP 1.1 protocol encrypted by {@value ClientThread#ENCRYPTION_PROTOCOL}.
104+
*
105+
* @throws Throwable
106+
*/
107+
@Test
108+
public void https() throws Throwable {
109+
final boolean secured = true;
110+
final boolean useHttp2 = false;
111+
this.server = new ServerManager(secured, useHttp2);
112+
this.clients.addAll(createClients(secured, useHttp2));
113+
executeTest();
114+
}
115+
116+
117+
/**
118+
* This test is rather for documentaion purpose, because HTTP/2 is usually not allowed to be
119+
* used without encryption. Remember that.
120+
*
121+
* @throws Throwable
122+
*/
123+
@Test(expected = IllegalArgumentException.class)
124+
public void http2() throws Throwable {
125+
this.server = new ServerManager(false, true);
126+
}
127+
128+
129+
/**
130+
* Test for HTTP/2 protocol encrypted by {@value ClientThread#ENCRYPTION_PROTOCOL}.
131+
*
132+
* @throws Throwable
133+
*/
134+
@Test
135+
public void https2() throws Throwable {
136+
final boolean secured = true;
137+
final boolean useHttp2 = true;
138+
this.server = new ServerManager(secured, useHttp2);
139+
this.clients.addAll(createClients(secured, useHttp2));
140+
executeTest();
141+
}
142+
143+
144+
private void executeTest() throws Throwable {
145+
for (final ClientThread clientThread : clients) {
146+
clientThread.start();
147+
}
148+
final long start = System.currentTimeMillis();
149+
while (error.get() == null && System.currentTimeMillis() < start + TIME_IN_MILLIS) {
150+
Thread.yield();
151+
}
152+
for (final ClientThread clientThread : clients) {
153+
clientThread.stopClient();
154+
}
155+
for (final ClientThread clientThread : clients) {
156+
// cycles are fast, so we can afford this.
157+
clientThread.join(100L);
158+
}
159+
if (error.get() != null) {
160+
throw error.get();
161+
}
162+
assertTrue("No requests processed.", counter.get() > 0);
163+
}
164+
165+
166+
private Collection<ClientThread> createClients(final boolean secured, final boolean useHttp2) throws Exception {
167+
final List<ClientThread> list = new ArrayList<>(COUNT_OF_CLIENTS);
168+
for (int i = 0; i < COUNT_OF_CLIENTS; i++) {
169+
list.add(createClient(secured, useHttp2, i + 1));
170+
}
171+
return list;
172+
}
173+
174+
175+
private ClientThread createClient(final boolean secured, final boolean useHttp2, final int id) throws Exception {
176+
@SuppressWarnings("unchecked")
177+
final Class<ClientThread> clazz = (Class<ClientThread>) Class.forName(CLIENT_IMPLEMENTATION);
178+
final Constructor<ClientThread> constructor = clazz.getConstructor(ClientThreadSettings.class,
179+
AtomicInteger.class, AtomicReference.class);
180+
assertNotNull("constructor for " + CLIENT_IMPLEMENTATION, constructor);
181+
final ClientThreadSettings settings = new ClientThreadSettings(id, secured, useHttp2,
182+
server.getApplicationServiceEndpoint());
183+
return constructor.newInstance(settings, counter, error);
184+
}
185+
}

0 commit comments

Comments
 (0)