Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Jul 10, 2023
1 parent 38f9cbe commit 4fefa7e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ By default, the following `KeyValues` are created:
|Name | Description
|`code.function` _(required)_|Name of Java `Method` that is scheduled for execution.
|`code.namespace` _(required)_|Canonical name of the class of the bean instance that holds the scheduled method.
|`exception` _(required)_|Name of the exception thrown during the execution, or `KeyValue#NONE_VALUE`} if no exception happened.
|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution.
|`exception` _(required)_|Name of the exception thrown during the execution, or `"none"` if no exception happened.
|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution).
|===


Expand Down Expand Up @@ -135,7 +135,7 @@ By default, the following `KeyValues` are created:
[cols="a,a"]
|===
|Name | Description
|`exception` _(required)_|Name of the exception thrown during the exchange, or `KeyValue#NONE_VALUE`} if no exception happened.
|`exception` _(required)_|Name of the exception thrown during the exchange, or `"none"` if no exception happened.
|`method` _(required)_|Name of HTTP request method or `"none"` if the request was not received properly.
|`outcome` _(required)_|Outcome of the HTTP server exchange.
|`status` _(required)_|HTTP response raw status code, or `"UNKNOWN"` if no response was created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected KeyValue outcome(ScheduledTaskObservationContext context) {
if (context.getError() != null) {
return OUTCOME_ERROR;
}
else if (!context.isComplete()) {
if (!context.isComplete()) {
return OUTCOME_UNKNOWN;
}
return OUTCOME_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.config.ScheduledTask;
import org.springframework.scheduling.config.ScheduledTaskHolder;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.ScheduledTaskObservationContext;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -155,14 +154,7 @@ private void registerScheduledBean(Class<?> beanClass) {
targetDefinition.getPropertyValues().add("observationRegistry", this.observationRegistry);
context.registerBeanDefinition("postProcessor", processorDefinition);
context.registerBeanDefinition("target", targetDefinition);
context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> {
return new SchedulingConfigurer() {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setObservationRegistry(observationRegistry);
}
};
});
context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> taskRegistrar -> taskRegistrar.setObservationRegistry(observationRegistry));
context.refresh();
}

Expand Down Expand Up @@ -198,7 +190,7 @@ public void setObservationRegistry(ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry;
}

public void await() throws InterruptedException {
void await() throws InterruptedException {
this.latch.await(3, TimeUnit.SECONDS);
}
}
Expand All @@ -207,7 +199,7 @@ public void await() throws InterruptedException {
static class FixedDelayBean extends TaskTester {

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public void fixedDelay() {
void fixedDelay() {
this.latch.countDown();
}
}
Expand All @@ -216,7 +208,7 @@ public void fixedDelay() {
static class FixedDelayErrorBean extends TaskTester {

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public void error() {
void error() {
this.latch.countDown();
throw new IllegalStateException("test error");
}
Expand All @@ -226,7 +218,7 @@ public void error() {
static class FixedDelayReactiveBean extends TaskTester {

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public Mono<Object> fixedDelay() {
Mono<Object> fixedDelay() {
return Mono.empty().doOnTerminate(() -> this.latch.countDown());
}
}
Expand All @@ -235,7 +227,7 @@ public Mono<Object> fixedDelay() {
static class FixedDelayReactiveErrorBean extends TaskTester {

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

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public void cancelled() {
void cancelled() {
this.latch.countDown();
try {
Thread.sleep(5000);
Expand All @@ -260,7 +252,7 @@ public void cancelled() {
static class CancelledReactiveTaskBean extends TaskTester {

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

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public void hasCurrentObservation() {
assertThat(this.observationRegistry.getCurrentObservation()).isNotNull();
assertThat(this.observationRegistry.getCurrentObservation().getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
void hasCurrentObservation() {
Observation observation = this.observationRegistry.getCurrentObservation();
assertThat(observation).isNotNull();
assertThat(observation.getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
this.latch.countDown();
}
}
Expand All @@ -281,7 +274,7 @@ public void hasCurrentObservation() {
static class CurrentObservationReactiveBean extends TaskTester {

@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
public Mono<String> hasCurrentObservation() {
Mono<String> hasCurrentObservation() {
return Mono.just("test")
.tap(() -> new DefaultSignalListener<String>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ interface TaskProcessor {

static class BeanWithScheduledMethods implements TaskProcessor {

@Override
public void process() {
}
}
Expand Down

0 comments on commit 4fefa7e

Please sign in to comment.