@@ -140,22 +140,22 @@ void testAllDeprecatedOptionsSet() {
140140 @ Test
141141 @ DisplayName ("Use timeout if available or the alternative" )
142142 void testUseTimeoutIfAvailableOrTheAlternative () {
143+ // No CSOT: returns alternative values
143144 TimeoutContext timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS );
144- assertEquals (99L , timeoutContext .timeoutOrAlternative (99 ));
145+ assertEquals (TIMEOUT_SETTINGS .getReadTimeoutMS (), timeoutContext .getReadTimeoutMS ());
146+ assertEquals (0 , timeoutContext .getWriteTimeoutMS ());
147+ assertEquals (0 , timeoutContext .getMaxCommitTimeMS ());
145148
149+ // CSOT with infinite timeout (0): returns 0
146150 timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS .withTimeoutMS (0L ));
147- assertEquals (0L , timeoutContext .timeoutOrAlternative (99 ));
148-
149- timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS .withTimeoutMS (999L ));
150- assertTrue (timeoutContext .timeoutOrAlternative (0 ) <= 999 );
151-
152- timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS .withTimeoutMS (999L ));
153- assertTrue (timeoutContext .timeoutOrAlternative (999999 ) <= 999 );
154-
155- timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS );
156- assertEquals (0 , timeoutContext .getMaxCommitTimeMS ());
151+ assertEquals (0L , timeoutContext .getReadTimeoutMS ());
152+ assertEquals (0L , timeoutContext .getWriteTimeoutMS ());
153+ assertEquals (0L , timeoutContext .getMaxCommitTimeMS ());
157154
155+ // CSOT with finite timeout: returns remaining time
158156 timeoutContext = new TimeoutContext (TIMEOUT_SETTINGS .withTimeoutMS (999L ));
157+ assertTrue (timeoutContext .getReadTimeoutMS () <= 999 );
158+ assertTrue (timeoutContext .getWriteTimeoutMS () <= 999 );
159159 assertTrue (timeoutContext .getMaxCommitTimeMS () <= 999 );
160160 }
161161
@@ -207,19 +207,16 @@ void testThrowsWhenExpired() {
207207 assertThrows (MongoOperationTimeoutException .class , smallTimeout ::getConnectTimeoutMs );
208208 assertThrows (MongoOperationTimeoutException .class , () -> getMaxTimeMS (smallTimeout ));
209209 assertThrows (MongoOperationTimeoutException .class , smallTimeout ::getMaxCommitTimeMS );
210- assertThrows (MongoOperationTimeoutException .class , () -> smallTimeout .timeoutOrAlternative (1 ));
211210 assertDoesNotThrow (longTimeout ::getReadTimeoutMS );
212211 assertDoesNotThrow (longTimeout ::getWriteTimeoutMS );
213212 assertDoesNotThrow (longTimeout ::getConnectTimeoutMs );
214213 assertDoesNotThrow (() -> getMaxTimeMS (longTimeout ));
215214 assertDoesNotThrow (longTimeout ::getMaxCommitTimeMS );
216- assertDoesNotThrow (() -> longTimeout .timeoutOrAlternative (1 ));
217215 assertDoesNotThrow (noTimeout ::getReadTimeoutMS );
218216 assertDoesNotThrow (noTimeout ::getWriteTimeoutMS );
219217 assertDoesNotThrow (noTimeout ::getConnectTimeoutMs );
220218 assertDoesNotThrow (() -> getMaxTimeMS (noTimeout ));
221219 assertDoesNotThrow (noTimeout ::getMaxCommitTimeMS );
222- assertDoesNotThrow (() -> noTimeout .timeoutOrAlternative (1 ));
223220 }
224221
225222 @ Test
0 commit comments