Search in sources :

Example 1 with RetryCodesConfig

use of com.google.api.codegen.config.RetryCodesConfig in project toolkit by googleapis.

the class RetryDefinitionsTransformerTest method testWithConfigAndInterface.

@Test
public void testWithConfigAndInterface() {
    DiagCollector diagCollector = new BoundedDiagCollector();
    RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto, apiInterface.getMethods(), protoParser);
    Map<String, ImmutableList<String>> retryCodesDef = retryCodesConfig.getRetryCodesDefinition();
    Map<String, String> retryCodesMap = retryCodesConfig.getMethodRetryNames();
    assertThat(retryCodesMap.size()).isEqualTo(4);
    String getHttpRetryName = retryCodesMap.get(GET_HTTP_METHOD_NAME);
    String nonIdempotentRetryName = retryCodesMap.get(NON_IDEMPOTENT_METHOD_NAME);
    String permissionDeniedRetryName = retryCodesMap.get(PERMISSION_DENIED_METHOD_NAME);
    String idempotentRetryName = retryCodesMap.get(IDEMPOTENT_METHOD_NAME);
    // RETRY_CODES_IDEMPOTENT_NAME name for HTTP-GET method had to be escaped because "idempotent"
    // was already defined in the config proto retry code map already, and the config proto's
    // "idempotent" refers to a different set of retry codes compared to the default codes for
    // HTTP-GET.
    assertThat(getHttpRetryName).isEqualTo("idempotent2");
    // Even though "non_idempotent" already exists in the GAPIC config, we can
    // reuse the name for this unconfigured method because it has the same set of retry codes as
    // a non-HTTP-GET method.
    assertThat(nonIdempotentRetryName).isEqualTo(RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(permissionDeniedRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(idempotentRetryName).isEqualTo(RetryTransformer.RETRY_CODES_IDEMPOTENT_NAME);
    // httpGetMethod was an HTTP Get method, so it has two codes by default; config proto didn't
    // have a retry config.
    assertThat(retryCodesDef.get(getHttpRetryName)).isEqualTo(RetryCodesConfig.RETRY_CODES_FOR_HTTP_GET);
    // Config proto gives [] for nonIdempotentMethod; method from protofile has
    // [] for retry codes.
    assertThat(retryCodesDef.get(nonIdempotentRetryName).size()).isEqualTo(0);
    // For permissionDeniedMethod, Config proto gives [] and proto method gives [PERMISSION_DENIED].
    assertThat(retryCodesDef.get(permissionDeniedRetryName).size()).isEqualTo(0);
    assertThat(retryCodesDef.get(idempotentRetryName).iterator().next()).isEqualTo(RESOURCE_EXHAUSTED.name());
}
Also used : BoundedDiagCollector(com.google.api.tools.framework.model.BoundedDiagCollector) DiagCollector(com.google.api.tools.framework.model.DiagCollector) BoundedDiagCollector(com.google.api.tools.framework.model.BoundedDiagCollector) ImmutableList(com.google.common.collect.ImmutableList) RetryCodesConfig(com.google.api.codegen.config.RetryCodesConfig) Test(org.junit.Test)

Example 2 with RetryCodesConfig

use of com.google.api.codegen.config.RetryCodesConfig in project toolkit by googleapis.

the class RetryDefinitionsTransformerTest method testWithInterfaceOnly.

@Test
public void testWithInterfaceOnly() {
    // During GAPIC config migration, we should only create retry codes for methods named in the
    // GAPIC config.
    // TODO(andrealin): Remove this once methods are generated by default.
    InterfaceConfigProto bareBonesConfigProto = InterfaceConfigProto.newBuilder().addMethods(MethodConfigProto.newBuilder().setName(GET_HTTP_METHOD_NAME)).addMethods(MethodConfigProto.newBuilder().setName(NON_IDEMPOTENT_METHOD_NAME)).addMethods(MethodConfigProto.newBuilder().setName(PERMISSION_DENIED_METHOD_NAME)).build();
    RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(bareBonesConfigProto, apiInterface.getMethods(), protoParser);
    Map<String, ImmutableList<String>> retryCodesDef = retryCodesConfig.getRetryCodesDefinition();
    Map<String, String> retryCodesMap = retryCodesConfig.getMethodRetryNames();
    assertThat(retryCodesMap).hasSize(3);
    String getHttpRetryName = retryCodesMap.get(GET_HTTP_METHOD_NAME);
    String nonIdempotentRetryName = retryCodesMap.get(NON_IDEMPOTENT_METHOD_NAME);
    String permissionDeniedRetryName = retryCodesMap.get(PERMISSION_DENIED_METHOD_NAME);
    assertThat(getHttpRetryName).isEqualTo(RetryTransformer.RETRY_CODES_IDEMPOTENT_NAME);
    assertThat(nonIdempotentRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(permissionDeniedRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    // httpGetMethod was an HTTP Get method, so it has two codes by default; config proto didn't
    // have a retry config.
    assertThat(retryCodesDef.get(getHttpRetryName)).isEqualTo(RetryCodesConfig.RETRY_CODES_FOR_HTTP_GET);
    // Method from protofile has
    // [] for retry codes.
    assertThat(retryCodesDef.get(nonIdempotentRetryName).size()).isEqualTo(0);
    // For permissionDeniedMethod, proto method gives [PERMISSION_DENIED].
    assertThat(retryCodesDef.get(permissionDeniedRetryName).size()).isEqualTo(0);
// assertThat(retryCodesDef.get(permissionDeniedRetryName).iterator().next())
// .isEqualTo(PERMISSION_DENIED.name());
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableList(com.google.common.collect.ImmutableList) RetryCodesConfig(com.google.api.codegen.config.RetryCodesConfig) Test(org.junit.Test)

Aggregations

RetryCodesConfig (com.google.api.codegen.config.RetryCodesConfig)2 ImmutableList (com.google.common.collect.ImmutableList)2 Test (org.junit.Test)2 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)1 BoundedDiagCollector (com.google.api.tools.framework.model.BoundedDiagCollector)1 DiagCollector (com.google.api.tools.framework.model.DiagCollector)1