11package com .baeldung .metrics .servo ;
22
3+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
4+ import static java .util .concurrent .TimeUnit .SECONDS ;
5+ import static java .util .stream .Collectors .toMap ;
6+ import static org .hamcrest .Matchers .allOf ;
7+ import static org .hamcrest .Matchers .containsInAnyOrder ;
8+ import static org .hamcrest .Matchers .hasEntry ;
9+ import static org .junit .Assert .assertEquals ;
10+ import static org .junit .Assert .assertThat ;
11+
12+ import java .util .Map ;
13+
14+ import org .junit .Ignore ;
15+ import org .junit .Test ;
16+
317import com .netflix .servo .monitor .BasicCounter ;
418import com .netflix .servo .monitor .BasicGauge ;
519import com .netflix .servo .monitor .BasicInformational ;
1731import com .netflix .servo .monitor .StepCounter ;
1832import com .netflix .servo .monitor .Stopwatch ;
1933import com .netflix .servo .stats .StatsConfig ;
20- import org .junit .Ignore ;
21- import org .junit .Test ;
22-
23- import java .util .Map ;
24-
25- import static java .util .concurrent .TimeUnit .SECONDS ;
26- import static java .util .stream .Collectors .toMap ;
27- import static org .hamcrest .Matchers .allOf ;
28- import static org .hamcrest .Matchers .containsInAnyOrder ;
29- import static org .hamcrest .Matchers .hasEntry ;
30- import static org .junit .Assert .assertEquals ;
31- import static org .junit .Assert .assertThat ;
3234
3335public class MetricTypeTest {
3436
@@ -104,17 +106,18 @@ public void givenPeakRateCounter_whenManipulate_thenPeakRateReturn() throws Exce
104106 public void givenTimer_whenExecuteTask_thenTimerUpdated () throws Exception {
105107 BasicTimer timer = new BasicTimer (MonitorConfig
106108 .builder ("test" )
107- .build (), SECONDS );
109+ .build (), MILLISECONDS );
108110
109111 Stopwatch stopwatch = timer .start ();
110- SECONDS .sleep (1 );
111- timer .record (2 , SECONDS );
112+ MILLISECONDS .sleep (1 );
113+ timer .record (2 , MILLISECONDS );
112114 stopwatch .stop ();
113115
114- assertEquals ("timer should count 1 second " , 1 , timer
116+ assertEquals ("timer should count 1 millisecond " , 1 , timer
115117 .getValue ()
116118 .intValue ());
117- assertEquals ("timer should count 3 seconds in total" , 3.0 , timer .getTotalTime (), 0.01 );
119+ assertEquals ("timer should count 3 millisecond in total" , 3 , timer .getTotalTime ()
120+ .intValue ());
118121 assertEquals ("timer should record 2 updates" , 2 , timer
119122 .getCount ()
120123 .intValue ());
@@ -158,6 +161,7 @@ private static String getMonitorTagValue(Monitor monitor, String tagKey) {
158161 }
159162
160163 @ Test
164+ //==
161165 public void givenStatsTimer_whenExecuteTask_thenStatsCalculated () throws Exception {
162166 System .setProperty ("netflix.servo" , "1000" );
163167 StatsTimer timer = new StatsTimer (MonitorConfig
@@ -171,20 +175,20 @@ public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Excepti
171175 .withPublishMean (true )
172176 .withPublishStdDev (true )
173177 .withPublishVariance (true )
174- .build (), SECONDS );
178+ .build (), MILLISECONDS );
175179
176180 Stopwatch stopwatch = timer .start ();
177- SECONDS .sleep (1 );
178- timer .record (3 , SECONDS );
181+ MILLISECONDS .sleep (1 );
182+ timer .record (3 , MILLISECONDS );
179183 stopwatch .stop ();
180184
181185 stopwatch = timer .start ();
182- timer .record (6 , SECONDS );
183- SECONDS .sleep (2 );
186+ timer .record (6 , MILLISECONDS );
187+ MILLISECONDS .sleep (2 );
184188 stopwatch .stop ();
185189
186- assertEquals ("timer should count 12 seconds in total" , 12 , timer .getTotalTime ());
187- assertEquals ("timer should count 12 seconds in total" , 12 , timer .getTotalMeasurement ());
190+ assertEquals ("timer should count 12 milliseconds in total" , 12 , timer .getTotalTime ());
191+ assertEquals ("timer should count 12 milliseconds in total" , 12 , timer .getTotalMeasurement ());
188192 assertEquals ("timer should record 4 updates" , 4 , timer .getCount ());
189193 assertEquals ("stats timer value time-cost/update should be 2" , 3 , timer
190194 .getValue ()
0 commit comments