Search in sources :

Example 1 with SpannerCallContextTimeoutConfigurator

use of com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator in project java-spanner by googleapis.

the class SpannerOptionsTest method testSpannerCallContextTimeoutConfigurator_WithTimeouts.

@Test
public void testSpannerCallContextTimeoutConfigurator_WithTimeouts() {
    SpannerCallContextTimeoutConfigurator configurator = SpannerCallContextTimeoutConfigurator.create();
    configurator.withBatchUpdateTimeout(Duration.ofSeconds(1L));
    configurator.withCommitTimeout(Duration.ofSeconds(2L));
    configurator.withExecuteQueryTimeout(Duration.ofSeconds(3L));
    configurator.withExecuteUpdateTimeout(Duration.ofSeconds(4L));
    configurator.withPartitionQueryTimeout(Duration.ofSeconds(5L));
    configurator.withPartitionReadTimeout(Duration.ofSeconds(6L));
    configurator.withReadTimeout(Duration.ofSeconds(7L));
    configurator.withRollbackTimeout(Duration.ofSeconds(8L));
    ApiCallContext inputCallContext = GrpcCallContext.createDefault();
    assertThat(configurator.configure(inputCallContext, BatchCreateSessionsRequest.getDefaultInstance(), SpannerGrpc.getBatchCreateSessionsMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, CreateSessionRequest.getDefaultInstance(), SpannerGrpc.getCreateSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, DeleteSessionRequest.getDefaultInstance(), SpannerGrpc.getDeleteSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, GetSessionRequest.getDefaultInstance(), SpannerGrpc.getGetSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, DeleteSessionRequest.getDefaultInstance(), SpannerGrpc.getDeleteSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ListSessionsRequest.getDefaultInstance(), SpannerGrpc.getListSessionsMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, BeginTransactionRequest.getDefaultInstance(), SpannerGrpc.getBeginTransactionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, CommitRequest.getDefaultInstance(), SpannerGrpc.getCommitMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(2L));
    assertThat(configurator.configure(inputCallContext, RollbackRequest.getDefaultInstance(), SpannerGrpc.getRollbackMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(8L));
    assertThat(configurator.configure(inputCallContext, ExecuteSqlRequest.getDefaultInstance(), SpannerGrpc.getExecuteSqlMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ExecuteSqlRequest.getDefaultInstance(), SpannerGrpc.getExecuteStreamingSqlMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(3L));
    assertThat(configurator.configure(inputCallContext, ExecuteBatchDmlRequest.getDefaultInstance(), SpannerGrpc.getExecuteBatchDmlMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(1L));
    assertThat(configurator.configure(inputCallContext, ReadRequest.getDefaultInstance(), SpannerGrpc.getReadMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ReadRequest.getDefaultInstance(), SpannerGrpc.getStreamingReadMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(7L));
    assertThat(configurator.configure(inputCallContext, PartitionQueryRequest.getDefaultInstance(), SpannerGrpc.getPartitionQueryMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(5L));
    assertThat(configurator.configure(inputCallContext, PartitionReadRequest.getDefaultInstance(), SpannerGrpc.getPartitionReadMethod()).getTimeout()).isEqualTo(Duration.ofSeconds(6L));
}
Also used : ApiCallContext(com.google.api.gax.rpc.ApiCallContext) SpannerCallContextTimeoutConfigurator(com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator) Test(org.junit.Test)

Example 2 with SpannerCallContextTimeoutConfigurator

use of com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator in project java-spanner by googleapis.

the class SpannerOptionsTest method testSpannerCallContextTimeoutConfigurator_NullValues.

@Test
public void testSpannerCallContextTimeoutConfigurator_NullValues() {
    SpannerCallContextTimeoutConfigurator configurator = SpannerCallContextTimeoutConfigurator.create();
    ApiCallContext inputCallContext = GrpcCallContext.createDefault();
    assertThat(configurator.configure(inputCallContext, BatchCreateSessionsRequest.getDefaultInstance(), SpannerGrpc.getBatchCreateSessionsMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, CreateSessionRequest.getDefaultInstance(), SpannerGrpc.getCreateSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, DeleteSessionRequest.getDefaultInstance(), SpannerGrpc.getDeleteSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, GetSessionRequest.getDefaultInstance(), SpannerGrpc.getGetSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, DeleteSessionRequest.getDefaultInstance(), SpannerGrpc.getDeleteSessionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ListSessionsRequest.getDefaultInstance(), SpannerGrpc.getListSessionsMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, BeginTransactionRequest.getDefaultInstance(), SpannerGrpc.getBeginTransactionMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, CommitRequest.getDefaultInstance(), SpannerGrpc.getCommitMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, RollbackRequest.getDefaultInstance(), SpannerGrpc.getRollbackMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ExecuteSqlRequest.getDefaultInstance(), SpannerGrpc.getExecuteSqlMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ExecuteSqlRequest.getDefaultInstance(), SpannerGrpc.getExecuteStreamingSqlMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ExecuteBatchDmlRequest.getDefaultInstance(), SpannerGrpc.getExecuteBatchDmlMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ReadRequest.getDefaultInstance(), SpannerGrpc.getReadMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, ReadRequest.getDefaultInstance(), SpannerGrpc.getStreamingReadMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, PartitionQueryRequest.getDefaultInstance(), SpannerGrpc.getPartitionQueryMethod())).isNull();
    assertThat(configurator.configure(inputCallContext, PartitionReadRequest.getDefaultInstance(), SpannerGrpc.getPartitionReadMethod())).isNull();
}
Also used : ApiCallContext(com.google.api.gax.rpc.ApiCallContext) SpannerCallContextTimeoutConfigurator(com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator) Test(org.junit.Test)

Aggregations

ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 SpannerCallContextTimeoutConfigurator (com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator)2 Test (org.junit.Test)2