Skip to content

Commit e40dca5

Browse files
committed
Fix the expired condition in ExpirableValue
1 parent 24c65ea commit e40dca5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

driver-core/src/main/com/mongodb/internal/ExpirableValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class ExpirableValue<T> {
3636
private final long deadline;
3737

3838
public static <T> ExpirableValue<T> expired() {
39-
return new ExpirableValue<>(null, Duration.ofSeconds(-1), System.nanoTime());
39+
return new ExpirableValue<>(null, Duration.ZERO, System.nanoTime());
4040
}
4141

4242
public static <T> ExpirableValue<T> expirable(final T value, final Duration lifetime) {
@@ -61,7 +61,7 @@ public Optional<T> getValue() {
6161

6262
@VisibleForTesting(otherwise = PRIVATE)
6363
Optional<T> getValue(final long currentNanoTime) {
64-
if (currentNanoTime - deadline > 0) {
64+
if (currentNanoTime - deadline >= 0) {
6565
return Optional.empty();
6666
} else {
6767
return Optional.of(value);

driver-core/src/test/unit/com/mongodb/internal/ExpirableValueTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void testExpirable() {
4141
() -> assertThrows(AssertionError.class, () -> expirable(null, Duration.ofNanos(1))),
4242
() -> assertThrows(AssertionError.class, () -> expirable(1, null)),
4343
() -> assertFalse(expirable(1, Duration.ofNanos(-1)).getValue().isPresent()),
44+
() -> assertFalse(expirable(1, Duration.ZERO).getValue().isPresent()),
4445
() -> assertEquals(1, expirable(1, Duration.ofSeconds(1)).getValue().get()),
4546
() -> {
4647
ExpirableValue<Integer> expirableValue = expirable(1, Duration.ofNanos(1));

0 commit comments

Comments
 (0)