diff --git a/resilience4j-bulkhead/src/main/java/io/github/resilience4j/bulkhead/BulkheadConfig.java b/resilience4j-bulkhead/src/main/java/io/github/resilience4j/bulkhead/BulkheadConfig.java index 588b71a2fe..116c3082b0 100644 --- a/resilience4j-bulkhead/src/main/java/io/github/resilience4j/bulkhead/BulkheadConfig.java +++ b/resilience4j-bulkhead/src/main/java/io/github/resilience4j/bulkhead/BulkheadConfig.java @@ -69,8 +69,8 @@ public static class Builder { * @return the BulkheadConfig.Builder */ public Builder maxConcurrentCalls(int maxConcurrentCalls) { - if (maxConcurrentCalls < 1) { - throw new IllegalArgumentException("maxConcurrentCalls must be a positive integer value >= 1"); + if (maxConcurrentCalls < 0) { + throw new IllegalArgumentException("maxConcurrentCalls must be an integer value >= 0"); } config.maxConcurrentCalls = maxConcurrentCalls; return this; diff --git a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadConfigTest.java b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadConfigTest.java index 606e2ebaeb..059a9a632c 100644 --- a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadConfigTest.java +++ b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadConfigTest.java @@ -43,6 +43,22 @@ public void testBuildCustom() { assertThat(config.getMaxWaitTime()).isEqualTo(maxWait); } + @Test + public void testBuildWithZeroMaxCurrentCalls() { + + // given + int maxConcurrent = 0; + + // when + BulkheadConfig config = BulkheadConfig.custom() + .maxConcurrentCalls(maxConcurrent) + .build(); + + // then + assertThat(config).isNotNull(); + assertThat(config.getMaxConcurrentCalls()).isEqualTo(maxConcurrent); + } + @Test(expected = IllegalArgumentException.class) public void testBuildWithIllegalMaxConcurrent() { diff --git a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/internal/SemaphoreBulkheadTest.java b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/internal/SemaphoreBulkheadTest.java index 3ab1402fa5..4532e3e373 100644 --- a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/internal/SemaphoreBulkheadTest.java +++ b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/internal/SemaphoreBulkheadTest.java @@ -137,6 +137,24 @@ public void testTryEnterWithTimeout() { assertThat(entered).isTrue(); } + @Test + public void testZeroMaxConcurrentCalls() { + + // given + BulkheadConfig config = BulkheadConfig.custom() + .maxConcurrentCalls(0) + .maxWaitTime(0) + .build(); + + SemaphoreBulkhead bulkhead = new SemaphoreBulkhead("test", config); + + // when + boolean entered = bulkhead.tryObtainPermission(); + + // then + assertThat(entered).isFalse(); + } + @Test public void testEntryTimeout() {