From 02263840337af4ecebe87aacc74acb6cec4faf3c Mon Sep 17 00:00:00 2001 From: hanbingleixue Date: Thu, 13 Apr 2023 18:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=A6=BB=E7=BE=A4=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E6=91=98=E9=99=A4=E6=8F=92=E4=BB=B6=E7=9A=84=E9=9B=86?= =?UTF-8?q?=E6=88=90=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/plugin-change-check/action.yml | 15 ++ .../scenarios/dubbo/removal/action.yml | 91 +++++++++ .../scenarios/spring/removal/action.yml | 175 ++++++++++++++++++ .github/workflows/dubbo_integration_test.yml | 3 + .../workflows/spring_integration_test_1.yml | 3 + .../workflows/spring_integration_test_2.yml | 3 + .../controller/RemovalController.java | 48 +++++ .../src/main/resources/dubbo/dubbo.xml | 2 + .../service/RemovalServiceImpl.java | 43 +++++ .../src/main/resources/application.yaml | 3 +- .../src/main/resources/dubbo/provider.xml | 3 + .../controller/RemovalController.java | 48 +++++ .../src/main/resources/dubbo/dubbo.xml | 20 +- .../service/RemovalServiceImpl.java | 43 +++++ .../src/main/resources/application.yaml | 3 +- .../src/main/resources/dubbo/provider.xml | 3 + .../integration/service/RemovalService.java | 32 ++++ .../integration/removal/RemovalTest.java | 76 ++++++++ .../spring/feign/api/RemovalBootService.java | 40 ++++ .../spring/feign/api/RemovalService.java | 40 ++++ .../controller/RemovalController.java | 66 +++++++ .../src/main/resources/application.yml | 6 + .../feign/provider/RemovalServiceImpl.java | 62 +++++++ .../src/main/resources/application.yml | 3 +- .../spring/feign/api/RemovalBootService.java | 40 ++++ .../spring/feign/api/RemovalService.java | 40 ++++ .../controller/RemovalController.java | 66 +++++++ .../src/main/resources/application.yml | 8 +- .../feign/provider/RemovalServiceImpl.java | 62 +++++++ .../src/main/resources/application.yml | 3 +- .../consumer/FlowcontrolConiguration.java | 24 ++- .../rest/consumer/RemovalController.java | 72 +++++++ .../src/main/resources/application.yml | 3 +- .../rest/provider/RemovalController.java | 52 ++++++ .../src/main/resources/application.yml | 3 +- .../spring/common/FeignConstants.java | 5 + .../intergration/removal/RemovalTest.java | 85 +++++++++ 37 files changed, 1274 insertions(+), 20 deletions(-) create mode 100644 .github/actions/scenarios/dubbo/removal/action.yml create mode 100644 .github/actions/scenarios/spring/removal/action.yml create mode 100644 sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java create mode 100644 sermant-integration-tests/dubbo-test/dubbo-2-6-integration-provider/src/main/java/com/huaweicloud/integration/service/RemovalServiceImpl.java create mode 100644 sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java create mode 100644 sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/com/huaweicloud/integration/service/RemovalServiceImpl.java create mode 100644 sermant-integration-tests/dubbo-test/dubbo-integration-api/src/main/java/com/huaweicloud/integration/service/RemovalService.java create mode 100644 sermant-integration-tests/dubbo-test/dubbo-integration-test/src/test/java/com/huaweicloud/integration/removal/RemovalTest.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/RemovalController.java create mode 100644 sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/java/com/huaweicloud/spring/rest/provider/RemovalController.java create mode 100644 sermant-integration-tests/spring-test/spring-intergration-test/src/test/java/com/huaweicloud/intergration/removal/RemovalTest.java diff --git a/.github/actions/common/plugin-change-check/action.yml b/.github/actions/common/plugin-change-check/action.yml index cac4538791..a4a94e0982 100644 --- a/.github/actions/common/plugin-change-check/action.yml +++ b/.github/actions/common/plugin-change-check/action.yml @@ -83,6 +83,14 @@ runs: shell: bash run: | echo "sermantMqConsumerDenyChanged=${{ steps.changed-sermant-mq-consumer-deny.outputs.changed }}" >> $GITHUB_ENV + - uses: marceloprado/has-changed-path@v1 + id: changed-sermant-removal + with: + paths: sermant-plugins/sermant-service-removal + - name: env sermant-sermant-service-removal + shell: bash + run: | + echo "sermantServiceRemovalChanged=${{ steps.changed-sermant-removal.outputs.changed }}" >> $GITHUB_ENV - uses: marceloprado/has-changed-path@v1 id: changed-workflow-or-test with: @@ -164,6 +172,12 @@ runs: ${{ env.sermantSpringbootRegistryChanged }} == 'true' -o ${{ env.sermantServiceRegistryChanged }} == 'true' ];then echo "enableSpringLane=true" >> $GITHUB_ENV fi + + # ==========removal is needed to test?========== + if [ ${{ env.sermantAgentCoreChanged }} == 'true' -o ${{ env.sermantServiceRemovalChanged }} == 'true' -o \ + ${{ env.sermantSpringbootRegistryChanged }} == 'true' -o ${{ env.sermantServiceRegistryChanged }} == 'true' ];then + echo "enableRemoval=true" >> $GITHUB_ENV + fi # all workflow will trigger while workflow changed if [ ${{ steps.changed-workflow-or-test.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' ];then @@ -178,5 +192,6 @@ runs: echo "enableVisibility=true" >> $GITHUB_ENV echo "enableSpringLane=true" >> $GITHUB_ENV echo "enableDubboLane=true" >> $GITHUB_ENV + echo "enableRemoval=true" >> $GITHUB_ENV fi diff --git a/.github/actions/scenarios/dubbo/removal/action.yml b/.github/actions/scenarios/dubbo/removal/action.yml new file mode 100644 index 0000000000..507b5118fb --- /dev/null +++ b/.github/actions/scenarios/dubbo/removal/action.yml @@ -0,0 +1,91 @@ + name: "Dubbo Removal Test" + description: "Automated testing of outlier instance removal plug-in duddo scenario" + runs: + using: "composite" + steps: + - name: removal-entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/dubbo-removal + - name: package dubbo 2.5.x tests + shell: bash + if: matrix.dubbo-version == '2-5' + run: mvn package -Dalibaba.dubbo.version=2.5.${{ matrix.dubbo-versions }} -DskipTests -P260 --file sermant-integration-tests/dubbo-test/pom.xml + - name: package dubbo 2.6.0 tests + shell: bash + if: matrix.dubbo-version == '2-6' && matrix.dubbo-versions == '0' + run: mvn package -Dalibaba.dubbo.version=2.6.${{ matrix.dubbo-versions }} -DskipTests -P260 --file sermant-integration-tests/dubbo-test/pom.xml + - name: package dubbo 2.6.x tests + shell: bash + if: matrix.dubbo-version == '2-6' && matrix.dubbo-versions != '0' + run: mvn package -Dalibaba.dubbo.version=2.6.${{ matrix.dubbo-versions }} -DskipTests --file sermant-integration-tests/dubbo-test/pom.xml + - name: package dubbo 2.7.x tests + shell: bash + if: matrix.dubbo-version == '2-7' + run: mvn package -Ddubbo.version=2.7.${{ matrix.dubbo-versions }} -DskipTests --file sermant-integration-tests/dubbo-test/pom.xml + - name: start provider service + shell: bash + env: + TIMEOUT: 2000 + SERVER_PORT: 28021 + DUBBO_PROTOCOL_PORT: 28821 + run: | + nohup java -jar sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-provider/target/dubbo-integration-provider.jar > ${{ env.logDir }}/removal-provider-28021.log 2>&1 & + - name: start provider service + shell: bash + env: + TIMEOUT: 0 + SERVER_PORT: 28022 + DUBBO_PROTOCOL_PORT: 28822 + run: | + nohup java -jar sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-provider/target/dubbo-integration-provider.jar > ${{ env.logDir }}/removal-provider-28022.log 2>&1 & + - name: start provider service + shell: bash + env: + TIMEOUT: 0 + SERVER_PORT: 28023 + DUBBO_PROTOCOL_PORT: 28823 + run: | + nohup java -jar sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-provider/target/dubbo-integration-provider.jar > ${{ env.logDir }}/removal-provider-28023.log 2>&1 & + - name: start consumer service + shell: bash + env: + REMOVAL_CONFIG_EXPIRE_TIMES: 60000 + REMOVAL_CONFIG_EXCEPTIONS: "[com.alibaba.dubbo.remoting.TimeoutException, org.apache.dubbo.remoting.TimeoutException, java.util.concurrent.TimeoutException, java.net.SocketTimeoutException]" + REMOVAL_CONFIG_ENABLE_REMOVAL: true + REMOVAL_CONFIG_RECOVERY_TIMES: 30000 + REMOVAL_CONFIG_WINDOWS_TIMES: 1000 + REMOVAL_CONFIG_WINDOWS_NUM: 10 + REMOVAL_CONFIG_RULES: "[{ scaleUpLimit: 0.6, minInstanceNum: 1, errorRate: 0.6 , key: default-rule}]" + SERVER_PORT: 28020 + DUBBO_PROTOCOL_PORT: 28820 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=dubbo-integration-consumer -jar \ + sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-consumer/target/dubbo-integration-consumer.jar > ${{ env.logDir }}/removal-consumer-28050.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28020/actuator/health 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28021/actuator/health 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28022/actuator/health 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28023/actuator/health 120 + - name: removal test + shell: bash + env: + TEST_TYPE: removal + run: mvn test --file sermant-integration-tests/dubbo-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: dubbo + - name: upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: removal-(${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }})-logs + path: | + ./*.log + ./logs/**/*.log + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/spring/removal/action.yml b/.github/actions/scenarios/spring/removal/action.yml new file mode 100644 index 0000000000..ef7203e874 --- /dev/null +++ b/.github/actions/scenarios/spring/removal/action.yml @@ -0,0 +1,175 @@ +name: "Spring Removal Test" +description: "Auto test for spring removal for plugin sermant-removal" +runs: + using: "composite" + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/spring-removal + - name: 1.5.x config + if: matrix.springBootVersion == '1.5.0.RELEASE' && matrix.springCloudVersion == 'Edgware.SR2' + shell: bash + run: | + echo "tailVersion=-1.5.x" >> $GITHUB_ENV + echo "healthApi=health" >> $GITHUB_ENV + - name: 2.x config + if: matrix.springBootVersion != '1.5.0.RELEASE' + shell: bash + run: | + echo "healthApi=actuator/health" >> $GITHUB_ENV + - name: package common demos + shell: bash + run: | + sed -i 's|${{ env.projectSpringBootVersion }}|${{ matrix.springBootVersion }}|g' sermant-integration-tests/spring-test/pom.xml + mvn package -Dspring.cloud.version=${{ matrix.springCloudVersion }} -Dspring.boot.version=${{ matrix.springBootVersion }} -DskipTests -P common-test${{ env.tailVersion }} --file sermant-integration-tests/spring-test/pom.xml + - name: post config + shell: bash + run: bash ./sermant-integration-tests/scripts/createStrategy.sh all + - name: start feign provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8013 + SPRING_APPLICATION_NAME: removal-provider + TIMEOUT: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign${{ env.tailVersion }}/feign-provider${{ env.tailVersion }}/target/feign-provider${{ env.tailVersion }}.jar > ${{ env.logDir }}/feign-provider.log 2>&1 & + - name: start second feign provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8014 + SPRING_APPLICATION_NAME: removal-provider + TIMEOUT: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign${{ env.tailVersion }}/feign-provider${{ env.tailVersion }}/target/feign-provider${{ env.tailVersion }}.jar > ${{ env.logDir }}/feign-provider2.log 2>&1 & + - name: start third feign provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8015 + SPRING_APPLICATION_NAME: removal-provider + TIMEOUT: 2000 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign${{ env.tailVersion }}/feign-provider${{ env.tailVersion }}/target/feign-provider${{ env.tailVersion }}.jar > ${{ env.logDir }}/feign-provider3.log 2>&1 & + - name: start fourth feign provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8016 + SPRING_APPLICATION_NAME: removal-provider + TIMEOUT: 2000 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign${{ env.tailVersion }}/feign-provider${{ env.tailVersion }}/target/feign-provider${{ env.tailVersion }}.jar > ${{ env.logDir }}/feign-provider4.log 2>&1 & + - name: start feign consumer service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + REMOVAL_CONFIG_EXPIRE_TIMES: 60000 + REMOVAL_CONFIG_EXCEPTIONS: "[com.alibaba.dubbo.remoting.TimeoutException, org.apache.dubbo.remoting.TimeoutException, java.util.concurrent.TimeoutException, java.net.SocketTimeoutException]" + REMOVAL_CONFIG_ENABLE_REMOVAL: true + REMOVAL_CONFIG_RECOVERY_TIMES: 30000 + REMOVAL_CONFIG_WINDOWS_TIMES: 1000 + REMOVAL_CONFIG_WINDOWS_NUM: 10 + REMOVAL_CONFIG_RULES: "[{ scaleUpLimit: 0.6, minInstanceNum: 1, errorRate: 0.6 , key: default-rule}]" + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8017 + SERMANT_SPRINGBOOT_REGISTRY_LB_MAXRETRY: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign${{ env.tailVersion }}/feign-consumer${{ env.tailVersion }}/target/feign-consumer${{ env.tailVersion }}.jar > ${{ env.logDir }}/feign-consumer.log 2>&1 & + - name: start resttemplate provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + SERVER_PORT: 8018 + TIMEOUT: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/target/rest-provider.jar > ${{ env.logDir }}/rest-provider.log 2>&1 & + - name: start second resttemplate provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + SERVER_PORT: 8019 + TIMEOUT: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/target/rest-provider.jar > ${{ env.logDir }}/rest-provider2.log 2>&1 & + - name: start third resttemplate provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + SERVER_PORT: 8020 + TIMEOUT: 0 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/target/rest-provider.jar > ${{ env.logDir }}/rest-provider3.log 2>&1 & + - name: start fourth resttemplate provider service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + SERVER_PORT: 8021 + TIMEOUT: 2000 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/target/rest-provider.jar > ${{ env.logDir }}/rest-provider4.log 2>&1 & + - name: start resttemplate consumer service + shell: bash + env: + SERMANT_SPRINGBOOT_REGISTRY_ENABLE_REGISTRY: true + REMOVAL_CONFIG_EXPIRE_TIMES: 60000 + REMOVAL_CONFIG_EXCEPTIONS: "[com.alibaba.dubbo.remoting.TimeoutException, org.apache.dubbo.remoting.TimeoutException, java.util.concurrent.TimeoutException, java.net.SocketTimeoutException]" + REMOVAL_CONFIG_ENABLE_REMOVAL: true + REMOVAL_CONFIG_RECOVERY_TIMES: 30000 + REMOVAL_CONFIG_WINDOWS_TIMES: 1000 + REMOVAL_CONFIG_WINDOWS_NUM: 10 + REMOVAL_CONFIG_RULES: "[{ scaleUpLimit: 0.6, minInstanceNum: 1, errorRate: 0.6 , key: default-rule}]" + NIWS_LOADBALANCER_AVAILABILITY_FILTERING_RULE_FILTER_CIRCUIT_TRIPPED: false + SERVER_PORT: 8022 + SERMANT_SPRINGBOOT_REGISTRY_LB_MAXRETRY: 0 + TIMEOUT: 1000 + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/target/rest-consumer.jar > ${{ env.logDir }}/rest-consumer.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8013/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8014/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8015/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8016/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8017/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8018/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8019/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8020/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8021/${{ env.healthApi }} 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8022/${{ env.healthApi }} 120 + - name: integration test module REMOVAL + shell: bash + run: mvn test -Dsermant.integration.test.type=REMOVAL --file sermant-integration-tests/spring-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: feign|rest + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-graceful-(${{ matrix.springBootVersion }}-${{ matrix.springCloudVersion }})-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 diff --git a/.github/workflows/dubbo_integration_test.yml b/.github/workflows/dubbo_integration_test.yml index ed2adeff0e..8bae0f525f 100644 --- a/.github/workflows/dubbo_integration_test.yml +++ b/.github/workflows/dubbo_integration_test.yml @@ -117,3 +117,6 @@ jobs: - name: (dubbo lane) test for ${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }} if: env.enableDubboLane == 'true' uses: ./.github/actions/scenarios/dubbo/lane + - name: removal test for ${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }} + if: env.enableRemoval == 'true' + uses: ./.github/actions/scenarios/dubbo/removal diff --git a/.github/workflows/spring_integration_test_1.yml b/.github/workflows/spring_integration_test_1.yml index fb0dce31fe..0f7c3cb88d 100644 --- a/.github/workflows/spring_integration_test_1.yml +++ b/.github/workflows/spring_integration_test_1.yml @@ -146,3 +146,6 @@ jobs: - name: visibility test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }} if: env.enableVisibility == 'true' uses: ./.github/actions/scenarios/spring/visibility + - name: removal test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }} + if: env.enableRemoval == 'true' + uses: ./.github/actions/scenarios/spring/removal diff --git a/.github/workflows/spring_integration_test_2.yml b/.github/workflows/spring_integration_test_2.yml index 550f164845..2185572b94 100644 --- a/.github/workflows/spring_integration_test_2.yml +++ b/.github/workflows/spring_integration_test_2.yml @@ -136,3 +136,6 @@ jobs: - name: (spring lane) test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }} if: env.enableSpringLane == 'true' uses: ./.github/actions/scenarios/spring/lane + - name: removal test for springboot=${{ matrix.springBootVersion }} springCloudVersion=${{ matrix.springCloudVersion }} + if: env.enableRemoval == 'true' + uses: ./.github/actions/scenarios/spring/removal diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java b/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java new file mode 100644 index 0000000000..190decdc46 --- /dev/null +++ b/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.integration.controller; + +import com.huaweicloud.integration.service.RemovalService; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 离群实例摘除测试接口 + * + * @author zhp + * @since 2023-03-16 + */ +@RestController +@RequestMapping("/removal") +public class RemovalController { + @Resource(name = "removalService") + private RemovalService removalService; + + /** + * 测试离群实例摘除接口接口 + * + * @return 测试信息 + */ + @GetMapping("/testReq") + public String testReq() { + return removalService.getPort(); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/resources/dubbo/dubbo.xml b/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/resources/dubbo/dubbo.xml index 1e6fe63257..daa775b7fc 100644 --- a/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/resources/dubbo/dubbo.xml +++ b/sermant-integration-tests/dubbo-test/dubbo-2-6-integration-consumer/src/main/resources/dubbo/dubbo.xml @@ -19,6 +19,8 @@ + + + + diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java new file mode 100644 index 0000000000..190decdc46 --- /dev/null +++ b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/java/com/huaweicloud/integration/controller/RemovalController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.integration.controller; + +import com.huaweicloud.integration.service.RemovalService; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 离群实例摘除测试接口 + * + * @author zhp + * @since 2023-03-16 + */ +@RestController +@RequestMapping("/removal") +public class RemovalController { + @Resource(name = "removalService") + private RemovalService removalService; + + /** + * 测试离群实例摘除接口接口 + * + * @return 测试信息 + */ + @GetMapping("/testReq") + public String testReq() { + return removalService.getPort(); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/resources/dubbo/dubbo.xml b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/resources/dubbo/dubbo.xml index e6297c9193..dabef0f406 100644 --- a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/resources/dubbo/dubbo.xml +++ b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-consumer/src/main/resources/dubbo/dubbo.xml @@ -1,8 +1,8 @@ @@ -10,20 +10,22 @@ + + group="bar2"/> + generic="true"/> + version="0.0.1" timeout="10000"/> + version="*"/> + interface="com.huaweicloud.integration.service.FlowControlService" group="flow"/> + interface="com.huaweicloud.integration.service.FlowControlVersionService" group="flow"/> diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/com/huaweicloud/integration/service/RemovalServiceImpl.java b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/com/huaweicloud/integration/service/RemovalServiceImpl.java new file mode 100644 index 0000000000..1b954c2733 --- /dev/null +++ b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/com/huaweicloud/integration/service/RemovalServiceImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.integration.service; + +import org.springframework.beans.factory.annotation.Value; + +/** + * 获取端口信息 + * + * @author zhp + * @since 2023-03-16 + */ +public class RemovalServiceImpl implements RemovalService { + @Value("${timeout}") + private long timeout; + + @Value("${server.port}") + private Integer port; + + @Override + public String getPort() { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return port.toString(); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/application.yaml b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/application.yaml index a79afef365..9c751a8bba 100644 --- a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/application.yaml +++ b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/application.yaml @@ -24,4 +24,5 @@ management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true +timeout: 0 \ No newline at end of file diff --git a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/dubbo/provider.xml b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/dubbo/provider.xml index 13d2a8d21b..7e65ab9efc 100644 --- a/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/dubbo/provider.xml +++ b/sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/resources/dubbo/provider.xml @@ -10,6 +10,9 @@ + + + diff --git a/sermant-integration-tests/dubbo-test/dubbo-integration-api/src/main/java/com/huaweicloud/integration/service/RemovalService.java b/sermant-integration-tests/dubbo-test/dubbo-integration-api/src/main/java/com/huaweicloud/integration/service/RemovalService.java new file mode 100644 index 0000000000..6059985fde --- /dev/null +++ b/sermant-integration-tests/dubbo-test/dubbo-integration-api/src/main/java/com/huaweicloud/integration/service/RemovalService.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.integration.service; + +/** + * 离群实例摘除测试接口 + * + * @author zhp + * @since 2023-03-16 + */ +public interface RemovalService { + /** + * 获取端口号 + * + * @return 测试信息 + */ + String getPort(); +} \ No newline at end of file diff --git a/sermant-integration-tests/dubbo-test/dubbo-integration-test/src/test/java/com/huaweicloud/integration/removal/RemovalTest.java b/sermant-integration-tests/dubbo-test/dubbo-integration-test/src/test/java/com/huaweicloud/integration/removal/RemovalTest.java new file mode 100644 index 0000000000..5d3bc46095 --- /dev/null +++ b/sermant-integration-tests/dubbo-test/dubbo-integration-test/src/test/java/com/huaweicloud/integration/removal/RemovalTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.integration.removal; + +import com.huaweicloud.integration.utils.RequestUtils; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; + +import java.util.HashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 离群实例插件场景测试 + * + * @author zhp + * @since 2023-03-15 + */ +@EnabledIfEnvironmentVariable(named = "TEST_TYPE", matches = "removal") +public class RemovalTest { + private static final String REQ_URL = "http://127.0.0.1:28020/removal/testReq"; + + private static final int TIMES = 15000; + + private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(10); + + @Test + public void testRemoval() { + int reqFailNum = getReqFailNum(); + Assertions.assertTrue(reqFailNum != 0, "No request failures have occurred"); + reqFailNum = getReqFailNum(); + Assertions.assertEquals(0, reqFailNum, "fail still occur after the outlier instance is removed"); + } + + /** + * 测试离群实例摘除功能 + * + * @return 失败数量 + */ + private static int getReqFailNum() { + AtomicInteger reqFailNum = new AtomicInteger(); + EXECUTOR_SERVICE.execute(() -> { + long currentTimes = System.currentTimeMillis(); + while (System.currentTimeMillis() - currentTimes <= TIMES) { + try { + RequestUtils.get(REQ_URL, new HashMap<>(), String.class); + } catch (Exception e) { + reqFailNum.incrementAndGet(); + } + } + }); + try { + Thread.sleep(TIMES); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return reqFailNum.get(); + } +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java new file mode 100644 index 0000000000..8d3b3d020c --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.api; + +import com.huaweicloud.spring.common.registry.common.RegistryConstants; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * removal测试 + * + * @author zhp + * @since 2023-03-16 + */ +@FeignClient(name = "removalBootService", url = "http://" + RegistryConstants.TEST_DOMAIN + "/removal-provider") +public interface RemovalBootService { + /** + * 限流测试 + * + * @return ok + */ + @RequestMapping("/testRemoval") + String testRemoval(); +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java new file mode 100644 index 0000000000..314d37d066 --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-api-1.5.x/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.api; + +import com.huaweicloud.spring.common.FeignConstants; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * removal测试 + * + * @author zhp + * @since 2023-03-16 + */ +@FeignClient(qualifier = FeignConstants.REMOVAL_SERVICE_BEAN_NAME, name = "removal-provider") +public interface RemovalService { + /** + * 限流测试 + * + * @return ok + */ + @RequestMapping("testRemoval") + String testRemoval(); +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java new file mode 100644 index 0000000000..f0f6bdbdd7 --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.consumer.controller; + +import com.huaweicloud.spring.common.FeignConstants; +import com.huaweicloud.spring.feign.api.RemovalBootService; +import com.huaweicloud.spring.feign.api.RemovalService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 流控测试 + * + * @author zhp + * @since 2023-03-16 + */ +@Controller +@ResponseBody +@RequestMapping("removal") +public class RemovalController { + @Autowired + @Qualifier(FeignConstants.REMOVAL_SERVICE_BEAN_NAME) + private RemovalService removalService; + + @Autowired + private RemovalBootService removalBootService; + + /** + * 离群实例摘除调用 + * + * @return 调用结果 + */ + @RequestMapping("/cloud/testRemoval") + public String removal() { + return removalService.testRemoval(); + } + + /** + * 离群实例摘除调用 + * + * @return 调用结果 + */ + @RequestMapping("/boot/testRemoval") + public String testBootRemoval() { + return removalBootService.testRemoval(); + } +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/resources/application.yml index 5bae42535c..d600f4e21b 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-consumer-1.5.x/src/main/resources/application.yml @@ -12,6 +12,12 @@ feign: default: connectTimeout: 3000 readTimeout: 6000 + removal-provider: + connectTimeout: 1000 + readTimeout: 1000 + removalBootService: + connectTimeout: 1000 + readTimeout: 1000 management: endpoint: diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java new file mode 100644 index 0000000000..83992d6e39 --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.provider; + +import com.huaweicloud.spring.feign.api.RemovalBootService; +import com.huaweicloud.spring.feign.api.RemovalService; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 离群实例摘除插件的feign测试 + * + * @author zhp + * @since 2023-03-16 + */ +@Controller +@ResponseBody +public class RemovalServiceImpl implements RemovalService, RemovalBootService { + @Value("${server.port:8099}") + private int port; + + /** + * 超时时间 + */ + @Value("${timeout}") + private int timeout; + + /** + * 离群实例服务调用测试 + * + * @return 端口号 + * @throws RuntimeException 运行异常 + */ + @Override + @RequestMapping("/testRemoval") + public String testRemoval() { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return String.valueOf(port); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/application.yml index 1b3b6fc9c2..a54d8c3845 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/application.yml @@ -17,4 +17,5 @@ management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true +timeout: 0 \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java new file mode 100644 index 0000000000..0e88e3d56d --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalBootService.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.api; + +import com.huaweicloud.spring.common.registry.common.RegistryConstants; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * removal测试 + * + * @author zhp + * @since 2023-03-16 + */ +@FeignClient(name = "removalBootService", url = "http://" + RegistryConstants.TEST_DOMAIN + "/removal-provider") +public interface RemovalBootService { + /** + * 限流测试 + * + * @return ok + */ + @RequestMapping("/testRemoval") + String testRemoval(); +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java new file mode 100644 index 0000000000..1a0ed589af --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-api/src/main/java/com/huaweicloud/spring/feign/api/RemovalService.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.api; + +import com.huaweicloud.spring.common.FeignConstants; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * removal测试 + * + * @author zhp + * @since 2023-03-16 + */ +@FeignClient(qualifier = FeignConstants.REMOVAL_SERVICE_BEAN_NAME, name = "removal-provider") +public interface RemovalService { + /** + * 限流测试 + * + * @return ok + */ + @RequestMapping("testRemoval") + String testRemoval(); +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java new file mode 100644 index 0000000000..f0f6bdbdd7 --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/java/com/huaweicloud/spring/feign/consumer/controller/RemovalController.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.consumer.controller; + +import com.huaweicloud.spring.common.FeignConstants; +import com.huaweicloud.spring.feign.api.RemovalBootService; +import com.huaweicloud.spring.feign.api.RemovalService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 流控测试 + * + * @author zhp + * @since 2023-03-16 + */ +@Controller +@ResponseBody +@RequestMapping("removal") +public class RemovalController { + @Autowired + @Qualifier(FeignConstants.REMOVAL_SERVICE_BEAN_NAME) + private RemovalService removalService; + + @Autowired + private RemovalBootService removalBootService; + + /** + * 离群实例摘除调用 + * + * @return 调用结果 + */ + @RequestMapping("/cloud/testRemoval") + public String removal() { + return removalService.testRemoval(); + } + + /** + * 离群实例摘除调用 + * + * @return 调用结果 + */ + @RequestMapping("/boot/testRemoval") + public String testBootRemoval() { + return removalBootService.testRemoval(); + } +} diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/resources/application.yml index 2ca155df5e..6ec84adcc7 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-consumer/src/main/resources/application.yml @@ -14,9 +14,15 @@ feign: default: connectTimeout: 3000 readTimeout: 6000 + removal-provider: + connect-timeout: 1000 + read-timeout: 1000 + removalBootService: + connect-timeout: 1000 + read-timeout: 1000 management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java new file mode 100644 index 0000000000..542536ceaa --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/java/com/huaweicloud/spring/feign/provider/RemovalServiceImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.feign.provider; + +import com.huaweicloud.spring.feign.api.RemovalBootService; +import com.huaweicloud.spring.feign.api.RemovalService; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 离群实例摘除插件的feign测试 + * + * @author zhp + * @since 2023-03-16 + */ +@Controller +@ResponseBody +public class RemovalServiceImpl implements RemovalService, RemovalBootService { + @Value("${server.port:8099}") + private int port; + + /** + * 超时时间 + */ + @Value("${timeout}") + private int timeout; + + /** + * 离群实例摘除的服务调用 + * + * @return ok + * @throws RuntimeException 运行异常 + */ + @Override + @RequestMapping("/testRemoval") + public String testRemoval() { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return String.valueOf(port); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/resources/application.yml index 1b3b6fc9c2..a54d8c3845 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-feign/feign-provider/src/main/resources/application.yml @@ -17,4 +17,5 @@ management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true +timeout: 0 \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/FlowcontrolConiguration.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/FlowcontrolConiguration.java index d71f6217d0..08d09e5260 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/FlowcontrolConiguration.java +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/FlowcontrolConiguration.java @@ -27,10 +27,12 @@ import org.apache.http.ssl.SSLContexts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import java.security.KeyManagementException; @@ -50,6 +52,9 @@ public class FlowcontrolConiguration { private static final Logger LOGGER = LoggerFactory.getLogger(FlowcontrolConiguration.class); private static final int TIME_OUT = 5 * 60 * 1000; + @Value("${timeout}") + private int timeout; + /** * 注入请求器 * @@ -61,6 +66,20 @@ public RestTemplate restTemplate() { return new RestTemplate(); } + /** + * 离群实例摘除的注入请求器 + * + * @return RestTemplate + */ + @LoadBalanced + @Bean("removalRestTemplate") + public RestTemplate removalRestTemplate() { + RestTemplate template = new RestTemplate(); + SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) template.getRequestFactory(); + rf.setReadTimeout(timeout); + return template; + } + /** * 注入请求器 * @@ -99,10 +118,7 @@ private HttpComponentsClientHttpRequestFactory buildHttpRequestFactory() SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, strategy).build(); SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); RequestConfig requestConfig = RequestConfig.custom() - .setSocketTimeout(TIME_OUT) - .setConnectTimeout(TIME_OUT) - .setConnectionRequestTimeout(TIME_OUT) - .build(); + .setSocketTimeout(TIME_OUT).setConnectTimeout(TIME_OUT).setConnectionRequestTimeout(TIME_OUT).build(); HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.setDefaultRequestConfig(requestConfig); httpClientBuilder.setSSLSocketFactory(factory); diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/RemovalController.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/RemovalController.java new file mode 100644 index 0000000000..8a8dbfedeb --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/java/com/huaweicloud/spring/rest/consumer/RemovalController.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.rest.consumer; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * 利群实例摘除插件测试接口 + * + * @author zhp + * @since 2023-03-16 + */ +@RestController +@RequestMapping("/removal") +public class RemovalController { + @Autowired + @Qualifier("removalRestTemplate") + RestTemplate restTemplate; + + @Value("${down.serviceName}") + private String downServiceName; + + @Value("${config.domain:www.domain.com}") + private String domain; + + @Value("${timeout}") + private int timeout; + + /** + * 获取端口 + * + * @return 端口 + */ + @GetMapping("/boot/testRemoval") + public String testRemoval() { + RestTemplate template = new RestTemplate(); + SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) template.getRequestFactory(); + rf.setReadTimeout(timeout); + return template.getForObject("http://" + domain + "/" + downServiceName + "/removal/testRemoval", String.class); + } + + /** + * 获取端口 + * + * @return 端口 + */ + @GetMapping("/cloud/testRemoval") + public String testRemovalByCloud() { + return restTemplate.getForObject("http://" + downServiceName + "/removal/testRemoval", String.class); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/resources/application.yml index 60cd6b755c..bacc8e0d47 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-consumer/src/main/resources/application.yml @@ -13,4 +13,5 @@ management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true +timeout: 1000 \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/java/com/huaweicloud/spring/rest/provider/RemovalController.java b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/java/com/huaweicloud/spring/rest/provider/RemovalController.java new file mode 100644 index 0000000000..5a29011bd2 --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/java/com/huaweicloud/spring/rest/provider/RemovalController.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.spring.rest.provider; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 测试接口 + * + * @author zhp + * @since 2023-03-17 + */ +@RestController +public class RemovalController { + @Value("${timeout}") + private int timeout; + + @Value("${server.port}") + private int port; + + /** + * 获取端口 + * + * @return 区域 + * @throws RuntimeException 运行异常 + */ + @GetMapping("/removal/testRemoval") + public String testRemoval() { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return String.valueOf(port); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/resources/application.yml b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/resources/application.yml index 3ff34c4a49..9a8684ae71 100644 --- a/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/resources/application.yml +++ b/sermant-integration-tests/spring-test/spring-common-demos/spring-common-resttemplate/rest-provider/src/main/resources/application.yml @@ -17,4 +17,5 @@ management: endpoint: health: probes: - enabled: true \ No newline at end of file + enabled: true +timeout: 0 \ No newline at end of file diff --git a/sermant-integration-tests/spring-test/spring-common/src/main/java/com/huaweicloud/spring/common/FeignConstants.java b/sermant-integration-tests/spring-test/spring-common/src/main/java/com/huaweicloud/spring/common/FeignConstants.java index 28cb3d3947..2304b05acb 100644 --- a/sermant-integration-tests/spring-test/spring-common/src/main/java/com/huaweicloud/spring/common/FeignConstants.java +++ b/sermant-integration-tests/spring-test/spring-common/src/main/java/com/huaweicloud/spring/common/FeignConstants.java @@ -29,6 +29,11 @@ public class FeignConstants { */ public static final String FEIGN_SERVICE_BEAN_NAME = "FEIGN_SERVICE"; + /** + * 离群实例摘除插件的feign client名称 + */ + public static final String REMOVAL_SERVICE_BEAN_NAME = "REMOVAL_SERVICE"; + private FeignConstants() { } } diff --git a/sermant-integration-tests/spring-test/spring-intergration-test/src/test/java/com/huaweicloud/intergration/removal/RemovalTest.java b/sermant-integration-tests/spring-test/spring-intergration-test/src/test/java/com/huaweicloud/intergration/removal/RemovalTest.java new file mode 100644 index 0000000000..9bd003267a --- /dev/null +++ b/sermant-integration-tests/spring-test/spring-intergration-test/src/test/java/com/huaweicloud/intergration/removal/RemovalTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * 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.huaweicloud.intergration.removal; + +import com.huaweicloud.intergration.common.utils.RequestUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; + +import java.util.HashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 离群实例摘除插件测试类 + * + * @author zhp + * @since 2023-03-16 + */ +@EnabledIfSystemProperty(named = "sermant.integration.test.type", matches = "REMOVAL") +public class RemovalTest { + private static final String REQ_URL = "http://127.0.0.1:8017/removal/boot/testRemoval"; + + private static final String REST_REQ_URL = "http://127.0.0.1:8022/removal/boot/testRemoval"; + + private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(10); + + private static final int REMOVAL_TIME = 20000; + + private static final int TEST_REMOVED_TIME = 10000; + + @Test + public void testRemoval() { + int reqFailNum = getReqFailNum(REMOVAL_TIME, REQ_URL); + Assertions.assertTrue(reqFailNum != 0); + reqFailNum = getReqFailNum(TEST_REMOVED_TIME, REQ_URL); + Assertions.assertEquals(0, reqFailNum); + + reqFailNum = getReqFailNum(REMOVAL_TIME, REST_REQ_URL); + Assertions.assertTrue(reqFailNum != 0); + reqFailNum = getReqFailNum(TEST_REMOVED_TIME, REST_REQ_URL); + Assertions.assertEquals(0, reqFailNum); + } + + /** + * 测试失败数量 + * + * @return 失败数量 + */ + private static int getReqFailNum(long time, String url) { + AtomicInteger reqFailNum = new AtomicInteger(); + EXECUTOR_SERVICE.execute(() -> { + long currentTimes = System.currentTimeMillis(); + while (System.currentTimeMillis() - currentTimes <= time) { + try { + RequestUtils.get(url, new HashMap<>(), String.class); + } catch (Exception e) { + reqFailNum.incrementAndGet(); + } + } + }); + try { + Thread.sleep(time); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return reqFailNum.get(); + } +}