### Question:
ClientRetryPolicy implements IDocumentClientRetryPolicy { @Override public Single<ShouldRetryResult> shouldRetry(Exception e) { logger.debug("retry count {}, isReadRequest {}, canUseMultipleWriteLocations {}, due to failure:", cnt.incrementAndGet(), isReadRequest, canUseMultipleWriteLocations, e); if (this.locationEndpoint == null) { logger.error("locationEndpoint is null because ClientRetryPolicy::onBeforeRequest(.) is not invoked, " + "probably request creation failed due to invalid options, serialization setting, etc."); return Single.just(ShouldRetryResult.error(e)); } if (ConnectionPoolExhaustedRetry.isConnectionPoolExhaustedException(e)) { return rxNettyConnectionPoolExhaustedRetry.shouldRetry(e); } this.retryContext = null; DocumentClientException clientException = Utils.as(e, DocumentClientException.class); if (clientException != null && clientException.getClientSideRequestStatistics() != null) { this.clientSideRequestStatistics = clientException.getClientSideRequestStatistics(); } if (clientException != null && Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.FORBIDDEN) && Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.FORBIDDEN_WRITEFORBIDDEN)) { logger.warn("Endpoint not writable. Will refresh cache and retry. ", e); return this.shouldRetryOnEndpointFailureAsync(false, true); } if (clientException != null && Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.FORBIDDEN) && Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.DATABASE_ACCOUNT_NOTFOUND) && (this.isReadRequest || this.canUseMultipleWriteLocations)) { logger.warn("Endpoint not available for reads. Will refresh cache and retry. ", e); return this.shouldRetryOnEndpointFailureAsync(true, false); } if (WebExceptionUtility.isNetworkFailure(e)) { if (clientException != null && Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE)) { if (this.isReadRequest || WebExceptionUtility.isWebExceptionRetriable(e)) { logger.warn("Gateway endpoint not reachable. Will refresh cache and retry. ", e); return this.shouldRetryOnEndpointFailureAsync(this.isReadRequest, false); } else { return this.shouldNotRetryOnEndpointFailureAsync(this.isReadRequest, false); } } else { logger.warn("Backend endpoint not reachable. ", e); return this.shouldRetryOnBackendServiceUnavailableAsync(this.isReadRequest, WebExceptionUtility.isWebExceptionRetriable(e)); } } if (clientException != null && Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.NOTFOUND) && Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)) { return Single.just(this.shouldRetryOnSessionNotAvailable()); } return this.throttlingRetry.shouldRetry(e); } ClientRetryPolicy(GlobalEndpointManager globalEndpointManager,
                             boolean enableEndpointDiscovery,
                             RetryOptions retryOptions); @Override Single<ShouldRetryResult> shouldRetry(Exception e); @Override void onBeforeSendRequest(RxDocumentServiceRequest request);  }### Answer:
@Test(groups = "unit") public void onBeforeSendRequestNotInvoked() { RetryOptions retryOptions = new RetryOptions(); GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null), Mockito.eq(false)); ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(endpointManager, true, retryOptions); Exception exception = ReadTimeoutException.INSTANCE; RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); Single<IRetryPolicy.ShouldRetryResult> shouldRetry = clientRetryPolicy.shouldRetry(exception); validateSuccess(shouldRetry, ShouldRetryValidator.builder() .withException(exception) .shouldRetry(false) .build()); Mockito.verifyZeroInteractions(endpointManager); }