Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
fix: make package-private + add ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Feb 5, 2021
1 parent 51b670b commit 41fdc4e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* #withTransportChannel}, return copies of the object, but with one field changed. The immutability
* and thread safety of the arguments solely depends on the arguments themselves.
*
* <p>Applications should reference {@link ApiCallContext} instead - this class is likely to
* <p>Applications should reference {@link ApiCallContext} instead. This class is likely to
* experience breaking changes.
*/
@Beta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public class BasicResultRetryAlgorithm<ResponseT> implements ResultRetryAlgorith
/**
* Always returns null, indicating that this algorithm does not provide any specific settings for
* the next attempt.
*
* @param previousThrowable exception thrown by the previous attempt ({@code null}, if none)
* @param previousResponse response returned by the previous attempt
* @param previousSettings previous attempt settings
*/
@Override
public TimedAttemptSettings createNextAttempt(
Expand All @@ -62,7 +58,7 @@ public TimedAttemptSettings createNextAttempt(
* the next attempt.
*
* @param context the retrying context of this invocation that can be used to determine the
* settings for the next attempt
* settings for the next attempt. Ignored by this implementation.
* @param previousThrowable exception thrown by the previous attempt ({@code null}, if none)
* @param previousResponse response returned by the previous attempt
* @param previousSettings previous attempt settings
Expand All @@ -72,15 +68,15 @@ public TimedAttemptSettings createNextAttempt(
Throwable previousThrowable,
ResponseT previousResponse,
TimedAttemptSettings previousSettings) {
return createNextAttempt(previousThrowable, previousResponse, previousSettings);
return null;
}

/**
* Returns {@code true} if an exception was thrown ({@code previousThrowable != null}), {@code
* false} otherwise.
*
* @param previousThrowable exception thrown by the previous attempt ({@code null}, if none)
* @param previousResponse response returned by the previous attempt
* @param previousResponse ignored
*/
@Override
public boolean shouldRetry(Throwable previousThrowable, ResponseT previousResponse) {
Expand All @@ -92,9 +88,10 @@ public boolean shouldRetry(Throwable previousThrowable, ResponseT previousRespon
* false} otherwise.
*
* @param context the retrying context of this invocation that can be used to determine whether
* the call should be retried
* the call should be retried. Ignored by this implementation.
* @param previousThrowable exception thrown by the previous attempt ({@code null}, if none)
* @param previousResponse response returned by the previous attempt
* @param previousResponse response returned by the previous attempt. Ignored by this
* implementation.
*/
public boolean shouldRetry(
RetryingContext context, Throwable previousThrowable, ResponseT previousResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) {
* Returns {@code true} if another attempt should be made, or {@code false} otherwise.
*
* @param context a {@link RetryingContext} that can contain custom {@link RetrySettings} and
* retryable codes
* retryable codes. Ignored by this implementation.
* @param nextAttemptSettings attempt settings, which will be used for the next attempt, if
* accepted
* @return {@code true} if {@code nextAttemptSettings} does not exceed either maxAttempts limit or
Expand All @@ -247,7 +247,11 @@ public boolean shouldRetry(RetryingContext context, TimedAttemptSettings nextAtt
}

// Injecting Random is not possible here, as Random does not provide nextLong(long bound) method
protected long nextRandomLong(long bound, boolean withJitter) {
protected long nextRandomLong(long bound) {
return nextRandomLong(bound, globalSettings.isJittered());
}

private long nextRandomLong(long bound, boolean withJitter) {
return bound > 0 && withJitter ? ThreadLocalRandom.current().nextLong(bound) : bound;
}
}
1 change: 0 additions & 1 deletion gax/src/main/java/com/google/api/gax/rpc/Callables.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.retrying.ContextAwareRetryAlgorithm;
import com.google.api.gax.retrying.ContextAwareScheduledRetryingExecutor;
import com.google.api.gax.retrying.ContextAwareStreamingRetryAlgorithm;
import com.google.api.gax.retrying.ExponentialRetryAlgorithm;
import com.google.api.gax.retrying.RetryAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.api.gax.retrying;
package com.google.api.gax.rpc;

import com.google.api.core.InternalApi;
import com.google.api.gax.retrying.BasicResultRetryAlgorithm;
import com.google.api.gax.retrying.ContextAwareRetryAlgorithm;
import com.google.api.gax.retrying.ExponentialRetryAlgorithm;
import com.google.api.gax.retrying.RetryAlgorithm;
import com.google.api.gax.retrying.RetryingContext;
import com.google.api.gax.retrying.ServerStreamingAttemptException;
import com.google.api.gax.retrying.StreamResumptionStrategy;
import com.google.api.gax.retrying.TimedAttemptSettings;
import java.util.concurrent.CancellationException;

/**
Expand All @@ -38,11 +45,8 @@
* information (provided by {@code ServerStreamingAttemptCallable}) into account.
*
* <p>This class is thread-safe.
*
* <p>Internal use only - public for technical reasons.
*/
@InternalApi("For internal use only")
public final class ContextAwareStreamingRetryAlgorithm<ResponseT>
final class ContextAwareStreamingRetryAlgorithm<ResponseT>
extends ContextAwareRetryAlgorithm<ResponseT> {
public ContextAwareStreamingRetryAlgorithm(
BasicResultRetryAlgorithm<ResponseT> resultAlgorithm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.api.gax.retrying;
package com.google.api.gax.rpc;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.google.api.core.ApiClock;
import com.google.api.gax.rpc.UnavailableException;
import com.google.api.gax.retrying.BasicResultRetryAlgorithm;
import com.google.api.gax.retrying.ExponentialRetryAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.retrying.RetryingContext;
import com.google.api.gax.retrying.ServerStreamingAttemptException;
import com.google.api.gax.retrying.TimedAttemptSettings;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down

0 comments on commit 41fdc4e

Please sign in to comment.