@@ -16,14 +16,16 @@ public class MetricsTest {
1616 @ Test
1717 public void whenMarkMeter_thenCorrectRates () throws InterruptedException {
1818 Meter meter = new Meter ();
19-
2019 long initCount = meter .getCount ();
20+
2121 assertThat (initCount , equalTo (0L ));
2222
2323 meter .mark ();
24+
2425 assertThat (meter .getCount (), equalTo (1L ));
2526
2627 meter .mark (20 );
28+
2729 assertThat (meter .getCount (), equalTo (21L ));
2830
2931 // not use assert for these rate values because they change every time when this test is run
@@ -40,6 +42,7 @@ public void whenMarkMeter_thenCorrectRates() throws InterruptedException {
4042 @ Test
4143 public void whenInitRatioGauge_thenCorrectRatio () {
4244 Gauge <Double > ratioGauge = new AttendanceRatioGauge (15 , 20 );
45+
4346 assertThat (ratioGauge .getValue (), equalTo (0.75 ));
4447 }
4548
@@ -48,43 +51,50 @@ public void whenUseCacheGauge_thenCorrectGauge() {
4851 Gauge <List <Long >> activeUsersGauge = new ActiveUsersGauge (15 , TimeUnit .MINUTES );
4952 List <Long > expected = new ArrayList <Long >();
5053 expected .add (12L );
54+
5155 assertThat (activeUsersGauge .getValue (), equalTo (expected ));
5256 }
5357
5458 @ Test
5559 public void whenUseDerivativeGauge_thenCorrectGaugeFromBase () {
5660 Gauge <List <Long >> activeUsersGauge = new ActiveUsersGauge (15 , TimeUnit .MINUTES );
5761 Gauge <Integer > activeUserCountGauge = new ActiveUserCountGauge (activeUsersGauge );
62+
5863 assertThat (activeUserCountGauge .getValue (), equalTo (1 ));
5964 }
6065
6166 @ Test
6267 public void whenIncDecCounter_thenCorrectCount () {
6368 Counter counter = new Counter ();
64-
6569 long initCount = counter .getCount ();
70+
6671 assertThat (initCount , equalTo (0L ));
6772
6873 counter .inc ();
74+
6975 assertThat (counter .getCount (), equalTo (1L ));
7076
7177 counter .inc (11 );
78+
7279 assertThat (counter .getCount (), equalTo (12L ));
7380
7481 counter .dec ();
82+
7583 assertThat (counter .getCount (), equalTo (11L ));
7684
7785 counter .dec (6 );
86+
7887 assertThat (counter .getCount (), equalTo (5L ));
7988 }
8089
8190 @ Test
8291 public void whenUpdateHistogram_thenCorrectDistributionData () {
8392 Histogram histogram = new Histogram (new UniformReservoir ());
84-
8593 histogram .update (5 );
8694 long count1 = histogram .getCount ();
95+
8796 assertThat (count1 , equalTo (1L ));
97+
8898 Snapshot snapshot1 = histogram .getSnapshot ();
8999 assertThat (snapshot1 .getValues ().length , equalTo (1 ));
90100 assertThat (snapshot1 .getValues ()[0 ], equalTo (5L ));
@@ -101,8 +111,11 @@ public void whenUpdateHistogram_thenCorrectDistributionData() {
101111
102112 histogram .update (20 );
103113 long count2 = histogram .getCount ();
114+
104115 assertThat (count2 , equalTo (2L ));
116+
105117 Snapshot snapshot2 = histogram .getSnapshot ();
118+
106119 assertThat (snapshot2 .getValues ().length , equalTo (2 ));
107120 assertThat (snapshot2 .getValues ()[0 ], equalTo (5L ));
108121 assertThat (snapshot2 .getValues ()[1 ], equalTo (20L ));
@@ -121,18 +134,19 @@ public void whenUpdateHistogram_thenCorrectDistributionData() {
121134 @ Test
122135 public void whenUseTimer_thenCorrectTimerContexts () throws InterruptedException {
123136 Timer timer = new Timer ();
124-
125137 Timer .Context context1 = timer .time ();
126138 TimeUnit .SECONDS .sleep (5 );
127139
128140 long elapsed1 = context1 .stop ();
141+
129142 assertEquals (5000000000L , elapsed1 , 1000000 );
130143 assertThat (timer .getCount (), equalTo (1L ));
131144 assertEquals (0.2 , timer .getMeanRate (), 0.1 );
132145
133146 Timer .Context context2 = timer .time ();
134147 TimeUnit .SECONDS .sleep (2 );
135148 context2 .close ();
149+
136150 assertThat (timer .getCount (), equalTo (2L ));
137151 assertEquals (0.3 , timer .getMeanRate (), 0.1 );
138152 }
0 commit comments