Skip to content

Commit

Permalink
Refactor reflection agent test cases (apache#23064)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 23, 2022
1 parent 684751f commit 7677c79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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));
}
}

0 comments on commit 7677c79

Please sign in to comment.