Skip to content

Commit

Permalink
add executor service param - fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Semernitskaya committed Sep 19, 2023
1 parent b3e9ebb commit 4ef296d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.failsafe.Policy;
import dev.failsafe.function.ContextualSupplier;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apiguardian.api.API;
import org.organicdesign.fp.collections.ImList;
import org.springframework.http.client.ClientHttpResponse;
Expand All @@ -15,6 +16,7 @@
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Predicate;

import static java.util.stream.Collectors.toList;
Expand All @@ -23,6 +25,7 @@
import static org.organicdesign.fp.StaticImports.vec;
import static org.zalando.riptide.Attributes.RETRIES;

@Slf4j
@API(status = MAINTAINED)
@AllArgsConstructor(access = PRIVATE)
public final class FailsafePlugin implements Plugin {
Expand Down Expand Up @@ -50,6 +53,11 @@ public FailsafePlugin withPolicy(final RequestPolicy policy) {
}

public FailsafePlugin withExecutor(@Nullable final ExecutorService executorService) {
if (executorService instanceof ThreadPoolExecutor
&& ((ThreadPoolExecutor) executorService).getCorePoolSize() == 1) {
log.warn("The executorService should have a core pool size or parallelism of at least 2 in order for timeouts to work, " +
"see dev.failsafe.Failsafe documentation for more details");
}
return new FailsafePlugin(policies, decorators, executorService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ExecutorService retryPolicyExecutorService() {

@Bean(name = "custom-executor-testCircuitBreakerExecutorService")
public ExecutorService circuitBreakerExecutorService() {
return new CountingExecutorService("circuitBreaker", 3, 3,
return new CountingExecutorService("circuitBreaker", 1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>());
}
Expand Down

0 comments on commit 4ef296d

Please sign in to comment.