Skip to content

Commit

Permalink
Issue ReactiveX#417: Allow to set maxConcurrentCalls to zero in order…
Browse files Browse the repository at this point in the history
… to close a bulkhead fully. (ReactiveX#433)
  • Loading branch information
RobWin authored Apr 24, 2019
1 parent 61cf042 commit 252d025
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down

0 comments on commit 252d025

Please sign in to comment.