Skip to content

Commit cc9f0ef

Browse files
committed
add smoke tests for armeria jetty/tomcat
Signed-off-by: Doğaç Eldenk <[email protected]>
1 parent 51a0e89 commit cc9f0ef

22 files changed

+915
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id "java"
3+
}
4+
5+
description = "Spring Boot Armeria Jetty smoke test"
6+
7+
ext {
8+
armeriaVersion = "1.32.0"
9+
}
10+
11+
dependencies {
12+
implementation("com.linecorp.armeria:armeria:$armeriaVersion")
13+
implementation("com.linecorp.armeria:armeria-spring-boot3-autoconfigure:$armeriaVersion")
14+
implementation("com.linecorp.armeria:armeria-jetty12:$armeriaVersion")
15+
16+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) {
17+
exclude module: "spring-boot-starter-tomcat"
18+
}
19+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty"))
20+
21+
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty;
18+
19+
import com.linecorp.armeria.server.ServerBuilder;
20+
import com.linecorp.armeria.server.healthcheck.HealthChecker;
21+
import com.linecorp.armeria.server.jetty.JettyService;
22+
import com.linecorp.armeria.spring.ArmeriaServerConfigurator;
23+
import org.eclipse.jetty.server.Server;
24+
25+
import org.springframework.boot.web.embedded.jetty.JettyWebServer;
26+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.context.annotation.Configuration;
29+
30+
/**
31+
* Configures an Armeria server to redirect the incoming requests to the Jetty instance provided by
32+
* Spring Boot. It also sets up a {@link HealthChecker} so that it works well with a load balancer.
33+
*/
34+
@Configuration
35+
public class ArmeriaConfiguration {
36+
37+
/**
38+
* Returns a new {@link HealthChecker} that marks the server as unhealthy when Tomcat becomes unavailable.
39+
*/
40+
@Bean
41+
public HealthChecker jettyHealthChecker(ServletWebServerApplicationContext applicationContext) {
42+
final Server server = jettyServer(applicationContext).getServer();
43+
return server::isRunning;
44+
}
45+
46+
/**
47+
* Returns a new {@link JettyService} that redirects the incoming requests to the Jetty instance
48+
* provided by Spring Boot.
49+
*/
50+
@Bean
51+
public JettyService jettyService(ServletWebServerApplicationContext applicationContext) {
52+
final JettyWebServer jettyWebServer = jettyServer(applicationContext);
53+
return JettyService.of(jettyWebServer.getServer(), null);
54+
}
55+
56+
/**
57+
* Returns a new {@link ArmeriaServerConfigurator} that is responsible for configuring a {@link Server}
58+
* using the given {@link ServerBuilder}.
59+
*/
60+
@Bean
61+
public ArmeriaServerConfigurator armeriaServiceInitializer(JettyService jettyService) {
62+
return sb -> sb.serviceUnder("/", jettyService);
63+
}
64+
65+
/**
66+
* Extracts a Jetty {@link Server} from Spring webapp context.
67+
*/
68+
private static JettyWebServer jettyServer(ServletWebServerApplicationContext applicationContext) {
69+
return (JettyWebServer) applicationContext.getWebServer();
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty;
18+
19+
import jakarta.servlet.ServletContextEvent;
20+
import jakarta.servlet.ServletContextListener;
21+
22+
import org.springframework.stereotype.Component;
23+
24+
/**
25+
* Simple {@link ServletContextListener} to test gh-2058.
26+
*/
27+
@Component
28+
public class ExampleServletContextListener implements ServletContextListener {
29+
30+
@Override
31+
public void contextInitialized(ServletContextEvent sce) {
32+
System.out.println("*** contextInitialized");
33+
}
34+
35+
@Override
36+
public void contextDestroyed(ServletContextEvent sce) {
37+
System.out.println("*** contextDestroyed");
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class SampleArmeriaJettyApplication {
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(SampleArmeriaJettyApplication.class, args);
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty.service;
18+
19+
import org.springframework.beans.factory.annotation.Value;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class HelloWorldService {
24+
25+
@Value("${test.name:World}")
26+
private String name;
27+
28+
public String getHelloMessage() {
29+
return "Hello " + this.name;
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty.service;
18+
19+
import smoketest.jetty.util.StringUtil;
20+
21+
import org.springframework.beans.factory.annotation.Value;
22+
import org.springframework.stereotype.Component;
23+
24+
@Component
25+
public class HttpHeaderService {
26+
27+
@Value("${server.jetty.max-http-response-header-size}")
28+
private int maxHttpResponseHeaderSize;
29+
30+
/**
31+
* Generates a header value, which is longer than
32+
* 'server.jetty.max-http-response-header-size'.
33+
* @return the header value
34+
*/
35+
public String getHeaderValue() {
36+
return StringUtil.repeat('A', this.maxHttpResponseHeaderSize + 1);
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty.util;
18+
19+
import java.util.Arrays;
20+
21+
public final class StringUtil {
22+
23+
private StringUtil() {
24+
}
25+
26+
public static String repeat(char c, int length) {
27+
char[] chars = new char[length];
28+
Arrays.fill(chars, c);
29+
return new String(chars);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jetty.web;
18+
19+
import jakarta.servlet.http.HttpServletResponse;
20+
import smoketest.jetty.service.HelloWorldService;
21+
import smoketest.jetty.service.HttpHeaderService;
22+
23+
import org.springframework.stereotype.Controller;
24+
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.ResponseBody;
26+
27+
@Controller
28+
public class SampleController {
29+
30+
private final HelloWorldService helloWorldService;
31+
32+
private final HttpHeaderService httpHeaderService;
33+
34+
public SampleController(HelloWorldService helloWorldService, HttpHeaderService httpHeaderService) {
35+
this.helloWorldService = helloWorldService;
36+
this.httpHeaderService = httpHeaderService;
37+
}
38+
39+
@GetMapping("/")
40+
@ResponseBody
41+
public String helloWorld() {
42+
return this.helloWorldService.getHelloMessage();
43+
}
44+
45+
@GetMapping("/max-http-response-header")
46+
@ResponseBody
47+
public String maxHttpResponseHeader(HttpServletResponse response) {
48+
String headerValue = this.httpHeaderService.getHeaderValue();
49+
response.addHeader("x-max-header", headerValue);
50+
return this.helloWorldService.getHelloMessage();
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
server.compression.enabled: true
2+
server.compression.min-response-size: 1
3+
server.max-http-request-header-size=1000
4+
server.jetty.threads.acceptors=2
5+
server.jetty.max-http-response-header-size=4096
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.port: -1

0 commit comments

Comments
 (0)