-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare seconds to seconds in InstrumentedPool.PoolMetrics#isInactive…
…ForMoreThan (#177) In the default implementation, the time units were mixed up and milliseconds were directly compared to seconds. Fixes #176.
- Loading branch information
Showing
2 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
reactor-pool/src/test/java/reactor/pool/InstrumentedPoolPoolMetricsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2023 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.pool; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class InstrumentedPoolPoolMetricsTest { | ||
|
||
@Test | ||
void testIsInactiveForMoreThan() { | ||
InstrumentedPool.PoolMetrics metrics = new TestPool(2); | ||
|
||
assertThat(metrics.isInactiveForMoreThan(Duration.ofMillis(1999))).isTrue(); | ||
assertThat(metrics.isInactiveForMoreThan(Duration.ofSeconds(2))).isTrue(); | ||
|
||
assertThat(metrics.isInactiveForMoreThan(Duration.ofMillis(2001))).isFalse(); | ||
assertThat(metrics.isInactiveForMoreThan(Duration.ofSeconds(3))).isFalse(); | ||
} | ||
|
||
static class TestPool implements InstrumentedPool.PoolMetrics { | ||
|
||
final long inactiveSeconds; | ||
|
||
TestPool(long inactiveSeconds) { | ||
this.inactiveSeconds = inactiveSeconds; | ||
} | ||
|
||
@Override | ||
public int acquiredSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int allocatedSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int idleSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int pendingAcquireSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long secondsSinceLastInteraction() { | ||
return inactiveSeconds; | ||
} | ||
|
||
@Override | ||
public int getMaxAllocatedSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getMaxPendingAcquireSize() { | ||
return 0; | ||
} | ||
} | ||
} |