Skip to content

Commit

Permalink
Merge pull request sermant-io#1307 from TangLeDaily/nacos_AgentCoreTe…
Browse files Browse the repository at this point in the history
…st_2

agentcore集成测试:补充测试插件、自动化测试流水线
  • Loading branch information
Sherlockhan authored Sep 18, 2023
2 parents 4bcd82f + 569c9ac commit 9bb2b8e
Show file tree
Hide file tree
Showing 14 changed files with 748 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/actions/common/agentcore/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Common operations"
description: "do something common for all test"
runs:
using: "composite"
steps:
- name: Set up JDK ${{ env.javaVersion }}
uses: actions/setup-java@v3
with:
java-version: ${{ env.javaVersion }}
distribution: 'adopt'
cache: maven
- name: download zookeeper
uses: actions/cache@v3
with:
path: apache-zookeeper-3.6.3-bin.tar.gz
key: ${{ runner.os }}-apache-zookeeper-3.6.3
- name: start zookeeper
shell: bash
run: |
tar -zxf apache-zookeeper-3.6.3-bin.tar.gz
bash apache-zookeeper-3.6.3-bin/bin/zkServer.sh start apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg
- name: download local cse
uses: actions/cache@v3
with:
path: Local-CSE-2.1.3-linux-amd64.zip
key: ${{ runner.os }}-local-cse
restore-keys: |
${{ runner.os }}-local-cse
- name: start cse
shell: bash
run: |
export ROOT_PATH=$(pwd)
bash ./sermant-integration-tests/scripts/startCse.sh
- name: download nacos server
uses: actions/cache@v3
with:
path: nacos-server-2.1.0.tar.gz
key: ${{ runner.os }}-nacos-server-2.1.0
restore-keys: |
${{ runner.os }}-nacos-server-2.1.0
- name: start nacos server
shell: bash
run: |
tar -zxf nacos-server-2.1.0.tar.gz
bash nacos/bin/startup.sh -m standalone
- name: cache dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: download agent
uses: actions/cache@v3
with:
path: sermant-agent-*/
key: ${{ runner.os }}-agent-${{ github.run_id }}
- name: plugin change check
uses: ./.github/actions/common/plugin-change-check
41 changes: 41 additions & 0 deletions .github/actions/scenarios/agentcore/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Agent-core Common Test"
description: "Auto test for spring common, include nacos dynamic config"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/agentcore-test
- name: start applications
shell: bash
env:
dynamic.config.serverAddress: 127.0.0.1:8848
dynamic.config.dynamicConfigType: NACOS
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 module start
shell: bash
run: mvn test --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-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
99 changes: 99 additions & 0 deletions .github/workflows/agentcore_integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Agent-core Integration Test
env:
sermantVersion: 1.0.0
on:
push:
pull_request:
branches:
- '*'
paths:
- 'sermant-agentcore/**'
- 'sermant-integration-tests/agentcore-test/**'
- '.github/workflows/agentcore*.yml'
- '.github/actions/common/agentcore/action.yml'
- '.github/actions/scenarios/agentcore/action.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
download-midwares-and-cache:
name: download midwares and cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: cache local cse
uses: actions/cache@v3
with:
path: Local-CSE-2.1.3-linux-amd64.zip
key: ${{ runner.os }}-local-cse
restore-keys: |
${{ runner.os }}-local-cse
- name: download cse
run: |
export ROOT_PATH=$(pwd)
bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh cse
- name: cache zookeeper
uses: actions/cache@v3
with:
path: apache-zookeeper-3.6.3-bin.tar.gz
key: ${{ runner.os }}-apache-zookeeper-3.6.3
restore-keys: |
${{ runner.os }}-apache-zookeeper-3.6.3
- name: download zookeeper
run: |
export ROOT_PATH=$(pwd)
bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh zk
- name: cache nacos server
uses: actions/cache@v3
with:
path: nacos-server-2.1.0.tar.gz
key: ${{ runner.os }}-nacos-server-2.1.0
restore-keys: |
${{ runner.os }}-nacos-server-2.1.0
- name: download nacos
run: |
export ROOT_PATH=$(pwd)
bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh nacos210
build-agent-and-cache:
name: build agent and cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
cache: maven
- name: cache agent
uses: actions/cache@v3
with:
path: sermant-agent-*/
key: ${{ runner.os }}-agent-${{ github.run_id }}
- name: package agent
run: |
sed -i '/sermant-injector/d' pom.xml
mvn package -DskipTests -Ptest --file pom.xml
- name: move test plugin
run: |
mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-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 ./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:
name: Test for agentcore
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 agentcore test
uses: ./.github/actions/scenarios/agentcore


