Skip to content

Commit

Permalink
AgentCore的prematin启动和agentmain启动测试、动态配置zk测试、配置加载测试
Browse files Browse the repository at this point in the history
  • Loading branch information
TangLeDaily committed Oct 11, 2023
1 parent 3ebe342 commit 3707923
Show file tree
Hide file tree
Showing 26 changed files with 865 additions and 28 deletions.
66 changes: 66 additions & 0 deletions .github/actions/scenarios/agentcore/agentmain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Agent-core Agentmain Startup Test"
description: "Auto test for agent-core agentmain startup"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test/agentmain
- name: compile AgentLoader
shell: bash
run: |
cp sermant-integration-tests/scripts/AgentLoader.java ./
javac -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader.java
- name: (install agent) modify plugins file
shell: bash
run: |
sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/dynamic-test-third-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/plugins:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/ active:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/ passive:/a \ - dynamic-test-third-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
- name: start backend with memory
shell: bash
run: |
nohup java -jar sermant-agent-${{ env.sermantVersion }}/server/sermant/sermant-backend-${{ env.sermantVersion }}.jar &
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:2181
dynamic.config.dynamicConfigType: ZOOKEEPER
service.meta.project: TestAgentCore
run: |
nohup java -jar \
sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir
}}/agentcore-test.log 2>&1 &
- name: waiting for agentcore services start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8900/sermant/event/webhooks 120
- name: (install agent) dynamic install agent
shell: bash
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar
- name: Sleep for 5 Seconds
shell: bash
run: sleep 5
- name: test agentmain startup
shell: bash
run: mvn test -Dagentcore.test.type=AGENTMAIN_STARTUP --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: agentcore
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-agentmain-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
45 changes: 45 additions & 0 deletions .github/actions/scenarios/agentcore/common/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Agent-core Common Test"
description: "Auto test for agent-core common"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test/common
- name: modify config
shell: bash
run: |
sed -i 's/service\.meta\.application=default/service.meta.application=testApplication/' sermant-agent-${{ env.sermantVersion }}/agent/config/config.properties
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:2181
dynamic.config.dynamicConfigType: ZOOKEEPER
service.meta.project: TestAgentCore
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir
}}/agentcore-test.log 2>&1 &
- name: waiting for agentcore services start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
- name: agentcore test config load start
shell: bash
run: mvn test -Dagentcore.test.type=CONFIG_LOAD --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: agentcore
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-common-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Agent-core Common Test"
description: "Auto test for agent-core common, include nacos dynamic config"
name: "Dynamic Config Test"
description: "Auto test for dynamic config"
runs:
using: "composite"
steps:
Expand All @@ -10,8 +10,8 @@ runs:
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:8848
dynamic.config.dynamicConfigType: NACOS
dynamic.config.serverAddress: ${{ matrix.serviceAddress }}
dynamic.config.dynamicConfigType: ${{ matrix.dynamicConfigType }}
service.meta.project: TestAgentCore
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
Expand All @@ -33,7 +33,7 @@ runs:
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-logs
name: agentcore-test-dynamic-config-logs
path: |
./*.log
./logs/**
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/scenarios/agentcore/dynamic/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ runs:
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-logs
name: agentcore-test-dynamic-logs
path: |
./*.log
./logs/**
Expand Down
53 changes: 53 additions & 0 deletions .github/actions/scenarios/agentcore/premain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "Agent-core Premain Startup Test"
description: "Auto test for agent-core premain startup"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test/premain
- name: (install agent) modify plugins file
shell: bash
run: |
sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/plugins:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
sed -i '/ active:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
- name: start backend with memory
shell: bash
run: |
nohup java -jar sermant-agent-${{ env.sermantVersion }}/server/sermant/sermant-backend-${{ env.sermantVersion }}.jar &
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:2181
dynamic.config.dynamicConfigType: ZOOKEEPER
service.meta.project: TestAgentCore
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir
}}/agentcore-test.log 2>&1 &
- name: waiting for agentcore services start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8900/sermant/event/webhooks 120
- name: test premain startup
shell: bash
run: mvn test -Dagentcore.test.type=PREMAIN_STARTUP --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: agentcore
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: agentcore-test-premain-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
61 changes: 59 additions & 2 deletions .github/workflows/agentcore_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ jobs:
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-third-plugin/plugin
cp ./sermant-integration-tests/agentcore-test/agentcore-test-plugin/target/agentcore-test-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin/
cp -r ./sermant-integration-tests/agentcore-test/config sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/
cp ./sermant-integration-tests/agentcore-test/dynamic-test-first-plugin/target/dynamic-test-first-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/dynamic-test-second-plugin/target/dynamic-test-second-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/target/dynamic-test-third-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-third-plugin/plugin/
cp ./sermant-integration-tests/agentcore-test/agentcore-test-application/target/agentcore-test-application-1.0.0-jar-with-dependencies.jar sermant-agent-${{ env.sermantVersion }}/agent/
sed -i '/plugins:/a \ - agentcore-test-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
test-for-agentcore-common:
name: Test for agentcore common
runs-on: ubuntu-latest
needs: [ build-agent-and-cache, download-midwares-and-cache ]
needs: [build-agent-and-cache, download-midwares-and-cache]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -98,7 +101,30 @@ jobs:
- name: common operations
uses: ./.github/actions/common/agentcore
- name: start agentcore common test
uses: ./.github/actions/scenarios/agentcore/agentcore-common
uses: ./.github/actions/scenarios/agentcore/common
test-for-agentcore-dynamic-config:
name: Test for agentcore dynamic config
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
strategy:
matrix:
include:
- serviceAddress: "127.0.0.1:8848"
dynamicConfigType: "NACOS"
- serviceAddress: "127.0.0.1:2181"
dynamicConfigType: "ZOOKEEPER"
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/agentcore
- name: test dynamic config for ${{ matrix.dynamicConfigType }}
uses: ./.github/actions/scenarios/agentcore/dynamic-config
test-for-agentcore-dynamic:
name: Test for agentcore dynamic
runs-on: ubuntu-latest
Expand All @@ -114,5 +140,36 @@ jobs:
uses: ./.github/actions/common/agentcore
- name: start dynamic test
uses: ./.github/actions/scenarios/agentcore/dynamic
test-for-agentcore-premain-startup:
name: Test for agentcore premain startup
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/agentcore
- name: start dynamic test
uses: ./.github/actions/scenarios/agentcore/premain
test-for-agentcore-agentmain-startup:
name: Test for agentcore agentmain startup
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/agentcore
- name: start dynamic test
uses: ./.github/actions/scenarios/agentcore/agentmain



Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.huaweicloud.agentcore.test.request;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Map;

/**
* 请求测试类,采用http请求调用方式测试
Expand Down Expand Up @@ -72,4 +74,46 @@ public void testReInstallPlugin() throws IOException {
public void testInstallPlugin() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testInstallPlugin");
}

/**
* agentmain启动测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "AGENTMAIN_STARTUP")
public void testAgentmainStartup() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testAgentmainStartup");
}

/**
* premain启动测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "PREMAIN_STARTUP")
public void testPremainStartup() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testPremainStartup");
}

/**
* 启动后backend的appType和service字段设置测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "PREMAIN_STARTUP|AGENTMAIN_STARTUP")
public void testBackend() throws IOException {
Map<String, Object> resultMap = RequestUtils.analyzingRequestBackend(
"http://127.0.0.1:8900/sermant/getPluginsInfo");
Assertions.assertNotNull(resultMap, "getPluginsInfo result is null");
Assertions.assertTrue(resultMap.containsKey("appType"), "the result does not contain appType");
Assertions.assertTrue(resultMap.containsKey("service"), "the result does not contain service");
Assertions.assertEquals("default", resultMap.getOrDefault("appType", ""), "the value of appType is wrong");
Assertions.assertEquals("default", resultMap.getOrDefault("service", ""), "the value of service is wrong");
}

/**
* 配置加载测试方法
*/
@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "CONFIG_LOAD")
public void testCoreAndPluginConfigLoad() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testCoreAndPluginConfigLoad");
}
}
Loading

0 comments on commit 3707923

Please sign in to comment.