Java Code Examples for io.netty.handler.timeout.ReadTimeoutException#INSTANCE

The following examples show how to use io.netty.handler.timeout.ReadTimeoutException#INSTANCE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@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);
}
 
Example 2
Source File: RenameCollectionAwareClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@Test(groups = "unit", timeOut = TIMEOUT)
public void onBeforeSendRequestNotInvoked() {
    GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class);
    Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null), Mockito.eq(false));

    IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault());
    RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class);

    ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class);
    RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer
            , rxClientCollectionCache
            , retryPolicyFactory.getRequestPolicy());

    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 = renameCollectionAwareClientRetryPolicy.shouldRetry(exception);
    validateSuccess(shouldRetry, ShouldRetryValidator.builder()
            .withException(exception)
            .shouldRetry(false)
            .build());

    Mockito.verifyZeroInteractions(endpointManager);
}
 
Example 3
Source File: ClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@Test(groups = "unit")
public void networkFailureOnRead() throws Exception {
    RetryOptions retryOptions = new RetryOptions();
    GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class);
    Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.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.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document);
    dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class);

    clientRetryPolicy.onBeforeSendRequest(dsr);

    for (int i = 0; i < 10; i++) {
        Single<IRetryPolicy.ShouldRetryResult> shouldRetry = clientRetryPolicy.shouldRetry(exception);

        validateSuccess(shouldRetry, ShouldRetryValidator.builder()
                .nullException()
                .shouldRetry(true)
                .backOfTime(Duration.ofMillis(ClientRetryPolicy.RetryIntervalInMS))
                .build());

        Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForRead(Mockito.any());
        Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForWrite(Mockito.any());
    }
}
 
Example 4
Source File: ClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@Test(groups = "unit")
public void networkFailureOnWrite() throws Exception {
    RetryOptions retryOptions = new RetryOptions();
    GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class);
    Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.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);

    clientRetryPolicy.onBeforeSendRequest(dsr);
    for (int i = 0; i < 10; i++) {
        Single<IRetryPolicy.ShouldRetryResult> shouldRetry = clientRetryPolicy.shouldRetry(exception);
        //  We don't want to retry writes on network failure
        validateSuccess(shouldRetry, ShouldRetryValidator.builder()
                .nullException()
                .shouldRetry(false)
                .build());

        Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForRead(Mockito.any());
        Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForWrite(Mockito.any());
    }
}
 
Example 5
Source File: ClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@Test(groups = "unit")
public void networkFailureOnUpsert() throws Exception {
    RetryOptions retryOptions = new RetryOptions();
    GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class);
    Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.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.Upsert, "/dbs/db/colls/col/docs/docId", ResourceType.Document);
    dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class);

    clientRetryPolicy.onBeforeSendRequest(dsr);
    for (int i = 0; i < 10; i++) {
        Single<IRetryPolicy.ShouldRetryResult> shouldRetry = clientRetryPolicy.shouldRetry(exception);
        //  We don't want to retry writes on network failure
        validateSuccess(shouldRetry, ShouldRetryValidator.builder()
                                                         .nullException()
                                                         .shouldRetry(false)
                                                         .build());

        Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForRead(Mockito.any());
        Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForWrite(Mockito.any());
    }
}
 
Example 6
Source File: ClientRetryPolicyTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@Test(groups = "unit")
public void networkFailureOnDelete() throws Exception {
    RetryOptions retryOptions = new RetryOptions();
    GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class);
    Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.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.Delete, "/dbs/db/colls/col/docs/docId", ResourceType.Document);
    dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class);

    clientRetryPolicy.onBeforeSendRequest(dsr);
    for (int i = 0; i < 10; i++) {
        Single<IRetryPolicy.ShouldRetryResult> shouldRetry = clientRetryPolicy.shouldRetry(exception);
        //  We don't want to retry writes on network failure
        validateSuccess(shouldRetry, ShouldRetryValidator.builder()
                                                         .nullException()
                                                         .shouldRetry(false)
                                                         .build());

        Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForRead(Mockito.any());
        Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForWrite(Mockito.any());
    }
}
 
Example 7
Source File: WebExceptionUtilityTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@DataProvider(name = "exceptionToIsRetriable")
public Object[][] exceptionToIsRetriable() {
    return new Object[][]{
            // exception, is retriable
            {
                    new RuntimeException(), false
            },
            {
                    new ConnectException(), true
            },
            {
                    new ConnectTimeoutException(), true
            },
            {
                    new UnknownHostException(), true
            },
            {
                    ReadTimeoutException.INSTANCE, false
            },
            {
                    new SSLHandshakeException("dummy"), true
            },
            {
                    new NoRouteToHostException(), true,
            },
            {
                    new SSLPeerUnverifiedException("dummy"), true
            },
            {
                    new SocketTimeoutException(), false
            },
            {
                    new PoolExhaustedException(), true
            }
    };
}
 
Example 8
Source File: WebExceptionUtilityTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
@DataProvider(name = "networkFailure")
public Object[][] networkFailure() {
    return new Object[][]{
            // exception, is retriable
            {
                    new RuntimeException(), false
            },
            {
                    new ConnectException(), true
            },
            {
                    new ConnectTimeoutException(), true
            },
            {
                    new UnknownHostException(), true
            },
            {
                    ReadTimeoutException.INSTANCE, true
            },
            {
                    new SSLHandshakeException("dummy"), true
            },
            {
                    new NoRouteToHostException(), true,
            },
            {
                    new SSLPeerUnverifiedException("dummy"), true
            },
            {
                    new SocketTimeoutException(), true
            },
            {
                    new ChannelException(), true
            }
    };
}