Search in sources :

Example 1 with SequenceServiceClient

use of com.google.showcase.v1beta1.SequenceServiceClient in project toolkit by googleapis.

the class ShowcaseTest method attemptSequenceTimeoutBackoff.

@Test
public void attemptSequenceTimeoutBackoff() throws Exception {
    // Recreate client with smaller timeout-backoff settings.
    SequenceServiceSettings.Builder builder = seqClient.getSettings().toBuilder();
    builder.attemptSequenceSettings().setRetrySettings(builder.attemptSequenceSettings().retrySettings().setInitialRpcTimeout(org.threeten.bp.Duration.ofSeconds(2L)).setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(2L)).build()).build();
    SequenceServiceClient s = SequenceServiceClient.create(builder.build());
    long backendDelaySeconds = 1L;
    Sequence toCreate = Sequence.newBuilder().addResponses(Sequence.Response.newBuilder().setDelay(Duration.newBuilder().setSeconds(backendDelaySeconds)).setStatus(Status.newBuilder().setCode(Code.UNAVAILABLE_VALUE))).addResponses(Sequence.Response.newBuilder().setDelay(Duration.newBuilder().setSeconds(backendDelaySeconds)).setStatus(Status.newBuilder().setCode(Code.UNAVAILABLE_VALUE))).addResponses(Sequence.Response.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE))).build();
    Sequence sequence = s.createSequence(toCreate);
    assertThat(sequence.getName()).isNotNull();
    s.attemptSequence(AttemptSequenceRequest.newBuilder().setName(sequence.getName()).build());
    SequenceReport report = s.getSequenceReport(sequence.getName() + "/sequenceReport");
    assertThat(report.getAttemptsList()).isNotNull();
    assertThat(report.getAttemptsList().size()).isEqualTo(3);
    for (int i = 1; i < report.getAttemptsList().size(); i++) {
        SequenceReport.Attempt cur = report.getAttempts(i);
        SequenceReport.Attempt prev = report.getAttempts(i - 1);
        long secondsDiff = Math.abs(cur.getAttemptDeadline().getSeconds() - prev.getAttemptDeadline().getSeconds());
        // The difference in the perceived deadline should be equal to
        // the time it took the server to respond, because a new deadline is set
        // with each attempt based on the *attempt start time*.
        assertThat(secondsDiff).isGreaterThan(0);
        assertThat(secondsDiff).isEqualTo(backendDelaySeconds);
    }
    // clean up extra client
    s.shutdownNow();
}
Also used : SequenceServiceSettings(com.google.showcase.v1beta1.SequenceServiceSettings) SequenceReport(com.google.showcase.v1beta1.SequenceReport) SequenceServiceClient(com.google.showcase.v1beta1.SequenceServiceClient) Sequence(com.google.showcase.v1beta1.Sequence) Test(org.junit.Test)

Aggregations

Sequence (com.google.showcase.v1beta1.Sequence)1 SequenceReport (com.google.showcase.v1beta1.SequenceReport)1 SequenceServiceClient (com.google.showcase.v1beta1.SequenceServiceClient)1 SequenceServiceSettings (com.google.showcase.v1beta1.SequenceServiceSettings)1 Test (org.junit.Test)1