26
26
import com .mongodb .annotations .ThreadSafe ;
27
27
import com .mongodb .connection .ConnectionDescription ;
28
28
import com .mongodb .connection .ServerType ;
29
+ import com .mongodb .internal .VisibleForTesting ;
29
30
import com .mongodb .internal .binding .ConnectionSource ;
30
31
import com .mongodb .internal .connection .Connection ;
31
32
import com .mongodb .internal .connection .QueryResult ;
58
59
import static com .mongodb .assertions .Assertions .isTrueArgument ;
59
60
import static com .mongodb .assertions .Assertions .notNull ;
60
61
import static com .mongodb .internal .Locks .withLock ;
62
+ import static com .mongodb .internal .VisibleForTesting .AccessModifier .PRIVATE ;
61
63
import static com .mongodb .internal .operation .CursorHelper .getNumberToReturn ;
62
64
import static com .mongodb .internal .operation .DocumentHelper .putIfNotNull ;
63
65
import static com .mongodb .internal .operation .SyncOperationHelper .getMoreCursorDocumentToQueryResult ;
@@ -359,7 +361,8 @@ private BsonDocument getPostBatchResumeTokenFromResponse(final BsonDocument resu
359
361
* others are not and rely on the total order mentioned above.
360
362
*/
361
363
@ ThreadSafe
362
- private final class ResourceManager {
364
+ @ VisibleForTesting (otherwise = PRIVATE )
365
+ final class ResourceManager {
363
366
private final Lock lock ;
364
367
private volatile State state ;
365
368
@ Nullable
@@ -416,7 +419,8 @@ <R> R execute(final String exceptionMessageIfClosed, final Supplier<R> operation
416
419
* If {@linkplain #operable() closed}, then returns false, otherwise completes abruptly.
417
420
* @throws IllegalStateException Iff another operation is in progress.
418
421
*/
419
- private boolean tryStartOperation () throws IllegalStateException {
422
+ @ VisibleForTesting (otherwise = PRIVATE )
423
+ boolean tryStartOperation () throws IllegalStateException {
420
424
return withLock (lock , () -> {
421
425
State localState = state ;
422
426
if (!localState .operable ()) {
@@ -435,7 +439,8 @@ private boolean tryStartOperation() throws IllegalStateException {
435
439
/**
436
440
* Thread-safe.
437
441
*/
438
- private void endOperation () {
442
+ @ VisibleForTesting (otherwise = PRIVATE )
443
+ void endOperation () {
439
444
boolean doClose = withLock (lock , () -> {
440
445
State localState = state ;
441
446
if (localState == State .OPERATION_IN_PROGRESS ) {
@@ -459,7 +464,7 @@ private void endOperation() {
459
464
void close () {
460
465
boolean doClose = withLock (lock , () -> {
461
466
State localState = state ;
462
- if (localState == State . OPERATION_IN_PROGRESS ) {
467
+ if (localState . inProgress () ) {
463
468
state = State .CLOSE_PENDING ;
464
469
return false ;
465
470
} else if (localState != State .CLOSED ) {
0 commit comments