2828
2929import static com .mongodb .assertions .Assertions .assertNotNull ;
3030import static com .mongodb .assertions .Assertions .assertNull ;
31+ import static com .mongodb .assertions .Assertions .assertTrue ;
3132import static com .mongodb .assertions .Assertions .isTrue ;
3233import static com .mongodb .internal .VisibleForTesting .AccessModifier .PRIVATE ;
3334import static com .mongodb .internal .time .Timeout .ZeroSemantics .ZERO_DURATION_MEANS_INFINITE ;
4142public class TimeoutContext {
4243 private static final int NO_ROUND_TRIP_TIME_MS = 0 ;
4344 private final TimeoutSettings timeoutSettings ;
45+ /**
46+ * Is {@code null} iff {@link #timeoutSettings}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is {@code null}.
47+ */
4448 @ Nullable
4549 private final Timeout timeout ;
4650 @ Nullable
@@ -139,6 +143,7 @@ private TimeoutContext(final boolean isMaintenanceContext,
139143 final TimeoutSettings timeoutSettings ,
140144 @ Nullable final MaxTimeSupplier maxTimeSupplier ,
141145 @ Nullable final Timeout timeout ) {
146+ assertTrue ((timeoutSettings .getTimeoutMS () == null ) == (timeout == null ));
142147 this .isMaintenanceContext = isMaintenanceContext ;
143148 this .timeoutSettings = timeoutSettings ;
144149 this .minRoundTripTimeMS = minRoundTripTimeMS ;
@@ -149,7 +154,8 @@ private TimeoutContext(final boolean isMaintenanceContext,
149154 /**
150155 * Allows for the differentiation between users explicitly setting a global operation timeout via {@code timeoutMS}.
151156 *
152- * @return true if a timeout has been set.
157+ * @return true iff {@link #getTimeoutSettings()}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is not {@code null}.
158+ * @see #getTimeout()
153159 */
154160 public boolean hasTimeoutMS () {
155161 return timeoutSettings .getTimeoutMS () != null ;
@@ -170,7 +176,6 @@ public Timeout timeoutIncludingRoundTrip() {
170176
171177 /**
172178 * Returns the remaining {@code timeoutMS} if set or the {@code alternativeTimeoutMS}.
173- *
174179 * zero means infinite timeout.
175180 *
176181 * @param alternativeTimeoutMS the alternative timeout.
@@ -191,6 +196,10 @@ public TimeoutSettings getTimeoutSettings() {
191196 return timeoutSettings ;
192197 }
193198
199+ /**
200+ * @return {@code null} iff {@link #hasTimeoutMS()} is {@code false}.
201+ * @see #hasTimeoutMS()
202+ */
194203 @ Nullable
195204 public Timeout getTimeout () {
196205 return timeout ;
0 commit comments