Skip to content

Commit 5dd6ef6

Browse files
authored
Polish (#3211)
1 parent 87ce354 commit 5dd6ef6

File tree

7 files changed

+37
-39
lines changed

7 files changed

+37
-39
lines changed

implementations/micrometer-registry-statsd/src/test/java/io/micrometer/statsd/StatsdMeterRegistryPublishTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,18 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
279279
@ParameterizedTest
280280
@EnumSource(StatsdProtocol.class)
281281
void receiveParallelMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
282-
final int N = 10;
282+
final int n = 10;
283283

284284
skipUdsTestOnWindows(protocol);
285-
serverLatch = new CountDownLatch(N);
285+
serverLatch = new CountDownLatch(n);
286286
server = startServer(protocol, 0);
287287
final int port = getPort(protocol);
288288

289289
meterRegistry = new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);
290290
startRegistryAndWaitForClient();
291291
Counter counter = Counter.builder("my.counter").register(meterRegistry);
292292

293-
IntStream.range(0, N).parallel().forEach(ignored -> counter.increment());
293+
IntStream.range(0, n).parallel().forEach(ignored -> counter.increment());
294294

295295
assertThat(serverLatch.await(3, TimeUnit.SECONDS)).isTrue();
296296
}

micrometer-core/src/main/java/io/micrometer/core/instrument/composite/CompositeTimer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class CompositeTimer extends AbstractCompositeMeter<Timer> implements Timer {
4646

4747
@Override
4848
public void record(long amount, TimeUnit unit) {
49-
for (Timer ds : getChildren()) {
50-
ds.record(amount, unit);
49+
for (Timer timer : getChildren()) {
50+
timer.record(amount, unit);
5151
}
5252
}
5353

5454
@Override
5555
public void record(Duration duration) {
56-
for (Timer ds : getChildren()) {
57-
ds.record(duration);
56+
for (Timer timer : getChildren()) {
57+
timer.record(duration);
5858
}
5959
}
6060

micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowMax.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class TimeWindowMax {
3838

3939
private final long durationBetweenRotatesMillis;
4040

41-
private AtomicLong[] ringBuffer;
41+
private final AtomicLong[] ringBuffer;
4242

4343
private int currentBucket;
4444

micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/TimeWindowSum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TimeWindowSum {
3232

3333
private final long durationBetweenRotatesMillis;
3434

35-
private AtomicLong[] ringBuffer;
35+
private final AtomicLong[] ringBuffer;
3636

3737
private int currentBucket;
3838

micrometer-core/src/main/java/io/micrometer/core/instrument/push/PushMeterRegistry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ private void publishSafely() {
5454
publish();
5555
}
5656
catch (Throwable e) {
57-
logger.warn("Unexpected exception thrown while publishing metrics for " + this.getClass().getSimpleName(),
58-
e);
57+
logger.warn("Unexpected exception thrown while publishing metrics for " + getClass().getSimpleName(), e);
5958
}
6059
}
6160

@@ -72,7 +71,7 @@ public void start(ThreadFactory threadFactory) {
7271
stop();
7372

7473
if (config.enabled()) {
75-
logger.info("publishing metrics for " + this.getClass().getSimpleName() + " every "
74+
logger.info("publishing metrics for " + getClass().getSimpleName() + " every "
7675
+ TimeUtils.format(config.step()));
7776

7877
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory);

micrometer-core/src/test/java/io/micrometer/core/aop/CountedAspectTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void countedWithSuccessfulMetrics() {
5656
countedService.succeedWithMetrics();
5757

5858
Counter counter = meterRegistry.get("metric.success").tag("method", "succeedWithMetrics")
59-
.tag("class", this.getClass().getName() + "$CountedService").tag("extra", "tag")
60-
.tag("result", "success").counter();
59+
.tag("class", getClass().getName() + "$CountedService").tag("extra", "tag").tag("result", "success")
60+
.counter();
6161

6262
assertThat(counter.count()).isOne();
6363
assertThat(counter.getId().getDescription()).isNull();
@@ -82,7 +82,7 @@ void countedWithFailure() {
8282
}
8383

8484
Counter counter = meterRegistry.get("metric.failing").tag("method", "fail")
85-
.tag("class", this.getClass().getName() + "$CountedService").tag("exception", "RuntimeException")
85+
.tag("class", getClass().getName() + "$CountedService").tag("exception", "RuntimeException")
8686
.tag("result", "failure").counter();
8787

8888
assertThat(counter.count()).isOne();
@@ -119,14 +119,14 @@ void countedWithSuccessfulMetricsWhenCompleted() {
119119
CompletableFuture<?> completableFuture = asyncCountedService.succeedWithMetrics(guardedResult);
120120

121121
assertThat(meterRegistry.find("metric.success").tag("method", "succeedWithMetrics")
122-
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
122+
.tag("class", getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
123123
.tag("exception", "none").tag("result", "success").counter()).isNull();
124124

125125
guardedResult.complete();
126126
completableFuture.join();
127127

128128
Counter counterAfterCompletion = meterRegistry.get("metric.success").tag("method", "succeedWithMetrics")
129-
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
129+
.tag("class", getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
130130
.tag("exception", "none").tag("result", "success").counter();
131131

132132
assertThat(counterAfterCompletion.count()).isOne();
@@ -139,14 +139,14 @@ void countedWithFailureWhenCompleted() {
139139
CompletableFuture<?> completableFuture = asyncCountedService.fail(guardedResult);
140140

141141
assertThat(meterRegistry.find("metric.failing").tag("method", "fail")
142-
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
142+
.tag("class", getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
143143
.tag("result", "failure").counter()).isNull();
144144

145145
guardedResult.complete(new RuntimeException());
146146
assertThatThrownBy(completableFuture::join).isInstanceOf(RuntimeException.class);
147147

148148
Counter counter = meterRegistry.get("metric.failing").tag("method", "fail")
149-
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
149+
.tag("class", getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
150150
.tag("result", "failure").counter();
151151

152152
assertThat(counter.count()).isOne();

micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void timeMethod() {
5050

5151
service.call();
5252

53-
assertThat(registry.get("call").tag("class", this.getClass().getName() + "$TimedService").tag("method", "call")
53+
assertThat(registry.get("call").tag("class", getClass().getName() + "$TimedService").tag("method", "call")
5454
.tag("extra", "tag").timer().count()).isEqualTo(1);
5555
}
5656

@@ -79,7 +79,7 @@ void timeMethodWithLongTaskTimer() {
7979

8080
service.longCall();
8181

82-
assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$TimedService")
82+
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$TimedService")
8383
.tag("method", "longCall").tag("extra", "tag").longTaskTimers().size()).isEqualTo(1);
8484
}
8585

@@ -95,7 +95,7 @@ void timeMethodFailure() {
9595
service.call();
9696

9797
assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
98-
failingRegistry.get("call").tag("class", this.getClass().getName() + "$TimedService").tag("method", "call")
98+
failingRegistry.get("call").tag("class", getClass().getName() + "$TimedService").tag("method", "call")
9999
.tag("extra", "tag").timer();
100100
});
101101
}
@@ -112,7 +112,7 @@ void timeMethodFailureWithLongTaskTimer() {
112112
service.longCall();
113113

114114
assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
115-
failingRegistry.get("longCall").tag("class", this.getClass().getName() + "$TimedService")
115+
failingRegistry.get("longCall").tag("class", getClass().getName() + "$TimedService")
116116
.tag("method", "longCall").tag("extra", "tag").longTaskTimer();
117117
});
118118
}
@@ -129,14 +129,14 @@ void timeMethodWhenCompleted() {
129129
GuardedResult guardedResult = new GuardedResult();
130130
CompletableFuture<?> completableFuture = service.call(guardedResult);
131131

132-
assertThat(registry.find("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
133-
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer()).isNull();
132+
assertThat(registry.find("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
133+
.tag("extra", "tag").tag("exception", "none").timer()).isNull();
134134

135135
guardedResult.complete();
136136
completableFuture.join();
137137

138-
assertThat(registry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
139-
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer().count()).isEqualTo(1);
138+
assertThat(registry.get("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
139+
.tag("extra", "tag").tag("exception", "none").timer().count()).isEqualTo(1);
140140
}
141141

142142
@Test
@@ -151,15 +151,14 @@ void timeMethodWhenCompletedExceptionally() {
151151
GuardedResult guardedResult = new GuardedResult();
152152
CompletableFuture<?> completableFuture = service.call(guardedResult);
153153

154-
assertThat(registry.find("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
155-
.tag("method", "call").tag("extra", "tag").tag("exception", "NullPointerException").timer()).isNull();
154+
assertThat(registry.find("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
155+
.tag("extra", "tag").tag("exception", "NullPointerException").timer()).isNull();
156156

157157
guardedResult.complete(new NullPointerException());
158158
catchThrowableOfType(completableFuture::join, CompletionException.class);
159159

160-
assertThat(registry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
161-
.tag("method", "call").tag("extra", "tag").tag("exception", "NullPointerException").timer().count())
162-
.isEqualTo(1);
160+
assertThat(registry.get("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
161+
.tag("extra", "tag").tag("exception", "NullPointerException").timer().count()).isEqualTo(1);
163162
}
164163

165164
@Test
@@ -174,13 +173,13 @@ void timeMethodWithLongTaskTimerWhenCompleted() {
174173
GuardedResult guardedResult = new GuardedResult();
175174
CompletableFuture<?> completableFuture = service.longCall(guardedResult);
176175

177-
assertThat(registry.find("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
176+
assertThat(registry.find("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
178177
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(1);
179178

180179
guardedResult.complete();
181180
completableFuture.join();
182181

183-
assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
182+
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
184183
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(0);
185184
}
186185

@@ -196,13 +195,13 @@ void timeMethodWithLongTaskTimerWhenCompletedExceptionally() {
196195
GuardedResult guardedResult = new GuardedResult();
197196
CompletableFuture<?> completableFuture = service.longCall(guardedResult);
198197

199-
assertThat(registry.find("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
198+
assertThat(registry.find("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
200199
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(1);
201200

202201
guardedResult.complete(new NullPointerException());
203202
catchThrowableOfType(completableFuture::join, CompletionException.class);
204203

205-
assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
204+
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
206205
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(0);
207206
}
208207

@@ -220,8 +219,8 @@ void timeMethodFailureWhenCompletedExceptionally() {
220219
guardedResult.complete();
221220
completableFuture.join();
222221

223-
assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(
224-
() -> failingRegistry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
222+
assertThatExceptionOfType(MeterNotFoundException.class)
223+
.isThrownBy(() -> failingRegistry.get("call").tag("class", getClass().getName() + "$AsyncTimedService")
225224
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer());
226225
}
227226

@@ -240,7 +239,7 @@ void timeMethodFailureWithLongTaskTimerWhenCompleted() {
240239
completableFuture.join();
241240

242241
assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
243-
failingRegistry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
242+
failingRegistry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
244243
.tag("method", "longCall").tag("extra", "tag").longTaskTimer();
245244
});
246245
}

0 commit comments

Comments
 (0)