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/23 11:04:08 UTC
[shardingsphere] branch master updated: Refactor reflection agent test cases (#23064)
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 7677c79b68f Refactor reflection agent test cases (#23064)
7677c79b68f is described below
commit 7677c79b68f6a7df19b05137776db8a195a165b2
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Dec 23 19:04:01 2022 +0800
Refactor reflection agent test cases (#23064)
---
.../agent/metrics/prometheus/wrapper/type/CounterWrapperTest.java | 6 +++---
.../agent/metrics/prometheus/wrapper/type/GaugeWrapperTest.java | 6 +++---
.../agent/metrics/prometheus/wrapper/type/HistogramWrapperTest.java | 6 +++---
.../agent/metrics/prometheus/wrapper/type/SummaryWrapperTest.java | 6 +++---
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/CounterWrapperTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/CounterWrapperTest.java
index c902f087a24..8437c68f1b9 100644
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/CounterWrapperTest.java
+++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/CounterWrapperTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;
import io.prometheus.client.Counter;
-import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -27,12 +27,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class CounterWrapperTest {
@Test
- public void assertCreate() {
+ public void assertCreate() throws ReflectiveOperationException {
Counter counter = Counter.build().name("a").help("help").create();
CounterWrapper counterWrapper = new CounterWrapper(counter);
counterWrapper.inc();
counterWrapper.inc(1);
- counter = (Counter) AgentReflectionUtil.getFieldValue(counterWrapper, "counter");
+ counter = (Counter) Plugins.getMemberAccessor().get(CounterWrapper.class.getDeclaredField("counter"), counterWrapper);
assertThat(counter.get(), is(2.0));
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/GaugeWrapperTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/GaugeWrapperTest.java
index ec260526602..31325d8f207 100644
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/GaugeWrapperTest.java
+++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/GaugeWrapperTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;
import io.prometheus.client.Gauge;
-import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -27,12 +27,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class GaugeWrapperTest {
@Test
- public void assertCreate() {
+ public void assertCreate() throws ReflectiveOperationException {
Gauge gauge = Gauge.build().name("a").help("help").create();
GaugeWrapper gaugeWrapper = new GaugeWrapper(gauge);
gaugeWrapper.inc();
gaugeWrapper.inc(1);
- gauge = (Gauge) AgentReflectionUtil.getFieldValue(gaugeWrapper, "gauge");
+ gauge = (Gauge) Plugins.getMemberAccessor().get(GaugeWrapper.class.getDeclaredField("gauge"), gaugeWrapper);
assertThat(gauge.get(), is(2.0));
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/HistogramWrapperTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/HistogramWrapperTest.java
index eb2d42f07d1..3b3564f310f 100644
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/HistogramWrapperTest.java
+++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/HistogramWrapperTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;
import io.prometheus.client.Histogram;
-import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -27,11 +27,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class HistogramWrapperTest {
@Test
- public void assertCreate() {
+ public void assertCreate() throws ReflectiveOperationException {
Histogram histogram = Histogram.build().name("a").help("help").create();
HistogramWrapper histogramWrapper = new HistogramWrapper(histogram);
histogramWrapper.observe(1);
- histogram = (Histogram) AgentReflectionUtil.getFieldValue(histogramWrapper, "histogram");
+ histogram = (Histogram) Plugins.getMemberAccessor().get(HistogramWrapper.class.getDeclaredField("histogram"), histogramWrapper);
assertThat(histogram.collect().size(), is(1));
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/SummaryWrapperTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/SummaryWrapperTest.java
index a8cb2b9b6fb..abc2221d39e 100644
--- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/SummaryWrapperTest.java
+++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/type/SummaryWrapperTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;
import io.prometheus.client.Summary;
-import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -27,10 +27,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class SummaryWrapperTest {
@Test
- public void assertCreate() {
+ public void assertCreate() throws ReflectiveOperationException {
SummaryWrapper summaryWrapper = new SummaryWrapper(Summary.build().name("a").help("help").create());
summaryWrapper.observe(1);
- Summary summary = (Summary) AgentReflectionUtil.getFieldValue(summaryWrapper, "summary");
+ Summary summary = (Summary) Plugins.getMemberAccessor().get(SummaryWrapper.class.getDeclaredField("summary"), summaryWrapper);
assertThat(summary.collect().size(), is(1));
}
}