2626import com .mongodb .annotations .ThreadSafe ;
2727import com .mongodb .connection .ConnectionDescription ;
2828import com .mongodb .connection .ServerType ;
29+ import com .mongodb .internal .VisibleForTesting ;
2930import com .mongodb .internal .binding .ConnectionSource ;
3031import com .mongodb .internal .connection .Connection ;
3132import com .mongodb .internal .connection .QueryResult ;
5859import static com .mongodb .assertions .Assertions .isTrueArgument ;
5960import static com .mongodb .assertions .Assertions .notNull ;
6061import static com .mongodb .internal .Locks .withLock ;
62+ import static com .mongodb .internal .VisibleForTesting .AccessModifier .PRIVATE ;
6163import static com .mongodb .internal .operation .CursorHelper .getNumberToReturn ;
6264import static com .mongodb .internal .operation .DocumentHelper .putIfNotNull ;
6365import static com .mongodb .internal .operation .SyncOperationHelper .getMoreCursorDocumentToQueryResult ;
@@ -359,7 +361,8 @@ private BsonDocument getPostBatchResumeTokenFromResponse(final BsonDocument resu
359361 * others are not and rely on the total order mentioned above.
360362 */
361363 @ ThreadSafe
362- private final class ResourceManager {
364+ @ VisibleForTesting (otherwise = PRIVATE )
365+ final class ResourceManager {
363366 private final Lock lock ;
364367 private volatile State state ;
365368 @ Nullable
@@ -416,7 +419,8 @@ <R> R execute(final String exceptionMessageIfClosed, final Supplier<R> operation
416419 * If {@linkplain #operable() closed}, then returns false, otherwise completes abruptly.
417420 * @throws IllegalStateException Iff another operation is in progress.
418421 */
419- private boolean tryStartOperation () throws IllegalStateException {
422+ @ VisibleForTesting (otherwise = PRIVATE )
423+ boolean tryStartOperation () throws IllegalStateException {
420424 return withLock (lock , () -> {
421425 State localState = state ;
422426 if (!localState .operable ()) {
@@ -435,7 +439,8 @@ private boolean tryStartOperation() throws IllegalStateException {
435439 /**
436440 * Thread-safe.
437441 */
438- private void endOperation () {
442+ @ VisibleForTesting (otherwise = PRIVATE )
443+ void endOperation () {
439444 boolean doClose = withLock (lock , () -> {
440445 State localState = state ;
441446 if (localState == State .OPERATION_IN_PROGRESS ) {
@@ -459,7 +464,7 @@ private void endOperation() {
459464 void close () {
460465 boolean doClose = withLock (lock , () -> {
461466 State localState = state ;
462- if (localState == State . OPERATION_IN_PROGRESS ) {
467+ if (localState . inProgress () ) {
463468 state = State .CLOSE_PENDING ;
464469 return false ;
465470 } else if (localState != State .CLOSED ) {
0 commit comments