JAMES-3784 EmptyErrorMailRepositoryHealthCheck: Wrap blocking calls (#1122) master
authorBenoit TELLIER <btellier@linagora.com>
Fri, 12 Aug 2022 09:03:46 +0000 (16:03 +0700)
committerGitHub <noreply@github.com>
Fri, 12 Aug 2022 09:03:46 +0000 (16:03 +0700)
server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/EmptyErrorMailRepositoryHealthCheck.java

index f699a25bbfd64ed00146f7ef8a0e9bf57fbb3231..235fa3e116bcf14fd567cd448b6a34af19112459 100644 (file)
@@ -23,8 +23,7 @@ import org.apache.james.core.healthcheck.ComponentName;
 import org.apache.james.core.healthcheck.HealthCheck;
 import org.apache.james.core.healthcheck.Result;
 import org.apache.james.util.FunctionalUtils;
 import org.apache.james.core.healthcheck.HealthCheck;
 import org.apache.james.core.healthcheck.Result;
 import org.apache.james.util.FunctionalUtils;
-
-import com.github.fge.lambdas.Throwing;
+import org.apache.james.util.ReactorUtils;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -46,11 +45,13 @@ public class EmptyErrorMailRepositoryHealthCheck implements HealthCheck {
 
     @Override
     public Mono<Result> check() {
 
     @Override
     public Mono<Result> check() {
-        return Flux.fromStream(Throwing.supplier(() -> repositoryStore.getByPath(errorRepositoryPath)))
+        return Mono.fromCallable(() -> repositoryStore.getByPath(errorRepositoryPath))
+            .flatMapMany(Flux::fromStream)
             .flatMap(MailRepository::sizeReactive)
             .any(repositorySize -> repositorySize > 0)
             .filter(FunctionalUtils.identityPredicate())
             .map(hasSize -> Result.degraded(COMPONENT_NAME, "MailRepository is not empty"))
             .flatMap(MailRepository::sizeReactive)
             .any(repositorySize -> repositorySize > 0)
             .filter(FunctionalUtils.identityPredicate())
             .map(hasSize -> Result.degraded(COMPONENT_NAME, "MailRepository is not empty"))
-            .switchIfEmpty(Mono.just(Result.healthy(COMPONENT_NAME)));
+            .switchIfEmpty(Mono.just(Result.healthy(COMPONENT_NAME)))
+            .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER);
     }
 }
     }
 }