Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reflection agent test cases #23064

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
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;

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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
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;

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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
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;

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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
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;

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));
}
}