|
5 | 5 | import org.junit.Ignore; |
6 | 6 | import org.junit.Test; |
7 | 7 |
|
8 | | -import java.util.HashMap; |
9 | 8 | import java.util.Map; |
10 | 9 |
|
11 | 10 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 11 | +import static java.util.stream.Collectors.toMap; |
12 | 12 | import static org.hamcrest.Matchers.*; |
13 | 13 | import static org.junit.Assert.assertEquals; |
14 | 14 | import static org.junit.Assert.assertThat; |
@@ -123,15 +123,14 @@ public void givenBucketTimer_whenRecord_thenStatsCalculated() throws Exception { |
123 | 123 | .getTotalTime() |
124 | 124 | .intValue()); |
125 | 125 |
|
126 | | - final Map<String, Long> metricMap = new HashMap<>(3); |
127 | | - timer |
| 126 | + final Map<String, Long> metricMap = timer |
128 | 127 | .getMonitors() |
129 | 128 | .stream() |
130 | 129 | .filter(monitor -> monitor |
131 | 130 | .getConfig() |
132 | 131 | .getTags() |
133 | 132 | .containsKey("servo.bucket")) |
134 | | - .forEach(monitor -> metricMap.put(getMonitorTagValue(monitor, "servo.bucket"), (Long) monitor.getValue())); |
| 133 | + .collect(toMap(monior -> getMonitorTagValue(monior, "servo.bucket"), monitor -> (Long) monitor.getValue())); |
135 | 134 |
|
136 | 135 | assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L))); |
137 | 136 | } |
@@ -177,10 +176,10 @@ public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Excepti |
177 | 176 | .getValue() |
178 | 177 | .intValue()); |
179 | 178 |
|
180 | | - final Map<String, Number> metricMap = new HashMap<>(10); |
181 | | - timer |
| 179 | + final Map<String, Number> metricMap = timer |
182 | 180 | .getMonitors() |
183 | | - .forEach(monitor -> metricMap.put(getMonitorTagValue(monitor, "statistic"), (Number) monitor.getValue())); |
| 181 | + .stream() |
| 182 | + .collect(toMap(monitor -> getMonitorTagValue(monitor, "statistic"), monitor -> (Number) monitor.getValue())); |
184 | 183 |
|
185 | 184 | assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90")); |
186 | 185 | } |
|
0 commit comments