From 584191362d964545ba17312c6a17096e8f5a9e92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 01:39:48 +0000 Subject: [PATCH 1/7] Add graceful shutdown configuration and tests for apollo-adminservice Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- .../src/main/resources/application.yml | 3 ++ .../GracefulShutdownConfigurationTest.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java diff --git a/apollo-adminservice/src/main/resources/application.yml b/apollo-adminservice/src/main/resources/application.yml index e1b1595c351..024b1810b20 100644 --- a/apollo-adminservice/src/main/resources/application.yml +++ b/apollo-adminservice/src/main/resources/application.yml @@ -27,9 +27,12 @@ spring: properties: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor + lifecycle: + timeout-per-shutdown-phase: 30s server: port: 8090 + shutdown: graceful logging: file: diff --git a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java new file mode 100644 index 00000000000..a9f4fb47dad --- /dev/null +++ b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2025 Apollo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.ctrip.framework.apollo.adminservice; + +import com.ctrip.framework.apollo.AdminServiceTestConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = AdminServiceTestConfiguration.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + "server.shutdown=graceful", + "spring.lifecycle.timeout-per-shutdown-phase=30s" + }) +public class GracefulShutdownConfigurationTest { + + @Autowired + private ServletWebServerApplicationContext webServerAppContext; + + @Test + public void testGracefulShutdownIsConfigured() { + assertNotNull("WebServer should be available", webServerAppContext); + assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); + + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) + assertNotNull("Lifecycle processor should be present for graceful shutdown", + webServerAppContext.getBean("lifecycleProcessor")); + } +} From b94ef4e14f941a39ae6da46072b5405a967bfe81 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 01:42:08 +0000 Subject: [PATCH 2/7] Add documentation for graceful shutdown feature Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- CHANGES.md | 1 + docs/en/deployment/distributed-deployment-guide.md | 2 ++ docs/zh/deployment/distributed-deployment-guide.md | 2 ++ 3 files changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fa31b77e969..451061e6e34 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Release Notes. Apollo 2.5.0 ------------------ +* [Feature: Enable graceful shutdown for apollo-adminservice](https://github.com/apolloconfig/apollo/pull/XXXX) * [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337) * [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336) * [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361) diff --git a/docs/en/deployment/distributed-deployment-guide.md b/docs/en/deployment/distributed-deployment-guide.md index a4997628ac6..46233866b24 100644 --- a/docs/en/deployment/distributed-deployment-guide.md +++ b/docs/en/deployment/distributed-deployment-guide.md @@ -531,6 +531,8 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > Note 3: To adjust the listening port of the service, you can modify the `SERVER_PORT` in scripts/startup.sh. +> Note 4: Starting from version 2.5.0, apollo-adminservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=30s` configuration. To adjust the timeout, you can modify the settings in application.yml. + #### 2.2.2.3 Deploy apollo-portal Upload `apollo-portal-x.x.x-github.zip` to the server, unzip it and execute scripts/startup.sh. To stop the service, execute scripts/shutdown.sh. diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index dc617cc2041..3e652cdf7a2 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -511,6 +511,8 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > 注3:如要调整服务的监听端口,可以修改scripts/startup.sh中的`SERVER_PORT`。 +> 注4:apollo-adminservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=30s`配置启用。如需调整超时时间,可以修改application.yml中的配置。 + #### 2.2.2.3 部署apollo-portal 将`apollo-portal-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. From e1251982e14e3b06d89f11cd1e46715c0c72f573 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 01:42:42 +0000 Subject: [PATCH 3/7] Fix CHANGES.md placeholder to use TODO marker Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 451061e6e34..c1fc5d48d59 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Release Notes. Apollo 2.5.0 ------------------ -* [Feature: Enable graceful shutdown for apollo-adminservice](https://github.com/apolloconfig/apollo/pull/XXXX) +* [Feature: Enable graceful shutdown for apollo-adminservice](#TODO) * [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337) * [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336) * [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361) From cc5ec5f97baecad38094ff138d9531fa70bae214 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:20:19 +0000 Subject: [PATCH 4/7] Address code review feedback: add configservice support, improve docs and config flexibility Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- CHANGES.md | 2 +- .../src/main/resources/application.yml | 2 +- .../GracefulShutdownConfigurationTest.java | 13 ++++ .../src/main/resources/application.yml | 3 + .../GracefulShutdownConfigurationTest.java | 64 +++++++++++++++++++ .../distributed-deployment-guide.md | 6 +- .../distributed-deployment-guide.md | 6 +- 7 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java diff --git a/CHANGES.md b/CHANGES.md index c1fc5d48d59..87d9f4b85ef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Release Notes. Apollo 2.5.0 ------------------ -* [Feature: Enable graceful shutdown for apollo-adminservice](#TODO) +* [Feature: Enable graceful shutdown for apollo-adminservice and apollo-configservice](https://github.com/apolloconfig/apollo/pull/5536) * [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337) * [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336) * [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361) diff --git a/apollo-adminservice/src/main/resources/application.yml b/apollo-adminservice/src/main/resources/application.yml index 024b1810b20..21d7ef1d1a9 100644 --- a/apollo-adminservice/src/main/resources/application.yml +++ b/apollo-adminservice/src/main/resources/application.yml @@ -28,7 +28,7 @@ spring: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor lifecycle: - timeout-per-shutdown-phase: 30s + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} server: port: 8090 diff --git a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java index a9f4fb47dad..ffbf86d296f 100644 --- a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java +++ b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java @@ -27,6 +27,19 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +/** + * Configuration validation test for graceful shutdown feature. + * + * This test verifies that the graceful shutdown configuration is properly loaded + * by checking for the presence of the lifecycleProcessor bean, which is created + * by Spring Boot when server.shutdown=graceful is configured. + * + * Note: This test does NOT verify the actual behavior of graceful shutdown + * (e.g., waiting for in-flight requests). Full behavioral testing requires: + * - Integration tests with real HTTP requests during shutdown + * - Manual testing in staging/production environments + * - Monitoring of shutdown metrics and logs + */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = AdminServiceTestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, diff --git a/apollo-configservice/src/main/resources/application.yml b/apollo-configservice/src/main/resources/application.yml index 986a8b91f38..ff8e2a1551c 100644 --- a/apollo-configservice/src/main/resources/application.yml +++ b/apollo-configservice/src/main/resources/application.yml @@ -27,9 +27,12 @@ spring: properties: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor + lifecycle: + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} server: port: 8080 + shutdown: graceful logging: file: diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java new file mode 100644 index 00000000000..27428f5a8ea --- /dev/null +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2025 Apollo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.ctrip.framework.apollo.configservice; + +import com.ctrip.framework.apollo.ConfigServiceTestConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Configuration validation test for graceful shutdown feature. + * + * This test verifies that the graceful shutdown configuration is properly loaded + * by checking for the presence of the lifecycleProcessor bean, which is created + * by Spring Boot when server.shutdown=graceful is configured. + * + * Note: This test does NOT verify the actual behavior of graceful shutdown + * (e.g., waiting for in-flight requests). Full behavioral testing requires: + * - Integration tests with real HTTP requests during shutdown + * - Manual testing in staging/production environments + * - Monitoring of shutdown metrics and logs + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = ConfigServiceTestConfiguration.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + "server.shutdown=graceful", + "spring.lifecycle.timeout-per-shutdown-phase=30s" + }) +public class GracefulShutdownConfigurationTest { + + @Autowired + private ServletWebServerApplicationContext webServerAppContext; + + @Test + public void testGracefulShutdownIsConfigured() { + assertNotNull("WebServer should be available", webServerAppContext); + assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); + + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) + assertNotNull("Lifecycle processor should be present for graceful shutdown", + webServerAppContext.getBean("lifecycleProcessor")); + } +} diff --git a/docs/en/deployment/distributed-deployment-guide.md b/docs/en/deployment/distributed-deployment-guide.md index 46233866b24..a4b5f1369bb 100644 --- a/docs/en/deployment/distributed-deployment-guide.md +++ b/docs/en/deployment/distributed-deployment-guide.md @@ -513,7 +513,9 @@ export JAVA_OPTS="-server -Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -X > Note 4: If the eureka.service.url of ApolloConfigDB.ServerConfig is only configured with the currently starting machine, the eureka registration failure information will be output in the log during the process of starting apollo-configservice, such as `com.sun.jersey .api.client.ClientHandlerException: java.net.ConnectException: Connection refused`. It should be noted that this is the expected situation, because apollo-configservice needs to register the service with the Meta Server (itself), but because it has not yet woken up during the startup process, it will report this error. The retry action will be performed later, so the registration will be normal after the service is up. -> Note 5: If you read this, I believe that you must be someone who reads the documentation carefully, and you are a little bit closer to success. Keep going, you should be able to complete the distributed deployment of Apollo soon! But do you feel that Apollo's distributed deployment steps are a bit cumbersome? Do you have any advice you would like to share with the author? If the answer is yes, please move to [#1424](https://github.com/apolloconfig/apollo/issues/1424) and look forward to your suggestions! +> Note 5: Starting from version 2.5.0, apollo-configservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). + +> Note 6: If you read this, I believe that you must be someone who reads the documentation carefully, and you are a little bit closer to success. Keep going, you should be able to complete the distributed deployment of Apollo soon! But do you feel that Apollo's distributed deployment steps are a bit cumbersome? Do you have any advice you would like to share with the author? If the answer is yes, please move to [#1424](https://github.com/apolloconfig/apollo/issues/1424) and look forward to your suggestions! #### 2.2.2.2 Deploy apollo-adminservice @@ -531,7 +533,7 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > Note 3: To adjust the listening port of the service, you can modify the `SERVER_PORT` in scripts/startup.sh. -> Note 4: Starting from version 2.5.0, apollo-adminservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=30s` configuration. To adjust the timeout, you can modify the settings in application.yml. +> Note 4: Starting from version 2.5.0, apollo-adminservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). #### 2.2.2.3 Deploy apollo-portal diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 3e652cdf7a2..9f8772f4e0f 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -495,7 +495,9 @@ export JAVA_OPTS="-server -Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -X > 注4:如果ApolloConfigDB.ServerConfig的eureka.service.url只配了当前正在启动的机器的话,在启动apollo-configservice的过程中会在日志中输出eureka注册失败的信息,如`com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`。需要注意的是,这个是预期的情况,因为apollo-configservice需要向Meta Server(它自己)注册服务,但是因为在启动过程中,自己还没起来,所以会报这个错。后面会进行重试的动作,所以等自己服务起来后就会注册正常了。 -> 注5:如果你看到了这里,相信你一定是一个细心阅读文档的人,而且离成功就差一点点了,继续加油,应该很快就能完成Apollo的分布式部署了!不过你是否有感觉Apollo的分布式部署步骤有点繁琐?是否有啥建议想要和作者说?如果答案是肯定的话,请移步 [#1424](https://github.com/apolloconfig/apollo/issues/1424),期待你的建议! +> 注5:apollo-configservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 + +> 注6:如果你看到了这里,相信你一定是一个细心阅读文档的人,而且离成功就差一点点了,继续加油,应该很快就能完成Apollo的分布式部署了!不过你是否有感觉Apollo的分布式部署步骤有点繁琐?是否有啥建议想要和作者说?如果答案是肯定的话,请移步 [#1424](https://github.com/apolloconfig/apollo/issues/1424),期待你的建议! #### 2.2.2.2 部署apollo-adminservice 将对应环境的`apollo-adminservice-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. @@ -511,7 +513,7 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > 注3:如要调整服务的监听端口,可以修改scripts/startup.sh中的`SERVER_PORT`。 -> 注4:apollo-adminservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=30s`配置启用。如需调整超时时间,可以修改application.yml中的配置。 +> 注4:apollo-adminservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 #### 2.2.2.3 部署apollo-portal 将`apollo-portal-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. From ea1273f80750629e88abca950542f132f26d9059 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 05:27:18 +0000 Subject: [PATCH 5/7] Address review feedback: fix tests to validate actual config, add assembly support, fix CHANGES.md ordering Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- CHANGES.md | 2 +- .../GracefulShutdownConfigurationTest.java | 18 +++++++++++------- .../src/test/resources/application.yml | 3 +++ .../src/main/resources/application.yml | 3 +++ .../GracefulShutdownConfigurationTest.java | 18 +++++++++++------- .../src/test/resources/application.yml | 3 +++ 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 87d9f4b85ef..e797333ee80 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,6 @@ Release Notes. Apollo 2.5.0 ------------------ -* [Feature: Enable graceful shutdown for apollo-adminservice and apollo-configservice](https://github.com/apolloconfig/apollo/pull/5536) * [Refactor: align permission validator api between openapi and portal](https://github.com/apolloconfig/apollo/pull/5337) * [Feature: Provide a new configfiles API to return the raw content of configuration files directly](https://github.com/apolloconfig/apollo/pull/5336) * [Feature: Enhanced instance configuration auditing and caching](https://github.com/apolloconfig/apollo/pull/5361) @@ -29,5 +28,6 @@ Apollo 2.5.0 * [doc: Add rust apollo client link](https://github.com/apolloconfig/apollo/pull/5514) * [Perf: optimize namespace-related interface](https://github.com/apolloconfig/apollo/pull/5518) * [Perf: Replace synchronized multimap with concurrent hashmap in NotificationControllerV2 for better performance](https://github.com/apolloconfig/apollo/pull/5532) +* [Feature: Enable graceful shutdown for apollo-adminservice and apollo-configservice](https://github.com/apolloconfig/apollo/pull/5536) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/16?closed=1) diff --git a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java index ffbf86d296f..dd949960097 100644 --- a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java +++ b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java @@ -20,10 +20,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -31,8 +33,7 @@ * Configuration validation test for graceful shutdown feature. * * This test verifies that the graceful shutdown configuration is properly loaded - * by checking for the presence of the lifecycleProcessor bean, which is created - * by Spring Boot when server.shutdown=graceful is configured. + * from application.yml by checking ServerProperties and the web server lifecycle. * * Note: This test does NOT verify the actual behavior of graceful shutdown * (e.g., waiting for in-flight requests). Full behavioral testing requires: @@ -42,21 +43,24 @@ */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = AdminServiceTestConfiguration.class, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "server.shutdown=graceful", - "spring.lifecycle.timeout-per-shutdown-phase=30s" - }) + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class GracefulShutdownConfigurationTest { @Autowired private ServletWebServerApplicationContext webServerAppContext; + @Autowired + private ServerProperties serverProperties; + @Test public void testGracefulShutdownIsConfigured() { assertNotNull("WebServer should be available", webServerAppContext); assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); + // Verify graceful shutdown is enabled in application.yml + assertEquals("Graceful shutdown should be enabled in application.yml", + "graceful", serverProperties.getShutdown().name().toLowerCase()); + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) assertNotNull("Lifecycle processor should be present for graceful shutdown", webServerAppContext.getBean("lifecycleProcessor")); diff --git a/apollo-adminservice/src/test/resources/application.yml b/apollo-adminservice/src/test/resources/application.yml index d1f2e0bd8e9..b67ce8d364d 100644 --- a/apollo-adminservice/src/test/resources/application.yml +++ b/apollo-adminservice/src/test/resources/application.yml @@ -16,9 +16,12 @@ spring: application: name: apollo-adminservice + lifecycle: + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} server: port: ${port:8090} + shutdown: graceful eureka: instance: diff --git a/apollo-assembly/src/main/resources/application.yml b/apollo-assembly/src/main/resources/application.yml index e25af6fde1b..61fa1a55e58 100644 --- a/apollo-assembly/src/main/resources/application.yml +++ b/apollo-assembly/src/main/resources/application.yml @@ -27,6 +27,8 @@ spring: properties: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor + lifecycle: + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} logging: file: @@ -60,6 +62,7 @@ eureka: register-with-eureka: false server: + shutdown: graceful compression: enabled: true tomcat: diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java index 27428f5a8ea..8bc7d90381b 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java @@ -20,10 +20,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -31,8 +33,7 @@ * Configuration validation test for graceful shutdown feature. * * This test verifies that the graceful shutdown configuration is properly loaded - * by checking for the presence of the lifecycleProcessor bean, which is created - * by Spring Boot when server.shutdown=graceful is configured. + * from application.yml by checking ServerProperties and the web server lifecycle. * * Note: This test does NOT verify the actual behavior of graceful shutdown * (e.g., waiting for in-flight requests). Full behavioral testing requires: @@ -42,21 +43,24 @@ */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = ConfigServiceTestConfiguration.class, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "server.shutdown=graceful", - "spring.lifecycle.timeout-per-shutdown-phase=30s" - }) + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class GracefulShutdownConfigurationTest { @Autowired private ServletWebServerApplicationContext webServerAppContext; + @Autowired + private ServerProperties serverProperties; + @Test public void testGracefulShutdownIsConfigured() { assertNotNull("WebServer should be available", webServerAppContext); assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); + // Verify graceful shutdown is enabled in application.yml + assertEquals("Graceful shutdown should be enabled in application.yml", + "graceful", serverProperties.getShutdown().name().toLowerCase()); + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) assertNotNull("Lifecycle processor should be present for graceful shutdown", webServerAppContext.getBean("lifecycleProcessor")); diff --git a/apollo-configservice/src/test/resources/application.yml b/apollo-configservice/src/test/resources/application.yml index 0e8c9321db5..a6ff433bfbe 100644 --- a/apollo-configservice/src/test/resources/application.yml +++ b/apollo-configservice/src/test/resources/application.yml @@ -16,9 +16,12 @@ spring: application: name: apollo-configservice + lifecycle: + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} server: port: ${port:8080} + shutdown: graceful eureka: instance: From dc52c9e855fca96170e318cea63bd0622cc27313 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 02:23:44 +0000 Subject: [PATCH 6/7] Change graceful shutdown default timeout from 30s to 10s for faster rolling updates Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- apollo-adminservice/src/main/resources/application.yml | 2 +- apollo-adminservice/src/test/resources/application.yml | 2 +- apollo-assembly/src/main/resources/application.yml | 2 +- apollo-configservice/src/main/resources/application.yml | 2 +- apollo-configservice/src/test/resources/application.yml | 2 +- docs/en/deployment/distributed-deployment-guide.md | 4 ++-- docs/zh/deployment/distributed-deployment-guide.md | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apollo-adminservice/src/main/resources/application.yml b/apollo-adminservice/src/main/resources/application.yml index 21d7ef1d1a9..dd9b8af4041 100644 --- a/apollo-adminservice/src/main/resources/application.yml +++ b/apollo-adminservice/src/main/resources/application.yml @@ -28,7 +28,7 @@ spring: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor lifecycle: - timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:10s} server: port: 8090 diff --git a/apollo-adminservice/src/test/resources/application.yml b/apollo-adminservice/src/test/resources/application.yml index b67ce8d364d..6a668e8d3af 100644 --- a/apollo-adminservice/src/test/resources/application.yml +++ b/apollo-adminservice/src/test/resources/application.yml @@ -17,7 +17,7 @@ spring: application: name: apollo-adminservice lifecycle: - timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:10s} server: port: ${port:8090} diff --git a/apollo-assembly/src/main/resources/application.yml b/apollo-assembly/src/main/resources/application.yml index 61fa1a55e58..4f2a77e7b97 100644 --- a/apollo-assembly/src/main/resources/application.yml +++ b/apollo-assembly/src/main/resources/application.yml @@ -28,7 +28,7 @@ spring: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor lifecycle: - timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:10s} logging: file: diff --git a/apollo-configservice/src/main/resources/application.yml b/apollo-configservice/src/main/resources/application.yml index ff8e2a1551c..77749a38243 100644 --- a/apollo-configservice/src/main/resources/application.yml +++ b/apollo-configservice/src/main/resources/application.yml @@ -28,7 +28,7 @@ spring: hibernate: metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor lifecycle: - timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:10s} server: port: 8080 diff --git a/apollo-configservice/src/test/resources/application.yml b/apollo-configservice/src/test/resources/application.yml index a6ff433bfbe..5e69a205bbd 100644 --- a/apollo-configservice/src/test/resources/application.yml +++ b/apollo-configservice/src/test/resources/application.yml @@ -17,7 +17,7 @@ spring: application: name: apollo-configservice lifecycle: - timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:30s} + timeout-per-shutdown-phase: ${GRACEFUL_SHUTDOWN_TIMEOUT:10s} server: port: ${port:8080} diff --git a/docs/en/deployment/distributed-deployment-guide.md b/docs/en/deployment/distributed-deployment-guide.md index a4b5f1369bb..ab610c568fe 100644 --- a/docs/en/deployment/distributed-deployment-guide.md +++ b/docs/en/deployment/distributed-deployment-guide.md @@ -513,7 +513,7 @@ export JAVA_OPTS="-server -Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -X > Note 4: If the eureka.service.url of ApolloConfigDB.ServerConfig is only configured with the currently starting machine, the eureka registration failure information will be output in the log during the process of starting apollo-configservice, such as `com.sun.jersey .api.client.ClientHandlerException: java.net.ConnectException: Connection refused`. It should be noted that this is the expected situation, because apollo-configservice needs to register the service with the Meta Server (itself), but because it has not yet woken up during the startup process, it will report this error. The retry action will be performed later, so the registration will be normal after the service is up. -> Note 5: Starting from version 2.5.0, apollo-configservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). +> Note 5: Starting from version 2.5.0, apollo-configservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 10 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:10s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `30s`, `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). > Note 6: If you read this, I believe that you must be someone who reads the documentation carefully, and you are a little bit closer to success. Keep going, you should be able to complete the distributed deployment of Apollo soon! But do you feel that Apollo's distributed deployment steps are a bit cumbersome? Do you have any advice you would like to share with the author? If the answer is yes, please move to [#1424](https://github.com/apolloconfig/apollo/issues/1424) and look forward to your suggestions! @@ -533,7 +533,7 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > Note 3: To adjust the listening port of the service, you can modify the `SERVER_PORT` in scripts/startup.sh. -> Note 4: Starting from version 2.5.0, apollo-adminservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 30 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). +> Note 4: Starting from version 2.5.0, apollo-adminservice supports graceful shutdown. When the service receives a stop signal, it will wait for in-flight requests to complete before shutting down, with a default timeout of 10 seconds. This feature is enabled via Spring Boot's `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:10s}` configuration. To adjust the timeout, you can set the `GRACEFUL_SHUTDOWN_TIMEOUT` environment variable (e.g., `30s`, `60s`, `2m`) or modify the settings in application.yml. In Kubernetes environments, ensure the Pod's `terminationGracePeriodSeconds` is greater than the configured timeout (recommend at least 10 seconds more). #### 2.2.2.3 Deploy apollo-portal diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 9f8772f4e0f..a95cc4dfaa8 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -495,7 +495,7 @@ export JAVA_OPTS="-server -Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -X > 注4:如果ApolloConfigDB.ServerConfig的eureka.service.url只配了当前正在启动的机器的话,在启动apollo-configservice的过程中会在日志中输出eureka注册失败的信息,如`com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`。需要注意的是,这个是预期的情况,因为apollo-configservice需要向Meta Server(它自己)注册服务,但是因为在启动过程中,自己还没起来,所以会报这个错。后面会进行重试的动作,所以等自己服务起来后就会注册正常了。 -> 注5:apollo-configservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 +> 注5:apollo-configservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为10秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:10s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`30s`、`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 > 注6:如果你看到了这里,相信你一定是一个细心阅读文档的人,而且离成功就差一点点了,继续加油,应该很快就能完成Apollo的分布式部署了!不过你是否有感觉Apollo的分布式部署步骤有点繁琐?是否有啥建议想要和作者说?如果答案是肯定的话,请移步 [#1424](https://github.com/apolloconfig/apollo/issues/1424),期待你的建议! @@ -513,7 +513,7 @@ export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -X > 注3:如要调整服务的监听端口,可以修改scripts/startup.sh中的`SERVER_PORT`。 -> 注4:apollo-adminservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为30秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:30s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 +> 注4:apollo-adminservice从2.5.0版本开始支持优雅下线功能。当服务收到停止信号时,会等待正在处理的请求完成后再关闭,默认等待时间为10秒。此功能通过Spring Boot的`server.shutdown=graceful`和`spring.lifecycle.timeout-per-shutdown-phase=${GRACEFUL_SHUTDOWN_TIMEOUT:10s}`配置启用。如需调整超时时间,可以通过环境变量`GRACEFUL_SHUTDOWN_TIMEOUT`设置(如`30s`、`60s`、`2m`等),或直接修改application.yml中的配置。在Kubernetes环境中,请确保Pod的`terminationGracePeriodSeconds`大于配置的超时时间(建议至少多10秒)。 #### 2.2.2.3 部署apollo-portal 将`apollo-portal-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. From 86bd575aba5648a1ecf49fcbb24d620d3a546b9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 02:43:47 +0000 Subject: [PATCH 7/7] Fix Spotless formatting violations in test files Co-authored-by: nobodyiam <837658+nobodyiam@users.noreply.github.com> --- .../GracefulShutdownConfigurationTest.java | 14 +++++++------- .../GracefulShutdownConfigurationTest.java | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java index dd949960097..aa71560845a 100644 --- a/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java +++ b/apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/GracefulShutdownConfigurationTest.java @@ -31,10 +31,10 @@ /** * Configuration validation test for graceful shutdown feature. - * + * * This test verifies that the graceful shutdown configuration is properly loaded * from application.yml by checking ServerProperties and the web server lifecycle. - * + * * Note: This test does NOT verify the actual behavior of graceful shutdown * (e.g., waiting for in-flight requests). Full behavioral testing requires: * - Integration tests with real HTTP requests during shutdown @@ -56,13 +56,13 @@ public class GracefulShutdownConfigurationTest { public void testGracefulShutdownIsConfigured() { assertNotNull("WebServer should be available", webServerAppContext); assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); - + // Verify graceful shutdown is enabled in application.yml - assertEquals("Graceful shutdown should be enabled in application.yml", - "graceful", serverProperties.getShutdown().name().toLowerCase()); - + assertEquals("Graceful shutdown should be enabled in application.yml", "graceful", + serverProperties.getShutdown().name().toLowerCase()); + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) - assertNotNull("Lifecycle processor should be present for graceful shutdown", + assertNotNull("Lifecycle processor should be present for graceful shutdown", webServerAppContext.getBean("lifecycleProcessor")); } } diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java index 8bc7d90381b..92dc9e57d16 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/GracefulShutdownConfigurationTest.java @@ -31,10 +31,10 @@ /** * Configuration validation test for graceful shutdown feature. - * + * * This test verifies that the graceful shutdown configuration is properly loaded * from application.yml by checking ServerProperties and the web server lifecycle. - * + * * Note: This test does NOT verify the actual behavior of graceful shutdown * (e.g., waiting for in-flight requests). Full behavioral testing requires: * - Integration tests with real HTTP requests during shutdown @@ -56,13 +56,13 @@ public class GracefulShutdownConfigurationTest { public void testGracefulShutdownIsConfigured() { assertNotNull("WebServer should be available", webServerAppContext); assertTrue("Server should be running", webServerAppContext.getWebServer().getPort() > 0); - + // Verify graceful shutdown is enabled in application.yml - assertEquals("Graceful shutdown should be enabled in application.yml", - "graceful", serverProperties.getShutdown().name().toLowerCase()); - + assertEquals("Graceful shutdown should be enabled in application.yml", "graceful", + serverProperties.getShutdown().name().toLowerCase()); + // Verify the lifecycle processor exists (indicates graceful shutdown is enabled) - assertNotNull("Lifecycle processor should be present for graceful shutdown", + assertNotNull("Lifecycle processor should be present for graceful shutdown", webServerAppContext.getBean("lifecycleProcessor")); } }