Skip to content

Commit 433b72d

Browse files
izeyebclozel
authored andcommitted
Polish gh-29883
1 parent 7bc731d commit 433b72d

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

Diff for: framework-docs/modules/ROOT/pages/integration/observability.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ By default, the following `KeyValues` are created:
103103
|Name | Description
104104
|`code.function` _(required)_|Name of Java `Method` that is scheduled for execution.
105105
|`code.namespace` _(required)_|Canonical name of the class of the bean instance that holds the scheduled method.
106-
|`exception` _(required)_|Name of the exception thrown during the execution, or `KeyValue#NONE_VALUE`} if no exception happened.
107-
|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution.
106+
|`exception` _(required)_|Name of the exception thrown during the execution, or `"none"` if no exception happened.
107+
|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution).
108108
|===
109109

110110

@@ -135,7 +135,7 @@ By default, the following `KeyValues` are created:
135135
[cols="a,a"]
136136
|===
137137
|Name | Description
138-
|`exception` _(required)_|Name of the exception thrown during the exchange, or `KeyValue#NONE_VALUE`} if no exception happened.
138+
|`exception` _(required)_|Name of the exception thrown during the exchange, or `"none"` if no exception happened.
139139
|`method` _(required)_|Name of HTTP request method or `"none"` if the request was not received properly.
140140
|`outcome` _(required)_|Outcome of the HTTP server exchange.
141141
|`status` _(required)_|HTTP response raw status code, or `"UNKNOWN"` if no response was created.

Diff for: spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected KeyValue outcome(ScheduledTaskObservationContext context) {
7575
if (context.getError() != null) {
7676
return OUTCOME_ERROR;
7777
}
78-
else if (!context.isComplete()) {
78+
if (!context.isComplete()) {
7979
return OUTCOME_UNKNOWN;
8080
}
8181
return OUTCOME_SUCCESS;

Diff for: spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java

+13-20
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3737
import org.springframework.scheduling.config.ScheduledTask;
3838
import org.springframework.scheduling.config.ScheduledTaskHolder;
39-
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
4039
import org.springframework.scheduling.support.ScheduledTaskObservationContext;
4140

4241
import static org.assertj.core.api.Assertions.assertThat;
@@ -155,14 +154,7 @@ private void registerScheduledBean(Class<?> beanClass) {
155154
targetDefinition.getPropertyValues().add("observationRegistry", this.observationRegistry);
156155
context.registerBeanDefinition("postProcessor", processorDefinition);
157156
context.registerBeanDefinition("target", targetDefinition);
158-
context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> {
159-
return new SchedulingConfigurer() {
160-
@Override
161-
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
162-
taskRegistrar.setObservationRegistry(observationRegistry);
163-
}
164-
};
165-
});
157+
context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> taskRegistrar -> taskRegistrar.setObservationRegistry(observationRegistry));
166158
context.refresh();
167159
}
168160

@@ -198,7 +190,7 @@ public void setObservationRegistry(ObservationRegistry observationRegistry) {
198190
this.observationRegistry = observationRegistry;
199191
}
200192

201-
public void await() throws InterruptedException {
193+
void await() throws InterruptedException {
202194
this.latch.await(3, TimeUnit.SECONDS);
203195
}
204196
}
@@ -207,7 +199,7 @@ public void await() throws InterruptedException {
207199
static class FixedDelayBean extends TaskTester {
208200

209201
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
210-
public void fixedDelay() {
202+
void fixedDelay() {
211203
this.latch.countDown();
212204
}
213205
}
@@ -216,7 +208,7 @@ public void fixedDelay() {
216208
static class FixedDelayErrorBean extends TaskTester {
217209

218210
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
219-
public void error() {
211+
void error() {
220212
this.latch.countDown();
221213
throw new IllegalStateException("test error");
222214
}
@@ -226,7 +218,7 @@ public void error() {
226218
static class FixedDelayReactiveBean extends TaskTester {
227219

228220
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
229-
public Mono<Object> fixedDelay() {
221+
Mono<Object> fixedDelay() {
230222
return Mono.empty().doOnTerminate(() -> this.latch.countDown());
231223
}
232224
}
@@ -235,7 +227,7 @@ public Mono<Object> fixedDelay() {
235227
static class FixedDelayReactiveErrorBean extends TaskTester {
236228

237229
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
238-
public Mono<Object> error() {
230+
Mono<Object> error() {
239231
return Mono.error(new IllegalStateException("test error"))
240232
.doOnTerminate(() -> this.latch.countDown());
241233
}
@@ -245,7 +237,7 @@ public Mono<Object> error() {
245237
static class CancelledTaskBean extends TaskTester {
246238

247239
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
248-
public void cancelled() {
240+
void cancelled() {
249241
this.latch.countDown();
250242
try {
251243
Thread.sleep(5000);
@@ -260,7 +252,7 @@ public void cancelled() {
260252
static class CancelledReactiveTaskBean extends TaskTester {
261253

262254
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
263-
public Flux<Long> cancelled() {
255+
Flux<Long> cancelled() {
264256
return Flux.interval(Duration.ZERO, Duration.ofSeconds(1))
265257
.doOnNext(el -> this.latch.countDown());
266258
}
@@ -270,9 +262,10 @@ public Flux<Long> cancelled() {
270262
static class CurrentObservationBean extends TaskTester {
271263

272264
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
273-
public void hasCurrentObservation() {
274-
assertThat(this.observationRegistry.getCurrentObservation()).isNotNull();
275-
assertThat(this.observationRegistry.getCurrentObservation().getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
265+
void hasCurrentObservation() {
266+
Observation observation = this.observationRegistry.getCurrentObservation();
267+
assertThat(observation).isNotNull();
268+
assertThat(observation.getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
276269
this.latch.countDown();
277270
}
278271
}
@@ -281,7 +274,7 @@ public void hasCurrentObservation() {
281274
static class CurrentObservationReactiveBean extends TaskTester {
282275

283276
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
284-
public Mono<String> hasCurrentObservation() {
277+
Mono<String> hasCurrentObservation() {
285278
return Mono.just("test")
286279
.tap(() -> new DefaultSignalListener<String>() {
287280
@Override

Diff for: spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ interface TaskProcessor {
101101

102102
static class BeanWithScheduledMethods implements TaskProcessor {
103103

104+
@Override
104105
public void process() {
105106
}
106107
}

0 commit comments

Comments
 (0)