use of org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcReadAttempt in project beam by apache.
the class RpcQosTest method attemptEnforcesActiveStateToPerformOperations_successful.
@Test
public void attemptEnforcesActiveStateToPerformOperations_successful() 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.recordRequestSuccessful(monotonicClock.instant());
readAttempt.completeSuccess();
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(0)).inc();
verify(counterRpcSuccesses, times(1)).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_blockWhenNotSafeToProceed.
@Test
public void reads_blockWhenNotSafeToProceed() throws InterruptedException {
RpcQos qos = new RpcQosImpl(options, random, sleeper, counterFactory, distributionFactory);
// Based on the defined options, 3 failures is the upper bound before the next attempt
// will have to wait before proceeding
int numFailures = 3;
for (int i = 0; i < numFailures; i++) {
RpcReadAttempt readAttempt = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
Instant start = monotonicClock.instant();
assertTrue(readAttempt.awaitSafeToProceed(start));
Instant end = monotonicClock.instant();
readAttempt.recordRequestStart(start);
readAttempt.recordRequestFailed(end);
}
RpcReadAttempt readAttempt2 = qos.newReadAttempt(RPC_ATTEMPT_CONTEXT);
assertFalse(readAttempt2.awaitSafeToProceed(monotonicClock.instant()));
long sleepMillis = options.getInitialBackoff().getMillis();
verify(sleeper, times(0)).sleep(sleepMillis);
verify(counterThrottlingMs, times(0)).inc(sleepMillis);
verify(counterRpcFailures, times(numFailures)).inc();
verify(counterRpcSuccesses, times(0)).inc();
verify(counterRpcStreamValueReceived, times(0)).inc();
}
Aggregations