/** * {@inheritDoc} * * <p>The attempt settings will be reset if the stream attempt produced any messages. */ @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { if (prevThrowable instanceof ServerStreamingAttemptException) { ServerStreamingAttemptException attemptException = (ServerStreamingAttemptException) prevThrowable; prevThrowable = prevThrowable.getCause(); // If we have made progress in the last attempt, then reset the delays if (attemptException.hasSeenResponses()) { prevSettings = createFirstAttempt() .toBuilder() .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .setOverallAttemptCount(prevSettings.getOverallAttemptCount()) .build(); } } return super.createNextAttempt(prevThrowable, prevResponse, prevSettings); }
/** * {@inheritDoc} * * <p>The attempt settings will be reset if the stream attempt produced any messages. */ @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { if (prevThrowable instanceof ServerStreamingAttemptException) { ServerStreamingAttemptException attemptException = (ServerStreamingAttemptException) prevThrowable; prevThrowable = prevThrowable.getCause(); // If we have made progress in the last attempt, then reset the delays if (attemptException.hasSeenResponses()) { prevSettings = createFirstAttempt() .toBuilder() .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .setOverallAttemptCount(prevSettings.getOverallAttemptCount()) .build(); } } return super.createNextAttempt(prevThrowable, prevResponse, prevSettings); }
@Test @SuppressWarnings("ConstantConditions") public void testInitialRetry() { resumptionStrategy = new MyStreamResumptionStrategy(); ServerStreamingAttemptCallable<String, String> callable = createCallable(); callable.start(); MockServerStreamingCall<String, String> call = innerCallable.popLastCall(); // Send initial error FakeApiException initialError = new FakeApiException(null, Code.UNAVAILABLE, true); call.getController().getObserver().onError(initialError); // Should notify the outer future Throwable outerError = null; try { fakeRetryingFuture.getAttemptResult().get(1, TimeUnit.SECONDS); } catch (ExecutionException e) { outerError = e.getCause(); } catch (Throwable e) { outerError = e; } Truth.assertThat(outerError).isInstanceOf(ServerStreamingAttemptException.class); Truth.assertThat(((ServerStreamingAttemptException) outerError).hasSeenResponses()).isFalse(); Truth.assertThat(((ServerStreamingAttemptException) outerError).canResume()).isTrue(); Truth.assertThat(outerError.getCause()).isEqualTo(initialError); // Make the retry call callable.call(); call = innerCallable.popLastCall(); // Verify the request and send a response Truth.assertThat(call.getRequest()).isEqualTo("request > 0"); }
Truth.assertThat(((ServerStreamingAttemptException) outerError).hasSeenResponses()).isTrue(); Truth.assertThat(((ServerStreamingAttemptException) outerError).canResume()).isTrue(); Truth.assertThat(outerError.getCause()).isEqualTo(innerError);