Original file line number Diff line number Diff line change
@@ -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.agentcore.tests.plugin.constants;

/**
* 测试静态类
*
* @author tangle
* @since 2023-09-18
*/
public class TestConstants {
/**
* 参数下标;0,因测试插件,不进行具体定义
*/
public static final int PARAM_INDEX_0 = 0;

/**
* 参数下标;1,因测试插件,不进行具体定义
*/
public static final int PARAM_INDEX_1 = 1;

/**
* 参数下标;2,因测试插件,不进行具体定义
*/
public static final int PARAM_INDEX_2 = 2;

/**
* 参数下标;3,因测试插件,不进行具体定义
*/
public static final int PARAM_INDEX_3 = 3;

private TestConstants() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.agentcore.tests.plugin.declarer.dynamicconfig;

import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.AddConfigListenerInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.AddGroupConfigListenerInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.GetConfigInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.PublishConfigInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.RemoveConfigInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.RemoveConfigListenerInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.dynamicconfig.RemoveGroupConfigListenerInterceptor;
import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher;
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* 测试动态配置核心
*
* @author tangle
* @since 2023-09-07
*/
public class TestDynamicConfigDeclarer extends AbstractPluginDeclarer {
@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameEquals(
"com.huaweicloud.agentcore.test.application.tests.dynamicconfig.DynamicConfigTest");
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.nameEquals("publishConfig"), new PublishConfigInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("getConfig"), new GetConfigInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("removeConfig"), new RemoveConfigInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("addConfigListener"),
new AddConfigListenerInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("removeConfigListener"),
new RemoveConfigListenerInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("addGroupConfigListener"),
new AddGroupConfigListenerInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals("removeGroupConfigListener"),
new RemoveGroupConfigListenerInterceptor())};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.agentcore.tests.plugin.interceptor.dynamicconfig;

import com.huaweicloud.agentcore.tests.plugin.constants.TestConstants;
import com.huaweicloud.agentcore.tests.plugin.listener.TestListener;
import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.core.service.dynamicconfig.DynamicConfigService;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* 添加单一配置监听拦截器
*
* @author tangle
* @since 2023-08-30
*/
public class AddConfigListenerInterceptor extends AbstractInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger();

DynamicConfigService dynamicConfigService = ServiceManager.getService(DynamicConfigService.class);

@Override
public ExecuteContext before(ExecuteContext context) {
String key = (String) context.getArguments()[TestConstants.PARAM_INDEX_1];
String group = (String) context.getArguments()[TestConstants.PARAM_INDEX_2];
context.getArguments()[TestConstants.PARAM_INDEX_0] = dynamicConfigService.doAddConfigListener(key, group,
new TestListener());
LOGGER.log(Level.INFO, "Test agentcore add config listener, key:{0}, group:{1}, result:{2}",
new String[]{key, group, String.valueOf(context.getArguments()[TestConstants.PARAM_INDEX_0])});
return context;
}

@Override
public ExecuteContext after(ExecuteContext context) {
return context;
}
}
Loading

0 comments on commit 9bb2b8e

Please sign in to comment.