use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method attemptEnforcesActiveStateToPerformOperations_maxAttemptsExhausted.
@Test
public void attemptEnforcesActiveStateToPerformOperations_maxAttemptsExhausted() throws InterruptedException {
RpcQosOptions rpcQosOptions = options.toBuilder().withMaxAttempts(1).unsafeBuild();
RpcQos qos = new RpcQosImpl(rpcQosOptions, random, sleeper, counterFactory, distributionFactory);
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
readAttempt.recordRequestStart(monotonicClock.instant());
readAttempt.recordRequestFailed(monotonicClock.instant());
try {
readAttempt.checkCanRetry(monotonicClock.instant(), RETRYABLE_ERROR);
fail("expected error to be re-thrown due to max attempts exhaustion");
} catch (ApiException e) {
// expected
}
try {
readAttempt.recordStreamValue(monotonicClock.instant());
fail("expected IllegalStateException due to attempt being in terminal state");
} catch (IllegalStateException e) {
// expected
}
verify(sleeper, times(0)).sleep(// happens in checkCanRetry when the backoff is checked
anyLong());
verify(counterThrottlingMs, times(0)).inc(anyLong());
verify(counterRpcFailures, times(1)).inc();
verify(counterRpcSuccesses, times(0)).inc();
verify(counterRpcStreamValueReceived, times(0)).inc();
}
use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method attemptsExhaustCorrectly.
@Test
public void attemptsExhaustCorrectly() throws InterruptedException {
RpcQosOptions rpcQosOptions = options.toBuilder().withMaxAttempts(3).unsafeBuild();
RpcQos qos = new RpcQosImpl(rpcQosOptions, random, sleeper, counterFactory, distributionFactory);
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
// try 1
readAttempt.recordRequestStart(monotonicClock.instant());
readAttempt.recordRequestFailed(monotonicClock.instant());
readAttempt.checkCanRetry(monotonicClock.instant(), RETRYABLE_ERROR);
// try 2
readAttempt.recordRequestStart(monotonicClock.instant());
readAttempt.recordRequestFailed(monotonicClock.instant());
readAttempt.checkCanRetry(monotonicClock.instant(), RETRYABLE_ERROR);
// try 3
readAttempt.recordRequestStart(monotonicClock.instant());
readAttempt.recordRequestFailed(monotonicClock.instant());
try {
readAttempt.checkCanRetry(monotonicClock.instant(), RETRYABLE_ERROR);
fail("expected retry to be exhausted after third attempt");
} catch (ApiException e) {
assertSame(e, RETRYABLE_ERROR);
}
verify(counterThrottlingMs, times(0)).inc(anyLong());
verify(counterRpcFailures, times(3)).inc();
verify(counterRpcSuccesses, times(0)).inc();
verify(counterRpcStreamValueReceived, times(0)).inc();
}
use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method attemptThrowsOnNonRetryableError.
@Test
public void attemptThrowsOnNonRetryableError() throws InterruptedException {
RpcQosOptions rpcQosOptions = options.toBuilder().withMaxAttempts(3).unsafeBuild();
RpcQos qos = new RpcQosImpl(rpcQosOptions, random, sleeper, counterFactory, distributionFactory);
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
readAttempt.recordRequestStart(monotonicClock.instant());
// try 1
readAttempt.recordRequestFailed(monotonicClock.instant());
try {
readAttempt.checkCanRetry(monotonicClock.instant(), NON_RETRYABLE_ERROR);
fail("expected non-retryable error to throw error on first occurrence");
} catch (ApiException e) {
assertSame(e, NON_RETRYABLE_ERROR);
}
verify(counterThrottlingMs, times(0)).inc(anyLong());
verify(counterRpcFailures, times(1)).inc();
verify(counterRpcSuccesses, times(0)).inc();
verify(counterRpcStreamValueReceived, times(0)).inc();
}
use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method reads_processedWhenNoErrors.
@Test
public void reads_processedWhenNoErrors() throws InterruptedException {
RpcQos qos = new RpcQosImpl(options, random, sleeper, counterFactory, distributionFactory);
int numSuccesses = 100;
int numStreamElements = 25;
// record enough successful requests to fill up the sample period
for (int i = 0; i < numSuccesses; i++) {
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
Instant start = monotonicClock.instant();
assertTrue(readAttempt.awaitSafeToProceed(start));
for (int j = 0; j < numStreamElements; j++) {
readAttempt.recordStreamValue(monotonicClock.instant());
}
readAttempt.recordRequestStart(monotonicClock.instant());
readAttempt.recordRequestSuccessful(monotonicClock.instant());
}
verify(sleeper, times(0)).sleep(anyLong());
verify(counterThrottlingMs, times(0)).inc(anyLong());
verify(counterRpcFailures, times(0)).inc();
verify(counterRpcSuccesses, times(numSuccesses)).inc();
verify(counterRpcStreamValueReceived, times(numSuccesses * numStreamElements)).inc();
}
use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method attemptThrowsOnNonRetryableErrorCode.
@Test
public void attemptThrowsOnNonRetryableErrorCode() throws InterruptedException {
RpcQosOptions rpcQosOptions = options.toBuilder().withMaxAttempts(3).unsafeBuild();
RpcQos qos = new RpcQosImpl(rpcQosOptions, random, sleeper, counterFactory, distributionFactory);
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
readAttempt.recordRequestStart(monotonicClock.instant());
// try 1
readAttempt.recordRequestFailed(monotonicClock.instant());
try {
readAttempt.checkCanRetry(monotonicClock.instant(), RETRYABLE_ERROR_WITH_NON_RETRYABLE_CODE);
fail("expected non-retryable error to throw error on first occurrence");
} catch (ApiException e) {
assertSame(e, RETRYABLE_ERROR_WITH_NON_RETRYABLE_CODE);
}
verify(counterThrottlingMs, times(0)).inc(anyLong());
verify(counterRpcFailures, times(1)).inc();
verify(counterRpcSuccesses, times(0)).inc();
verify(counterRpcStreamValueReceived, times(0)).inc();
}
Aggregations