You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/20 07:39:11 UTC
[shardingsphere] branch master updated: Add test cases for YamlAdvisorsConfigurationSwapper (#22983)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 867e76a94d4 Add test cases for YamlAdvisorsConfigurationSwapper (#22983)
867e76a94d4 is described below
commit 867e76a94d4c1f2555be5b56ab067fe5723dd7c3
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Dec 20 15:38:59 2022 +0800
Add test cases for YamlAdvisorsConfigurationSwapper (#22983)
---
.../entity/YamlPointcutParameterConfiguration.java | 2 +-
.../swapper/YamlAdvisorsConfigurationSwapper.java | 12 ----
.../swapper/YamlPointcutConfigurationSwapper.java | 10 ++-
.../plugin/yaml/fixture/YamlAdviceFixture.java | 57 ++++++++++++++++
.../yaml/fixture/YamlTargetObjectFixture.java} | 48 ++++++++------
.../YamlAdvisorsConfigurationSwapperTest.java | 76 ++++++++--------------
.../core/transformer/AgentTransformerTest.java | 24 +++----
.../fixture/targeted/TargetObjectFixture.java | 8 +--
agent/core/src/test/resources/advisors.yaml | 51 ---------------
agent/core/src/test/resources/conf/advisors.yaml | 54 +++++++++++++++
10 files changed, 192 insertions(+), 150 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
index 39f128daa93..f62668bf7f0 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
@@ -29,5 +29,5 @@ public final class YamlPointcutParameterConfiguration {
private int index;
- private String type;
+ private String name;
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
index 1663d197c10..09c466035fd 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
@@ -20,9 +20,7 @@ package org.apache.shardingsphere.agent.core.plugin.yaml.swapper;
import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAdvisorsConfiguration;
-import org.yaml.snakeyaml.Yaml;
-import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedList;
@@ -33,16 +31,6 @@ public final class YamlAdvisorsConfigurationSwapper {
private final YamlAdvisorConfigurationSwapper advisorConfigurationSwapper = new YamlAdvisorConfigurationSwapper();
- /**
- * Unmarshal advisors configuration.
- *
- * @param inputStream input stream
- * @return unmarshalled advisors configuration
- */
- public YamlAdvisorsConfiguration unmarshal(final InputStream inputStream) {
- return new Yaml().loadAs(inputStream, YamlAdvisorsConfiguration.class);
- }
-
/**
* Swap from YAML advisors configuration to advisor configurations.
*
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlPointcutConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlPointcutConfigurationSwapper.java
index d2f4cb4500b..e05f46f2a97 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlPointcutConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlPointcutConfigurationSwapper.java
@@ -42,15 +42,19 @@ public final class YamlPointcutConfigurationSwapper {
return Optional.of(appendParameters(yamlPointcutConfig, ElementMatchers.isConstructor()));
}
if ("method".equals(yamlPointcutConfig.getType())) {
- return Optional.of(appendParameters(yamlPointcutConfig, ElementMatchers.namedOneOf(yamlPointcutConfig.getName())));
+ return Optional.of(appendParameters(yamlPointcutConfig, ElementMatchers.named(yamlPointcutConfig.getName())));
}
return Optional.empty();
}
private ElementMatcher<? super MethodDescription> appendParameters(final YamlPointcutConfiguration yamlPointcutConfig, final Junction<? super MethodDescription> pointcut) {
+ if (yamlPointcutConfig.getParams().isEmpty()) {
+ return pointcut.and(ElementMatchers.takesNoArguments());
+ }
+ Junction<? super MethodDescription> result = pointcut;
for (YamlPointcutParameterConfiguration each : yamlPointcutConfig.getParams()) {
- pointcut.and(ElementMatchers.takesArgument(each.getIndex(), ElementMatchers.named(each.getType())));
+ result = result.and(ElementMatchers.takesArgument(each.getIndex(), ElementMatchers.named(each.getName())));
}
- return pointcut;
+ return result;
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlAdviceFixture.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlAdviceFixture.java
new file mode 100644
index 00000000000..b33dd198cd6
--- /dev/null
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlAdviceFixture.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.agent.core.plugin.yaml.fixture;
+
+import org.apache.shardingsphere.agent.advice.MethodInvocationResult;
+import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
+import org.apache.shardingsphere.agent.advice.type.ConstructorAdvice;
+import org.apache.shardingsphere.agent.advice.type.InstanceMethodAdvice;
+import org.apache.shardingsphere.agent.advice.type.StaticMethodAdvice;
+
+import java.lang.reflect.Method;
+
+public final class YamlAdviceFixture implements ConstructorAdvice, InstanceMethodAdvice, StaticMethodAdvice {
+
+ @Override
+ public void onConstructor(final TargetAdviceObject target, final Object[] args) {
+ }
+
+ @Override
+ public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final MethodInvocationResult invocationResult) {
+ }
+
+ @Override
+ public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final MethodInvocationResult result) {
+ }
+
+ @Override
+ public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final MethodInvocationResult invocationResult) {
+ }
+
+ @Override
+ public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final MethodInvocationResult result) {
+ }
+
+ @Override
+ public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable) {
+ }
+
+ @Override
+ public void onThrowing(final Class<?> clazz, final Method method, final Object[] args, final Throwable throwable) {
+ }
+}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlTargetObjectFixture.java
similarity index 52%
copy from agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java
copy to agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlTargetObjectFixture.java
index 54a7e3b2b40..3fa377432d1 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/fixture/YamlTargetObjectFixture.java
@@ -15,49 +15,59 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.transformer.fixture.targeted;
+package org.apache.shardingsphere.agent.core.plugin.yaml.fixture;
-import java.util.List;
+import lombok.NoArgsConstructor;
-public final class TargetObjectFixture {
+@NoArgsConstructor
+public final class YamlTargetObjectFixture {
- public TargetObjectFixture(final List<String> queue) {
- queue.add("on constructor");
+ public YamlTargetObjectFixture(final String value) {
+ }
+
+ /**
+ * Call instance method.
+ */
+ public void call() {
}
/**
* Call instance method.
*
- * @param queue queue
+ * @param value value
*/
- public void callInstanceMethod(final List<String> queue) {
- queue.add("on instance method");
+ public void call(final String value) {
}
/**
- * Call instance method when exception thrown.
+ * Call instance method.
*
- * @param queue queue
+ * @param value1 value1
+ * @param value2 value2
*/
- public void callInstanceMethodWhenExceptionThrown(final List<String> queue) {
- throw new UnsupportedOperationException();
+ public void call(final String value1, final String value2) {
+ }
+
+ /**
+ * Call static method.
+ */
+ public static void staticCall() {
}
/**
* Call static method.
*
- * @param queue queue
+ * @param value value
*/
- public static void callStaticMethod(final List<String> queue) {
- queue.add("on static method");
+ public static void staticCall(final String value) {
}
/**
- * Call static method when exception thrown.
+ * Call static method.
*
- * @param queue queue
+ * @param value1 value1
+ * @param value2 value2
*/
- public static void callStaticMethodWhenExceptionThrown(final List<String> queue) {
- throw new UnsupportedOperationException();
+ public static void staticCall(final String value1, final String value2) {
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
index 198b677f07b..c3cca840c62 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
@@ -17,16 +17,17 @@
package org.apache.shardingsphere.agent.core.plugin.yaml.swapper;
-import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAdvisorConfiguration;
+import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
+import org.apache.shardingsphere.agent.config.advisor.MethodAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAdvisorsConfiguration;
-import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlPointcutConfiguration;
+import org.apache.shardingsphere.agent.core.plugin.yaml.fixture.YamlAdviceFixture;
+import org.apache.shardingsphere.agent.core.plugin.yaml.fixture.YamlTargetObjectFixture;
import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@@ -35,51 +36,30 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class YamlAdvisorsConfigurationSwapperTest {
@Test
- public void assertUnmarshal() {
- YamlAdvisorsConfiguration actual = new YamlAdvisorsConfigurationSwapper().unmarshal(getClass().getResourceAsStream("/advisors.yaml"));
- assertThat(actual.getAdvisors().size(), is(5));
- List<YamlAdvisorConfiguration> actualYamlAdvisorConfigs = new ArrayList<>(actual.getAdvisors());
- assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(0), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask",
- "org.apache.shardingsphere.agent.metrics.core.advice.CommandExecutorTaskAdvice",
- Arrays.asList(createExpectedYamlPointcutConfiguration("run", "method"), createExpectedYamlPointcutConfiguration("processException", "method"))));
- assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(1), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler",
- "org.apache.shardingsphere.agent.metrics.core.advice.ChannelHandlerAdvice",
- Arrays.asList(createExpectedYamlPointcutConfiguration("channelActive", "method"),
- createExpectedYamlPointcutConfiguration("channelRead", "method"), createExpectedYamlPointcutConfiguration("channelInactive", "method"))));
- assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(2), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.route.engine.SQLRouteEngine",
- "org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("route", "method"))));
- assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(3), createExpectedYamlAdvisorConfiguration(
- "org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager",
- "org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice",
- Arrays.asList(createExpectedYamlPointcutConfiguration("commit", "method"), createExpectedYamlPointcutConfiguration("rollback", "method"))));
- assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(4), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper",
- "org.apache.shardingsphere.agent.metrics.core.advice.DataSourceAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("decorate", "method"))));
+ public void assertSwapToObject() {
+ Collection<AdvisorConfiguration> actual = new YamlAdvisorsConfigurationSwapper().swapToObject(
+ new Yaml().loadAs(getClass().getResourceAsStream("/conf/advisors.yaml"), YamlAdvisorsConfiguration.class), "YAML_FIXTURE");
+ assertThat(actual.size(), is(1));
+ assertAdvisorConfiguration(actual.iterator().next());
}
- private void assertYamlAdvisorConfiguration(final YamlAdvisorConfiguration actual, final YamlAdvisorConfiguration expected) {
- assertThat(actual.getTarget(), is(expected.getTarget()));
- assertThat(actual.getAdvice(), is(expected.getAdvice()));
- assertThat(actual.getPointcuts().isEmpty(), is(expected.getPointcuts().isEmpty()));
- Iterator<YamlPointcutConfiguration> expectedYamlPointcutConfigs = expected.getPointcuts().iterator();
- for (YamlPointcutConfiguration each : actual.getPointcuts()) {
- YamlPointcutConfiguration expectedYamlPointcutConfig = expectedYamlPointcutConfigs.next();
- assertThat(each.getName(), is(expectedYamlPointcutConfig.getName()));
- assertThat(each.getType(), is(expectedYamlPointcutConfig.getType()));
+ private void assertAdvisorConfiguration(final AdvisorConfiguration actual) {
+ assertThat(actual.getTargetClassName(), is(YamlTargetObjectFixture.class.getName()));
+ assertThat(actual.getAdvisors().size(), is(8));
+ for (MethodAdvisorConfiguration each : actual.getAdvisors()) {
+ assertThat(each.getAdviceClassName(), is(YamlAdviceFixture.class.getName()));
}
- }
-
- private YamlAdvisorConfiguration createExpectedYamlAdvisorConfiguration(final String target, final String advice, final Collection<YamlPointcutConfiguration> yamlPointcutConfigs) {
- YamlAdvisorConfiguration result = new YamlAdvisorConfiguration();
- result.setTarget(target);
- result.setAdvice(advice);
- result.setPointcuts(yamlPointcutConfigs);
- return result;
- }
-
- private YamlPointcutConfiguration createExpectedYamlPointcutConfiguration(final String name, final String type) {
- YamlPointcutConfiguration result = new YamlPointcutConfiguration();
- result.setName(name);
- result.setType(type);
- return result;
+ List<MethodAdvisorConfiguration> actualAdvisorConfig = new ArrayList<>(actual.getAdvisors());
+ assertThat(actualAdvisorConfig.get(0).getPointcut(), is(ElementMatchers.isConstructor().and(ElementMatchers.takesNoArguments())));
+ assertThat(actualAdvisorConfig.get(1).getPointcut(), is(ElementMatchers.isConstructor().and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
+ assertThat(actualAdvisorConfig.get(2).getPointcut(), is(ElementMatchers.named("call").and(ElementMatchers.takesNoArguments())));
+ assertThat(actualAdvisorConfig.get(3).getPointcut(), is(ElementMatchers.named("call").and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
+ assertThat(actualAdvisorConfig.get(4).getPointcut(), is(ElementMatchers.named("call")
+ .and(ElementMatchers.takesArgument(0, ElementMatchers.named("value1"))).and(ElementMatchers.takesArgument(1, ElementMatchers.named("value2")))));
+ assertThat(actualAdvisorConfig.get(5).getPointcut(), is(ElementMatchers.named("staticCall").and(ElementMatchers.takesNoArguments())));
+ assertThat(actualAdvisorConfig.get(6).getPointcut(), is(ElementMatchers.named("staticCall").and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
+ assertThat(actualAdvisorConfig.get(7).getPointcut(), is(ElementMatchers.named("staticCall")
+ .and(ElementMatchers.takesArgument(0, ElementMatchers.named("value1"))).and(ElementMatchers.takesArgument(1, ElementMatchers.named("value2")))));
+
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
index 67027aa5c1d..f81e7fbcb15 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
@@ -68,14 +68,14 @@ public final class AgentTransformerTest {
AdvisorConfiguration result = new AdvisorConfiguration("org.apache.shardingsphere.agent.core.transformer.fixture.targeted.TargetObjectFixture");
result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), FooAdvice.class.getName()));
result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), BarAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callInstanceMethod"), FooAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callInstanceMethod"), BarAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callInstanceMethodWhenExceptionThrown"), FooAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callInstanceMethodWhenExceptionThrown"), BarAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callStaticMethod"), FooAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callStaticMethod"), BarAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callStaticMethodWhenExceptionThrown"), FooAdvice.class.getName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callStaticMethodWhenExceptionThrown"), BarAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("call"), FooAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("call"), BarAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callWhenExceptionThrown"), FooAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("callWhenExceptionThrown"), BarAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticCall"), FooAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticCall"), BarAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticCallWhenExceptionThrown"), FooAdvice.class.getName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticCallWhenExceptionThrown"), BarAdvice.class.getName()));
return result;
}
@@ -94,7 +94,7 @@ public final class AgentTransformerTest {
@Test
public void assertAdviceInstanceMethod() {
List<String> queue = new LinkedList<>();
- new TargetObjectFixture(new LinkedList<>()).callInstanceMethod(queue);
+ new TargetObjectFixture(new LinkedList<>()).call(queue);
assertThat(queue, is(Arrays.asList("foo before instance method", "bar before instance method", "on instance method", "foo after instance method", "bar after instance method")));
}
@@ -102,7 +102,7 @@ public final class AgentTransformerTest {
public void assertAdviceInstanceMethodWhenExceptionThrown() {
List<String> queue = new LinkedList<>();
try {
- new TargetObjectFixture(new LinkedList<>()).callInstanceMethodWhenExceptionThrown(queue);
+ new TargetObjectFixture(new LinkedList<>()).callWhenExceptionThrown(queue);
} catch (final UnsupportedOperationException ignored) {
}
assertThat(queue, is(Arrays.asList("foo before instance method", "bar before instance method",
@@ -112,7 +112,7 @@ public final class AgentTransformerTest {
@Test
public void assertAdviceStaticMethod() {
List<String> queue = new LinkedList<>();
- TargetObjectFixture.callStaticMethod(queue);
+ TargetObjectFixture.staticCall(queue);
assertThat(queue, is(Arrays.asList("foo before static method", "bar before static method", "on static method", "foo after static method", "bar after static method")));
}
@@ -120,7 +120,7 @@ public final class AgentTransformerTest {
public void assertAdviceStaticMethodWhenExceptionThrown() {
List<String> queue = new LinkedList<>();
try {
- TargetObjectFixture.callStaticMethodWhenExceptionThrown(queue);
+ TargetObjectFixture.staticCallWhenExceptionThrown(queue);
} catch (final UnsupportedOperationException ignored) {
}
assertThat(queue, is(Arrays.asList("foo before static method", "bar before static method",
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java
index 54a7e3b2b40..5352d448b2b 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/TargetObjectFixture.java
@@ -30,7 +30,7 @@ public final class TargetObjectFixture {
*
* @param queue queue
*/
- public void callInstanceMethod(final List<String> queue) {
+ public void call(final List<String> queue) {
queue.add("on instance method");
}
@@ -39,7 +39,7 @@ public final class TargetObjectFixture {
*
* @param queue queue
*/
- public void callInstanceMethodWhenExceptionThrown(final List<String> queue) {
+ public void callWhenExceptionThrown(final List<String> queue) {
throw new UnsupportedOperationException();
}
@@ -48,7 +48,7 @@ public final class TargetObjectFixture {
*
* @param queue queue
*/
- public static void callStaticMethod(final List<String> queue) {
+ public static void staticCall(final List<String> queue) {
queue.add("on static method");
}
@@ -57,7 +57,7 @@ public final class TargetObjectFixture {
*
* @param queue queue
*/
- public static void callStaticMethodWhenExceptionThrown(final List<String> queue) {
+ public static void staticCallWhenExceptionThrown(final List<String> queue) {
throw new UnsupportedOperationException();
}
}
diff --git a/agent/core/src/test/resources/advisors.yaml b/agent/core/src/test/resources/advisors.yaml
deleted file mode 100644
index ef945e7b5e9..00000000000
--- a/agent/core/src/test/resources/advisors.yaml
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-#
-
-advisors:
- - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
- advice: org.apache.shardingsphere.agent.metrics.core.advice.CommandExecutorTaskAdvice
- pointcuts:
- - name: run
- type: method
- - name: processException
- type: method
- - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
- advice: org.apache.shardingsphere.agent.metrics.core.advice.ChannelHandlerAdvice
- pointcuts:
- - name: channelActive
- type: method
- - name: channelRead
- type: method
- - name: channelInactive
- type: method
- - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
- advice: org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice
- pointcuts:
- - name: route
- type: method
- - target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager
- advice: org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice
- pointcuts:
- - name: commit
- type: method
- - name: rollback
- type: method
- - target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper
- advice: org.apache.shardingsphere.agent.metrics.core.advice.DataSourceAdvice
- pointcuts:
- - name: decorate
- type: method
diff --git a/agent/core/src/test/resources/conf/advisors.yaml b/agent/core/src/test/resources/conf/advisors.yaml
new file mode 100644
index 00000000000..c446b931c87
--- /dev/null
+++ b/agent/core/src/test/resources/conf/advisors.yaml
@@ -0,0 +1,54 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+advisors:
+ - target: org.apache.shardingsphere.agent.core.plugin.yaml.fixture.YamlTargetObjectFixture
+ advice: org.apache.shardingsphere.agent.core.plugin.yaml.fixture.YamlAdviceFixture
+ pointcuts:
+ - type: constructor
+ - type: constructor
+ params:
+ - index: 0
+ name: value
+ - name: call
+ type: method
+ - name: call
+ type: method
+ params:
+ - index: 0
+ name: value
+ - name: call
+ type: method
+ params:
+ - index: 0
+ name: value1
+ - index: 1
+ name: value2
+ - name: staticCall
+ type: method
+ - name: staticCall
+ type: method
+ params:
+ - index: 0
+ name: value
+ - name: staticCall
+ type: method
+ params:
+ - index: 0
+ name: value1
+ - index: 1
+ name: value2