Skip to content

Commit

Permalink
AgentCore的基础增强测试:插件部分、测试用例部分
Browse files Browse the repository at this point in the history
  • Loading branch information
TangLeDaily committed Oct 12, 2023
1 parent 317d2ea commit d164d39
Show file tree
Hide file tree
Showing 25 changed files with 968 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,28 @@ public void testBackend() throws IOException {
public void testCoreAndPluginConfigLoad() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testCoreAndPluginConfigLoad");
}

@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "COMMON_ENHANCE")
public void testClassMatch() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testClassMatch");
}

@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "COMMON_ENHANCE")
public void testMethodMatch() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testMethodMatch");
}

@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "COMMON_ENHANCE")
public void testEnhancement() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testEnhancement");
}

@Test
@EnabledIfSystemProperty(named = "agentcore.test.type", matches = "COMMON_ENHANCE")
public void testBootstrap() throws IOException {
RequestUtils.testRequest("http://127.0.0.1:8915/testBootstrap");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.test.application.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 示例注解,用于作为注解拦截的示例
*
* @author luanwenfei
* @since 2023-09-08
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface TestAnnotationA {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.test.application.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 实例注解,用于座位注解拦截的示例
*
* @author luanwenfei
* @since 2023-09-08
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface TestAnnotationB {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.test.application.common;

/**
* TestSuperTypeA
*
* @author luanwenfei
* @since 2023-09-08
*/
public interface TestSuperTypeA {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.test.application.common;

/**
* TestSuperTypeB
*
* @author luanwenfei
* @since 2023-09-08
*/
public interface TestSuperTypeB {
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ public class RouterPath {
*/
public static final String REQUEST_PATH_CORE_AND_PLUGIN_CONFIG_LOAD = "/testCoreAndPluginConfigLoad";

/**
* 测试类匹配
*/
public static final String REQUEST_PATH_CLASS_MATCH = "/testClassMatch";

/**
* 测试动态重装Agent请求地址
*/
public static final String REQUEST_PATH_METHOD_MATCH = "/testMethodMatch";

/**
* 测试动态重装Agent请求地址
*/
public static final String REQUEST_PATH_ENHANCEMENT = "/testEnhancement";

/**
* 测试动态重装Agent请求地址
*/
public static final String REQUEST_PATH_BOOTSTRAP = "/testBootstrap";

private RouterPath() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.bootstrap;

import com.huaweicloud.agentcore.tests.plugin.interceptor.bootstrap.ActiveCountInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.bootstrap.GetAllStackTracesInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.bootstrap.NoParamsConstructorInterceptor;
import com.huaweicloud.agentcore.tests.plugin.interceptor.bootstrap.SetNameInterceptor;
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 luanwenfei
* @since 2023-09-07
*/
public class TestBootstrapDeclarer extends AbstractPluginDeclarer {
@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameEquals("java.lang.Thread");
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
// 测试静态方法
InterceptDeclarer.build(MethodMatcher.nameEquals("getAllStackTraces"),
new GetAllStackTracesInterceptor()),
// 测试无参构造方法
InterceptDeclarer.build(MethodMatcher.isConstructor().and(MethodMatcher.paramCountEquals(0)),
new NoParamsConstructorInterceptor()),
// 测试实例方法
InterceptDeclarer.build(MethodMatcher.nameEquals("setName"), new SetNameInterceptor()),
// 测试静态方法skip
InterceptDeclarer.build(MethodMatcher.nameEquals("activeCount"), new ActiveCountInterceptor()),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.classmatch;

import com.huaweicloud.agentcore.tests.plugin.interceptor.common.SetEnhanceFlagInterceptor;
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 luanwenfei
* @since 2023-09-07
*/
public class TestAnnotationDeclarer extends AbstractPluginDeclarer {
@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.isAnnotatedWith("com.huaweicloud.agentcore.test.application.common.TestAnnotationA");
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.isStaticMethod(), new SetEnhanceFlagInterceptor())};
}
}
Original file line number Diff line number Diff line change
@@ -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.agentcore.tests.plugin.declarer.classmatch;

import com.huaweicloud.agentcore.tests.plugin.interceptor.common.SetEnhanceFlagInterceptor;
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 luanwenfei
* @since 2023-09-07
*/
public class TestAnnotationsDeclarer extends AbstractPluginDeclarer {
@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.isAnnotatedWith("com.huaweicloud.agentcore.test.application.common.TestAnnotationA",
"com.huaweicloud.agentcore.test.application.common.TestAnnotationB");
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.isStaticMethod(), new SetEnhanceFlagInterceptor())};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.classmatch;

import com.huaweicloud.agentcore.tests.plugin.interceptor.common.SetEnhanceFlagInterceptor;
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 luanwenfei
* @since 2023-09-07
*/
public class TestInfixDeclarer extends AbstractPluginDeclarer {
@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameInfixedWith("Infix");
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.isStaticMethod(), new SetEnhanceFlagInterceptor())};
}
}
Loading

0 comments on commit d164d39

Please sign in to comment.