Search in sources :

Example 6 with ServerStreamingAttemptException

use of com.google.api.gax.retrying.ServerStreamingAttemptException in project gax-java by googleapis.

the class OpencensusTracerTest method testStreamingErrorConversion.

@Test
public void testStreamingErrorConversion() {
    ServerStreamingAttemptException error = new ServerStreamingAttemptException(new DeadlineExceededException("timeout", null, new FakeStatusCode(Code.DEADLINE_EXCEEDED), true), true, true);
    Status opencensusStatus = OpencensusTracer.convertErrorToStatus(error);
    assertThat(opencensusStatus.getDescription()).isEqualTo("timeout");
    assertThat(opencensusStatus.getCanonicalCode()).isEqualTo(CanonicalCode.DEADLINE_EXCEEDED);
}
Also used : Status(io.opencensus.trace.Status) FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) Test(org.junit.Test)

Example 7 with ServerStreamingAttemptException

use of com.google.api.gax.retrying.ServerStreamingAttemptException in project gax-java by googleapis.

the class StreamingRetryAlgorithmTest method testShouldNotRetryIfAttemptIsNonResumable.

@Test
public void testShouldNotRetryIfAttemptIsNonResumable() {
    RetryingContext context = mock(RetryingContext.class);
    ServerStreamingAttemptException exception = mock(ServerStreamingAttemptException.class);
    when(exception.canResume()).thenReturn(false);
    UnavailableException cause = mock(UnavailableException.class);
    when(exception.getCause()).thenReturn(cause);
    BasicResultRetryAlgorithm<String> resultAlgorithm = new BasicResultRetryAlgorithm<>();
    ExponentialRetryAlgorithm timedAlgorithm = new ExponentialRetryAlgorithm(DEFAULT_RETRY_SETTINGS, mock(ApiClock.class));
    StreamingRetryAlgorithm<String> algorithm = new StreamingRetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
    // This should return false because the attempt exception indicates that it is non-resumable.
    boolean shouldRetry = algorithm.shouldRetry(context, exception, null, mock(TimedAttemptSettings.class));
    assertThat(shouldRetry).isFalse();
    boolean shouldRetryWithoutContext = algorithm.shouldRetry(exception, null, mock(TimedAttemptSettings.class));
    assertThat(shouldRetryWithoutContext).isFalse();
}
Also used : ApiClock(com.google.api.core.ApiClock) StreamingRetryAlgorithm(com.google.api.gax.retrying.StreamingRetryAlgorithm) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) BasicResultRetryAlgorithm(com.google.api.gax.retrying.BasicResultRetryAlgorithm) TimedAttemptSettings(com.google.api.gax.retrying.TimedAttemptSettings) RetryingContext(com.google.api.gax.retrying.RetryingContext) Test(org.junit.Test)

Example 8 with ServerStreamingAttemptException

use of com.google.api.gax.retrying.ServerStreamingAttemptException in project gax-java by googleapis.

the class StreamingRetryAlgorithmTest method testShouldRetryIfAllSayYes.

@Test
public void testShouldRetryIfAllSayYes() {
    RetryingContext context = mock(RetryingContext.class);
    ServerStreamingAttemptException exception = mock(ServerStreamingAttemptException.class);
    when(exception.canResume()).thenReturn(true);
    UnavailableException cause = mock(UnavailableException.class);
    when(exception.getCause()).thenReturn(cause);
    BasicResultRetryAlgorithm<String> resultAlgorithm = new BasicResultRetryAlgorithm<>();
    ExponentialRetryAlgorithm timedAlgorithm = mock(ExponentialRetryAlgorithm.class);
    when(timedAlgorithm.shouldRetry(Mockito.eq(context), any(TimedAttemptSettings.class))).thenReturn(true);
    StreamingRetryAlgorithm<String> algorithm = new StreamingRetryAlgorithm<>(resultAlgorithm, timedAlgorithm);
    boolean shouldRetry = algorithm.shouldRetry(context, exception, null, mock(TimedAttemptSettings.class));
    assertThat(shouldRetry).isTrue();
}
Also used : StreamingRetryAlgorithm(com.google.api.gax.retrying.StreamingRetryAlgorithm) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) BasicResultRetryAlgorithm(com.google.api.gax.retrying.BasicResultRetryAlgorithm) TimedAttemptSettings(com.google.api.gax.retrying.TimedAttemptSettings) RetryingContext(com.google.api.gax.retrying.RetryingContext) Test(org.junit.Test)

Example 9 with ServerStreamingAttemptException

use of com.google.api.gax.retrying.ServerStreamingAttemptException in project java-bigquerystorage by googleapis.

the class ReadRowsAttemptCallable method onCancel.

/**
 * Called when the outer {@link ResponseObserver} wants to prematurely cancel the stream.
 *
 * @see StreamController#cancel()
 */
private void onCancel() {
    StreamController localInnerController;
    synchronized (lock) {
        if (cancellationCause != null) {
            return;
        }
        // NOTE: BasicRetryingFuture will replace j.u.c.CancellationExceptions with it's own,
        // which will not have the current stacktrace, so a special wrapper has be used here.
        cancellationCause = new ServerStreamingAttemptException(new CancellationException("User cancelled stream"), resumptionStrategy.canResume(), seenSuccessSinceLastError);
        localInnerController = innerController;
    }
    if (localInnerController != null) {
        localInnerController.cancel();
    }
}
Also used : StreamController(com.google.api.gax.rpc.StreamController) CancellationException(java.util.concurrent.CancellationException) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException)

Example 10 with ServerStreamingAttemptException

use of com.google.api.gax.retrying.ServerStreamingAttemptException in project java-bigquerystorage by googleapis.

the class ReadRowsAttemptCallable method onCancel.

/**
 * Called when the outer {@link ResponseObserver} wants to prematurely cancel the stream.
 *
 * @see StreamController#cancel()
 */
private void onCancel() {
    StreamController localInnerController;
    synchronized (lock) {
        if (cancellationCause != null) {
            return;
        }
        // NOTE: BasicRetryingFuture will replace j.u.c.CancellationExceptions with it's own,
        // which will not have the current stacktrace, so a special wrapper has be used here.
        cancellationCause = new ServerStreamingAttemptException(new CancellationException("User cancelled stream"), resumptionStrategy.canResume(), seenSuccessSinceLastError);
        localInnerController = innerController;
    }
    if (localInnerController != null) {
        localInnerController.cancel();
    }
}
Also used : StreamController(com.google.api.gax.rpc.StreamController) CancellationException(java.util.concurrent.CancellationException) ServerStreamingAttemptException(com.google.api.gax.retrying.ServerStreamingAttemptException)

Aggregations

ServerStreamingAttemptException (com.google.api.gax.retrying.ServerStreamingAttemptException)10 Test (org.junit.Test)6 CancellationException (java.util.concurrent.CancellationException)4 BasicResultRetryAlgorithm (com.google.api.gax.retrying.BasicResultRetryAlgorithm)3 ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)3 RetryingContext (com.google.api.gax.retrying.RetryingContext)3 StreamingRetryAlgorithm (com.google.api.gax.retrying.StreamingRetryAlgorithm)3 TimedAttemptSettings (com.google.api.gax.retrying.TimedAttemptSettings)3 StreamController (com.google.api.gax.rpc.StreamController)3 ApiClock (com.google.api.core.ApiClock)2 FakeApiException (com.google.api.gax.rpc.testing.FakeApiException)2 ExecutionException (java.util.concurrent.ExecutionException)2 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)1 Status (io.opencensus.trace.Status)1