@@ -38,7 +38,7 @@ public final class TestStatsReporter implements StatsReporter {
3838 private final Map <String , Double > gauges = new HashMap <>();
3939 private final Map <String , StatsAccumulator > timers = new HashMap <>();
4040
41- public void assertCounter (String name , Map <String , String > tags ) {
41+ public synchronized void assertCounter (String name , Map <String , String > tags ) {
4242 String metricName = getMetricName (name , tags );
4343 if (!counters .containsKey (metricName )) {
4444 fail (
@@ -49,7 +49,7 @@ public void assertCounter(String name, Map<String, String> tags) {
4949 }
5050 }
5151
52- public void assertNoMetric (String name , Map <String , String > tags ) {
52+ public synchronized void assertNoMetric (String name , Map <String , String > tags ) {
5353 String metricName = getMetricName (name , tags );
5454 if (counters .containsKey (metricName )) {
5555 fail (
@@ -60,7 +60,7 @@ public void assertNoMetric(String name, Map<String, String> tags) {
6060 }
6161 }
6262
63- public void assertCounter (String name , Map <String , String > tags , long expected ) {
63+ public synchronized void assertCounter (String name , Map <String , String > tags , long expected ) {
6464 String metricName = getMetricName (name , tags );
6565 AtomicLong accumulator = counters .get (metricName );
6666 if (accumulator == null ) {
@@ -73,11 +73,12 @@ public void assertCounter(String name, Map<String, String> tags, long expected)
7373 assertEquals (String .valueOf (accumulator .get ()), expected , accumulator .get ());
7474 }
7575
76- public void assertGauge (String name , Map <String , String > tags , double expected ) {
76+ public synchronized void assertGauge (String name , Map <String , String > tags , double expected ) {
7777 assertGauge (name , tags , val -> Math .abs (expected - val ) < 1e-3 );
7878 }
7979
80- public void assertGauge (String name , Map <String , String > tags , Predicate <Double > isExpected ) {
80+ public synchronized void assertGauge (
81+ String name , Map <String , String > tags , Predicate <Double > isExpected ) {
8182 String metricName = getMetricName (name , tags );
8283 Double value = gauges .get (metricName );
8384 if (value == null ) {
@@ -90,7 +91,7 @@ public void assertGauge(String name, Map<String, String> tags, Predicate<Double>
9091 assertTrue (String .valueOf (value ), isExpected .test (value ));
9192 }
9293
93- public void assertTimer (String name , Map <String , String > tags ) {
94+ public synchronized void assertTimer (String name , Map <String , String > tags ) {
9495 String metricName = getMetricName (name , tags );
9596 if (!timers .containsKey (metricName )) {
9697 fail (
@@ -101,7 +102,8 @@ public void assertTimer(String name, Map<String, String> tags) {
101102 }
102103 }
103104
104- public void assertTimerMinDuration (String name , Map <String , String > tags , Duration minDuration ) {
105+ public synchronized void assertTimerMinDuration (
106+ String name , Map <String , String > tags , Duration minDuration ) {
105107 String metricName = getMetricName (name , tags );
106108 StatsAccumulator value = timers .get (metricName );
107109 if (value == null ) {
@@ -134,7 +136,7 @@ public synchronized void reportGauge(String name, Map<String, String> tags, doub
134136 }
135137
136138 @ Override
137- public void reportTimer (
139+ public synchronized void reportTimer (
138140 String name , Map <String , String > tags , com .uber .m3 .util .Duration interval ) {
139141 String metricName = getMetricName (name , tags );
140142 StatsAccumulator value = timers .get (metricName );
@@ -147,7 +149,7 @@ public void reportTimer(
147149
148150 @ SuppressWarnings ("deprecation" )
149151 @ Override
150- public void reportHistogramValueSamples (
152+ public synchronized void reportHistogramValueSamples (
151153 String name ,
152154 Map <String , String > tags ,
153155 com .uber .m3 .tally .Buckets buckets ,
@@ -159,7 +161,7 @@ public void reportHistogramValueSamples(
159161
160162 @ SuppressWarnings ("deprecation" )
161163 @ Override
162- public void reportHistogramDurationSamples (
164+ public synchronized void reportHistogramDurationSamples (
163165 String name ,
164166 Map <String , String > tags ,
165167 com .uber .m3 .tally .Buckets buckets ,
0 commit comments