Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warmup throws IllegalArgumentException in case no permits are available #181

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions reactor-pool/src/main/java/reactor/pool/SimpleDequePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public Mono<Integer> warmup() {
recordInteractionTimestamp();
int initSize = poolConfig.allocationStrategy()
.getPermits(0);
if (initSize <= 0) {
return Mono.just(0);
}
@SuppressWarnings({ "unchecked", "rawtypes" }) //rawtypes added since javac actually complains
Mono<POOLABLE>[] allWarmups = new Mono[initSize];
for (int i = 0; i < initSize; i++) {
Expand Down
39 changes: 39 additions & 0 deletions reactor-pool/src/test/java/reactor/pool/CommonPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2730,4 +2730,43 @@ void recordsPendingCountAndLatencies(PoolStyle configAdjuster) {
.as("pending error latency")
.isGreaterThanOrEqualTo(1L);
}


@ParameterizedTestWithName
@MethodSource("allPools")
void gh180_warmupIdempotent(PoolStyle configAdjuster) {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();

AtomicInteger allocCounter = new AtomicInteger();
Mono<Integer> allocator = Mono.fromCallable(allocCounter::incrementAndGet);

PoolBuilder<Integer, ?> builder =
PoolBuilder.from(allocator)
.sizeBetween(10, 10)
.evictionPredicate((poolable, metadata) -> metadata.idleTime() >= 4000)
.evictInBackground(Duration.ofSeconds(5), vts)
.clock(SchedulerClock.of(vts));

InstrumentedPool<Integer> pool = configAdjuster.apply(builder);
pool.warmup().block();
assertThat(allocCounter).as("allocations").hasValue(10);
assertThat(pool.metrics().allocatedSize()).as("allocatedSize").isEqualTo(10);

assertThatCode(() -> vts.advanceTimeBy(Duration.ofSeconds(10))).doesNotThrowAnyException();

assertThat(pool.metrics().allocatedSize()).as("allocatedSize").isEqualTo(0);
assertThat(allocCounter).as("allocations").hasValue(10);

pool.warmup().block();
assertThat(allocCounter).as("allocations").hasValue(20);
assertThat(pool.metrics().allocatedSize()).as("allocatedSize").isEqualTo(10);

// Since warmup can be called at anytime, calling warmup again should not cause any troubles and should keep the
// pool unchanged.
pool.warmup().block();
assertThat(allocCounter).as("allocations").hasValue(20);
assertThat(pool.metrics().allocatedSize()).as("allocatedSize").isEqualTo(10);

pool.disposeLater().block(Duration.ofSeconds(3));
}
}
Loading