Skip to content

Commit bb2f27a

Browse files
authored
Polish (#5886)
Signed-off-by: Johnny Lim <[email protected]>
1 parent 27a98e4 commit bb2f27a

File tree

8 files changed

+25
-40
lines changed

8 files changed

+25
-40
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/logging/LoggingMeterRegistry.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.stream.StreamSupport;
4343

4444
import static io.micrometer.core.instrument.util.DoubleFormat.decimalOrNan;
45-
import static io.micrometer.core.instrument.util.DoubleFormat.wholeOrDecimal;
4645
import static java.util.stream.Collectors.joining;
4746

4847
/**
@@ -147,24 +146,24 @@ protected void publish() {
147146
int activeTasks = longTaskTimer.activeTasks();
148147
if (!config.logInactive() && activeTasks == 0)
149148
return;
150-
loggingSink.accept(print.id() + " active=" + wholeOrDecimal(activeTasks) + " duration="
149+
loggingSink.accept(print.id() + " active=" + activeTasks + " duration="
151150
+ print.time(longTaskTimer.duration(getBaseTimeUnit())));
152151
}, timeGauge -> {
153152
double value = timeGauge.value(getBaseTimeUnit());
154153
if (!config.logInactive() && value == 0)
155154
return;
156155
loggingSink.accept(print.id() + " value=" + print.time(value));
157-
}, counter -> {
158-
double count = counter.count();
156+
}, functionCounter -> {
157+
double count = functionCounter.count();
159158
if (!config.logInactive() && count == 0)
160159
return;
161160
loggingSink.accept(print.id() + " throughput=" + print.rate(count));
162-
}, timer -> {
163-
double count = timer.count();
161+
}, functionTimer -> {
162+
double count = functionTimer.count();
164163
if (!config.logInactive() && count == 0)
165164
return;
166165
loggingSink.accept(print.id() + " throughput=" + print.unitlessRate(count) + " mean="
167-
+ print.time(timer.mean(getBaseTimeUnit())));
166+
+ print.time(functionTimer.mean(getBaseTimeUnit())));
168167
}, meter -> loggingSink.accept(writeMeter(meter, print)));
169168
});
170169
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/jvm/ExecutorServiceMetricsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ void queuedSubmissionsAreIncludedInExecutorQueuedMetric() {
284284
busy.set(false);
285285

286286
assertThat(queued).isEqualTo(2.0);
287+
288+
pool.shutdown();
287289
}
288290

289291
@SuppressWarnings("unchecked")

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetricsAdminTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void shouldCreateMeters() {
4949
MeterRegistry registry = new SimpleMeterRegistry();
5050

5151
metrics.bindTo(registry);
52-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
52+
assertThat(registry.getMeters()).isNotEmpty()
5353
.extracting(meter -> meter.getId().getName())
5454
.allMatch(s -> s.startsWith(METRIC_NAME_PREFIX));
5555
}
@@ -63,7 +63,7 @@ void shouldCreateMetersWithTags() {
6363

6464
metrics.bindTo(registry);
6565

66-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
66+
assertThat(registry.getMeters()).isNotEmpty()
6767
.extracting(meter -> meter.getId().getTag("app"))
6868
.allMatch(s -> s.equals("myapp"));
6969
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetricsConsumerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void shouldCreateMeters() {
5151
MeterRegistry registry = new SimpleMeterRegistry();
5252

5353
metrics.bindTo(registry);
54-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
54+
assertThat(registry.getMeters()).isNotEmpty()
5555
.extracting(meter -> meter.getId().getName())
5656
.allMatch(s -> s.startsWith(METRIC_NAME_PREFIX));
5757
}
@@ -65,7 +65,7 @@ void shouldCreateMetersWithTags() {
6565

6666
metrics.bindTo(registry);
6767

68-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
68+
assertThat(registry.getMeters()).isNotEmpty()
6969
.extracting(meter -> meter.getId().getTag("app"))
7070
.allMatch(s -> s.equals("myapp"));
7171
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetricsIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void shouldManageProducerAndConsumerMetrics() {
6868
// end::producer_setup[]
6969

7070
int producerMetrics = registry.getMeters().size();
71-
assertThat(registry.getMeters()).hasSizeGreaterThan(0);
71+
assertThat(registry.getMeters()).isNotEmpty();
7272
assertThat(registry.getMeters()).extracting(m -> m.getId().getTag("kafka.version")).allMatch(v -> !v.isEmpty());
7373

7474
// tag::consumer_setup[]

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetricsProducerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void shouldCreateMeters() {
5151
MeterRegistry registry = new SimpleMeterRegistry();
5252

5353
metrics.bindTo(registry);
54-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
54+
assertThat(registry.getMeters()).isNotEmpty()
5555
.extracting(meter -> meter.getId().getName())
5656
.allMatch(s -> s.startsWith(METRIC_NAME_PREFIX));
5757
}
@@ -65,7 +65,7 @@ void shouldCreateMetersWithTags() {
6565

6666
metrics.bindTo(registry);
6767

68-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
68+
assertThat(registry.getMeters()).isNotEmpty()
6969
.extracting(meter -> meter.getId().getTag("app"))
7070
.allMatch(s -> s.equals("myapp"));
7171
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaStreamsMetricsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void shouldCreateMeters() {
5252
MeterRegistry registry = new SimpleMeterRegistry();
5353

5454
metrics.bindTo(registry);
55-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
55+
assertThat(registry.getMeters()).isNotEmpty()
5656
.extracting(meter -> meter.getId().getName())
5757
.allMatch(s -> s.startsWith(METRIC_NAME_PREFIX));
5858
}
@@ -67,7 +67,7 @@ void shouldCreateMetersWithTags() {
6767

6868
metrics.bindTo(registry);
6969

70-
assertThat(registry.getMeters()).hasSizeGreaterThan(0)
70+
assertThat(registry.getMeters()).isNotEmpty()
7171
.extracting(meter -> meter.getId().getTag("app"))
7272
.allMatch(s -> s.equals("myapp"));
7373
}

micrometer-core/src/test/java/io/micrometer/core/instrument/logging/LoggingMeterRegistryTest.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void time() {
129129
}
130130

131131
@Test
132-
void writeMeterUnitLessValue() {
132+
void writeMeterUnitlessValue() {
133133
String expectedResult = "meter.1{} value=0, throughput=0.5/s";
134134

135135
Measurement m1 = new Measurement(() -> 0d, Statistic.VALUE);
@@ -191,21 +191,13 @@ void printerValueWhenGaugeIsInfinityShouldPrintInfinity() {
191191
}
192192

193193
@Test
194-
void publishShouldPrintDeltaCountAndThroughputWithBaseUnitWhenMeterIsCounter() {
194+
void publishShouldPrintThroughputWithBaseUnitWhenMeterIsCounter() {
195195
Counter.builder("my.counter").baseUnit("sheep").register(recordingRegistry).increment(30);
196196
clock.add(config.step());
197197
recordingRegistry.publish();
198198
assertThat(recordingRegistry.getLogs()).containsExactly("my.counter{} throughput=0.5 sheep/s");
199199
}
200200

201-
@Test
202-
void publishShouldPrintDeltaCountAsDecimalWhenMeterIsCounterAndCountIsDecimal() {
203-
recordingRegistry.counter("my.counter").increment(0.5);
204-
clock.add(config.step());
205-
recordingRegistry.publish();
206-
assertThat(recordingRegistry.getLogs()).containsExactly("my.counter{} throughput=0.008333/s");
207-
}
208-
209201
@Test
210202
void publishShouldPrintValueWhenMeterIsGauge() {
211203
Gauge.builder("my.gauge", () -> 100).baseUnit("C").register(recordingRegistry);
@@ -214,7 +206,7 @@ void publishShouldPrintValueWhenMeterIsGauge() {
214206
}
215207

216208
@Test
217-
void publishShouldPrintDeltaCountAndThroughputWhenMeterIsTimer() {
209+
void publishShouldPrintThroughputWhenMeterIsTimer() {
218210
var timer = recordingRegistry.timer("my.timer");
219211
IntStream.rangeClosed(1, 30).forEach(t -> timer.record(1, SECONDS));
220212
clock.add(config.step());
@@ -240,7 +232,7 @@ void publishShouldPrintValueWhenMeterIsTimeGauge() {
240232
}
241233

242234
@Test
243-
void publishShouldPrintDeltaCountAndThroughputWhenMeterIsSummary() {
235+
void publishShouldPrintThroughputWhenMeterIsSummary() {
244236
var summary = recordingRegistry.summary("my.summary");
245237
IntStream.rangeClosed(1, 30).forEach(t -> summary.record(1));
246238
clock.add(config.step());
@@ -249,7 +241,7 @@ void publishShouldPrintDeltaCountAndThroughputWhenMeterIsSummary() {
249241
}
250242

251243
@Test
252-
void publishShouldPrintDeltaCountAndThroughputWithBaseUnitWhenMeterIsFunctionCounter() {
244+
void publishShouldPrintThroughputWithBaseUnitWhenMeterIsFunctionCounter() {
253245
FunctionCounter.builder("my.function-counter", new AtomicDouble(), d -> 30)
254246
.baseUnit("sheep")
255247
.register(recordingRegistry);
@@ -259,15 +251,7 @@ void publishShouldPrintDeltaCountAndThroughputWithBaseUnitWhenMeterIsFunctionCou
259251
}
260252

261253
@Test
262-
void publishShouldPrintDeltaCountAsDecimalWhenMeterIsFunctionCounterAndCountIsDecimal() {
263-
recordingRegistry.more().counter("my.function-counter", emptyList(), new AtomicDouble(), d -> 0.5);
264-
clock.add(config.step());
265-
recordingRegistry.publish();
266-
assertThat(recordingRegistry.getLogs()).containsExactly("my.function-counter{} throughput=0.008333/s");
267-
}
268-
269-
@Test
270-
void publishShouldPrintDeltaCountAndThroughputWhenMeterIsFunctionTimer() {
254+
void publishShouldPrintThroughputWhenMeterIsFunctionTimer() {
271255
recordingRegistry.more().timer("my.function-timer", emptyList(), new AtomicDouble(), d -> 30, d -> 30, SECONDS);
272256
clock.add(config.step());
273257
recordingRegistry.publish();
@@ -293,7 +277,7 @@ void publishShouldNotPrintAnythingWhenRegistryIsDisabled() {
293277
}
294278

295279
@Test
296-
void publishShouldNotPrintAnythingWhenStepCountIsZeroAndLogsInactiveIsDisabled() {
280+
void publishShouldNotPrintAnythingWhenStepCountIsZeroAndLogInactiveIsDisabled() {
297281
recordingRegistry.counter("my.counter");
298282
recordingRegistry.timer("my.timer");
299283
recordingRegistry.summary("my.summary");
@@ -306,7 +290,7 @@ void publishShouldNotPrintAnythingWhenStepCountIsZeroAndLogsInactiveIsDisabled()
306290
}
307291

308292
@Test
309-
void publishShouldPrintMetersWithZeroStepCountWhenLogsInactiveIsEnabled() {
293+
void publishShouldPrintMetersWithZeroStepCountWhenLogInactiveIsEnabled() {
310294
config.set("logInactive", "true");
311295
recordingRegistry.counter("my.counter");
312296
recordingRegistry.timer("my.timer");

0 commit comments

Comments
 (0)