|
32 | 32 | import static com.mongodb.ClusterFixture.sleep;
|
33 | 33 | import static java.util.Arrays.asList;
|
34 | 34 | import static org.junit.jupiter.api.Assertions.assertAll;
|
| 35 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
35 | 36 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
36 | 37 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
37 | 38 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -197,6 +198,30 @@ Collection<DynamicTest> timeoutContextTest() {
|
197 | 198 | () -> assertTrue(smallTimeout.hasExpired())
|
198 | 199 | );
|
199 | 200 | }),
|
| 201 | + dynamicTest("throws when calculating timeout if expired", () -> { |
| 202 | + TimeoutContext smallTimeout = new TimeoutContext(TIMEOUT_SETTINGS.withTimeoutMS(1)); |
| 203 | + TimeoutContext longTimeout = |
| 204 | + new TimeoutContext(TIMEOUT_SETTINGS.withTimeoutMS(9999999)); |
| 205 | + TimeoutContext noTimeout = new TimeoutContext(TIMEOUT_SETTINGS); |
| 206 | + sleep(100); |
| 207 | + assertAll( |
| 208 | + () -> assertThrows(MongoOperationTimeoutException.class, smallTimeout::getReadTimeoutMS), |
| 209 | + () -> assertThrows(MongoOperationTimeoutException.class, smallTimeout::getWriteTimeoutMS), |
| 210 | + () -> assertThrows(MongoOperationTimeoutException.class, smallTimeout::getMaxTimeMS), |
| 211 | + () -> assertThrows(MongoOperationTimeoutException.class, smallTimeout::getMaxCommitTimeMS), |
| 212 | + () -> assertThrows(MongoOperationTimeoutException.class, () -> smallTimeout.timeoutOrAlternative(1)), |
| 213 | + () -> assertDoesNotThrow(longTimeout::getReadTimeoutMS), |
| 214 | + () -> assertDoesNotThrow(longTimeout::getWriteTimeoutMS), |
| 215 | + () -> assertDoesNotThrow(longTimeout::getMaxTimeMS), |
| 216 | + () -> assertDoesNotThrow(longTimeout::getMaxCommitTimeMS), |
| 217 | + () -> assertDoesNotThrow(() -> longTimeout.timeoutOrAlternative(1)), |
| 218 | + () -> assertDoesNotThrow(noTimeout::getReadTimeoutMS), |
| 219 | + () -> assertDoesNotThrow(noTimeout::getWriteTimeoutMS), |
| 220 | + () -> assertDoesNotThrow(noTimeout::getMaxTimeMS), |
| 221 | + () -> assertDoesNotThrow(noTimeout::getMaxCommitTimeMS), |
| 222 | + () -> assertDoesNotThrow(() -> noTimeout.timeoutOrAlternative(1)) |
| 223 | + ); |
| 224 | + }), |
200 | 225 | dynamicTest("validates minRoundTripTime for maxTimeMS", () -> {
|
201 | 226 | Supplier<TimeoutContext> supplier = () -> new TimeoutContext(TIMEOUT_SETTINGS.withTimeoutMS(100));
|
202 | 227 | assertAll(
|
|
0 commit comments