Search in sources :

Example 6 with GapicBatchingSettings

use of com.google.api.generator.gapic.model.GapicBatchingSettings in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createClassStatements.

private static List<Statement> createClassStatements(Service service, GapicServiceConfig serviceConfig, Map<String, VariableExpr> methodSettingsMemberVarExprs, Map<String, Message> messageTypes, TypeStore typeStore) {
    Function<Expr, Statement> exprToStatementFn = e -> ExprStatement.withExpr(e);
    List<Statement> statements = new ArrayList<>();
    // Assign DEFAULT_SERVICE_SCOPES.
    statements.add(SettingsCommentComposer.DEFAULT_SCOPES_COMMENT);
    VariableExpr defaultServiceScopesDeclVarExpr = DEFAULT_SERVICE_SCOPES_VAR_EXPR.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsStatic(true).setIsFinal(true).build();
    MethodInvocationExpr listBuilderExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("ImmutableList")).setGenerics(Arrays.asList(ConcreteReference.withClazz(String.class))).setMethodName("builder").build();
    for (String serviceScope : service.oauthScopes()) {
        listBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(listBuilderExpr).setMethodName("add").setArguments(ValueExpr.withValue(StringObjectValue.withValue(serviceScope))).build();
    }
    listBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(listBuilderExpr).setMethodName("build").setReturnType(DEFAULT_SERVICE_SCOPES_VAR_EXPR.type()).build();
    statements.add(exprToStatementFn.apply(AssignmentExpr.builder().setVariableExpr(defaultServiceScopesDeclVarExpr).setValueExpr(listBuilderExpr).build()));
    // Declare settings members.
    statements.addAll(methodSettingsMemberVarExprs.values().stream().map(v -> exprToStatementFn.apply(v.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsFinal(true).build())).collect(Collectors.toList()));
    statements.add(EMPTY_LINE_STATEMENT);
    for (Expr pagingAssignExpr : createPagingStaticAssignExprs(service, serviceConfig, messageTypes, typeStore)) {
        statements.add(exprToStatementFn.apply(pagingAssignExpr));
        statements.add(EMPTY_LINE_STATEMENT);
    }
    for (Method method : service.methods()) {
        Optional<GapicBatchingSettings> batchingSettingOpt = Objects.isNull(serviceConfig) ? Optional.empty() : serviceConfig.getBatchingSetting(service, method);
        if (batchingSettingOpt.isPresent()) {
            statements.add(exprToStatementFn.apply(BatchingDescriptorComposer.createBatchingDescriptorFieldDeclExpr(method, batchingSettingOpt.get(), messageTypes)));
        }
        statements.add(EMPTY_LINE_STATEMENT);
    }
    return statements;
}
Also used : Arrays(java.util.Arrays) BatchingDescriptor(com.google.api.gax.rpc.BatchingDescriptor) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) ServerStreamingCallSettings(com.google.api.gax.rpc.ServerStreamingCallSettings) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) PagedCallSettings(com.google.api.gax.rpc.PagedCallSettings) Empty(com.google.protobuf.Empty) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) PartitionKey(com.google.api.gax.batching.PartitionKey) ApiClientHeaderProvider(com.google.api.gax.rpc.ApiClientHeaderProvider) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) ApiFuture(com.google.api.core.ApiFuture) Duration(org.threeten.bp.Duration) LimitExceededBehavior(com.google.api.gax.batching.FlowController.LimitExceededBehavior) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) BatchedRequestIssuer(com.google.api.gax.rpc.BatchedRequestIssuer) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClientContext(com.google.api.gax.rpc.ClientContext) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) ArrayList(java.util.ArrayList) RetrySettings(com.google.api.gax.retrying.RetrySettings) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) LinkedHashMap(java.util.LinkedHashMap) Expr(com.google.api.generator.engine.ast.Expr) Lists(com.google.common.collect.Lists) StubSettings(com.google.api.gax.rpc.StubSettings) BatchingCallSettings(com.google.api.gax.rpc.BatchingCallSettings) Nullable(javax.annotation.Nullable) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) InstantiatingExecutorProvider(com.google.api.gax.core.InstantiatingExecutorProvider) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) GapicClass(com.google.api.generator.gapic.model.GapicClass) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) RequestBuilder(com.google.api.gax.batching.RequestBuilder) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) StreamingCallSettings(com.google.api.gax.rpc.StreamingCallSettings) ImmutableSet(com.google.common.collect.ImmutableSet) SettingsSampleComposer(com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer) ImmutableMap(com.google.common.collect.ImmutableMap) PageContext(com.google.api.gax.rpc.PageContext) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) OperationCallSettings(com.google.api.gax.rpc.OperationCallSettings) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) SettingsCommentComposer(com.google.api.generator.gapic.composer.comment.SettingsCommentComposer) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) PagedListResponseFactory(com.google.api.gax.rpc.PagedListResponseFactory) HashSet(java.util.HashSet) GaxProperties(com.google.api.gax.core.GaxProperties) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) ImmutableList(com.google.common.collect.ImmutableList) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) OperationTimedPollAlgorithm(com.google.api.gax.longrunning.OperationTimedPollAlgorithm) PagedListDescriptor(com.google.api.gax.rpc.PagedListDescriptor) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) CastExpr(com.google.api.generator.engine.ast.CastExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) IfStatement(com.google.api.generator.engine.ast.IfStatement) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Statement(com.google.api.generator.engine.ast.Statement) ArrayList(java.util.ArrayList) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Method(com.google.api.generator.gapic.model.Method) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings)

Example 7 with GapicBatchingSettings

use of com.google.api.generator.gapic.model.GapicBatchingSettings in project gapic-generator-java by googleapis.

the class Parser method parse.

public static GapicContext parse(CodeGeneratorRequest request) {
    Optional<String> gapicYamlConfigPathOpt = PluginArgumentParser.parseGapicYamlConfigPath(request);
    Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(gapicYamlConfigPathOpt);
    Optional<List<GapicLroRetrySettings>> lroRetrySettingsOpt = GapicLroRetrySettingsParser.parse(gapicYamlConfigPathOpt);
    Optional<GapicLanguageSettings> languageSettingsOpt = GapicLanguageSettingsParser.parse(gapicYamlConfigPathOpt);
    Optional<String> transportOpt = PluginArgumentParser.parseTransport(request);
    boolean willGenerateMetadata = PluginArgumentParser.hasMetadataFlag(request);
    Optional<String> serviceConfigPathOpt = PluginArgumentParser.parseJsonConfigPath(request);
    Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(serviceConfigPathOpt.orElse(null));
    if (serviceConfigOpt.isPresent()) {
        GapicServiceConfig serviceConfig = serviceConfigOpt.get();
        serviceConfig.setLroRetrySettings(lroRetrySettingsOpt);
        serviceConfig.setBatchingSettings(batchingSettingsOpt);
        serviceConfig.setLanguageSettings(languageSettingsOpt);
        serviceConfigOpt = Optional.of(serviceConfig);
    }
    Optional<String> serviceYamlConfigPathOpt = PluginArgumentParser.parseServiceYamlConfigPath(request);
    Optional<com.google.api.Service> serviceYamlProtoOpt = serviceYamlConfigPathOpt.flatMap(ServiceYamlParser::parse);
    // Collect the resource references seen in messages.
    Set<ResourceReference> outputResourceReferencesSeen = new HashSet<>();
    // Keep message and resource name parsing separate for cleaner logic.
    // While this takes an extra pass through the protobufs, the extra time is relatively trivial
    // and is worth the larger reduced maintenance cost.
    Map<String, Message> messages = parseMessages(request, outputResourceReferencesSeen);
    Map<String, ResourceName> resourceNames = parseResourceNames(request);
    messages = updateResourceNamesInMessages(messages, resourceNames.values());
    // Contains only resource names that are actually used. Usage refers to the presence of a
    // request message's field in an RPC's method_signature annotation. That is,  resource name
    // definitions
    // or references that are simply defined, but not used in such a manner, will not have
    // corresponding Java helper
    // classes generated.
    Set<ResourceName> outputArgResourceNames = new HashSet<>();
    List<Service> mixinServices = new ArrayList<>();
    Transport transport = Transport.parse(transportOpt.orElse(Transport.GRPC.toString()));
    List<Service> services = parseServices(request, messages, resourceNames, outputArgResourceNames, serviceYamlProtoOpt, serviceConfigOpt, mixinServices, transport);
    Preconditions.checkState(!services.isEmpty(), "No services found to generate");
    // Temporary workaround for Ads, who still need these resource names.
    if (services.get(0).protoPakkage().startsWith("google.ads.googleads.v")) {
        Function<ResourceName, String> typeNameFn = r -> r.resourceTypeString().substring(r.resourceTypeString().indexOf("/") + 1);
        Function<Set<ResourceName>, Set<String>> typeStringSetFn = sr -> sr.stream().map(typeNameFn).collect(Collectors.toSet());
        // Include all resource names present in message types for backwards-compatibility with the
        // monolith. In the future, this should be removed on a client library major semver update.
        // Resolve type name collisions with the ones present in the method arguments.
        final Set<String> typeStringSet = typeStringSetFn.apply(outputArgResourceNames);
        outputArgResourceNames.addAll(resourceNames.values().stream().filter(r -> r.hasParentMessageName() && !typeStringSet.contains(typeNameFn.apply(r))).collect(Collectors.toSet()));
        String servicePackage = services.get(0).pakkage();
        Map<String, ResourceName> patternsToResourceNames = ResourceParserHelpers.createPatternResourceNameMap(resourceNames);
        for (ResourceReference resourceReference : outputResourceReferencesSeen) {
            final Set<String> interimTypeStringSet = typeStringSetFn.apply(outputArgResourceNames);
            outputArgResourceNames.addAll(ResourceReferenceParser.parseResourceNames(resourceReference, servicePackage, null, resourceNames, patternsToResourceNames).stream().filter(r -> !interimTypeStringSet.contains(typeNameFn.apply(r))).collect(Collectors.toSet()));
        }
    }
    return GapicContext.builder().setServices(services).setMixinServices(mixinServices).setMessages(messages).setResourceNames(resourceNames).setHelperResourceNames(outputArgResourceNames).setServiceConfig(serviceConfigOpt.orElse(null)).setGapicMetadataEnabled(willGenerateMetadata).setServiceYamlProto(serviceYamlProtoOpt.orElse(null)).setTransport(transport).build();
}
Also used : HttpBindings(com.google.api.generator.gapic.model.HttpBindings) CodeGeneratorRequest(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest) Arrays(java.util.Arrays) RoutingHeaderRule(com.google.api.generator.gapic.model.RoutingHeaderRule) OperationInfo(com.google.longrunning.OperationInfo) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) Field(com.google.api.generator.gapic.model.Field) Method(com.google.api.generator.gapic.model.Method) HttpRule(com.google.api.HttpRule) LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Map(java.util.Map) ResourceProto(com.google.api.ResourceProto) FieldOptions(com.google.protobuf.DescriptorProtos.FieldOptions) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) BiMap(com.google.common.collect.BiMap) ResourceDescriptor(com.google.api.ResourceDescriptor) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceReference(com.google.api.generator.gapic.model.ResourceReference) Collection(java.util.Collection) Set(java.util.Set) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) OperationsProto(com.google.longrunning.OperationsProto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ResourceNameConstants(com.google.api.generator.gapic.utils.ResourceNameConstants) List(java.util.List) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) DocumentationRule(com.google.api.DocumentationRule) Optional(java.util.Optional) Transport(com.google.api.generator.gapic.model.Transport) GapicContext(com.google.api.generator.gapic.model.GapicContext) GapicLanguageSettings(com.google.api.generator.gapic.model.GapicLanguageSettings) IntStream(java.util.stream.IntStream) VaporReference(com.google.api.generator.engine.ast.VaporReference) TypeNode(com.google.api.generator.engine.ast.TypeNode) GapicLroRetrySettings(com.google.api.generator.gapic.model.GapicLroRetrySettings) Descriptor(com.google.protobuf.Descriptors.Descriptor) HashMap(java.util.HashMap) Function(java.util.function.Function) OperationResponseMapping(com.google.cloud.OperationResponseMapping) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) Maps(com.google.common.collect.Maps) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) HashBiMap(com.google.common.collect.HashBiMap) ServiceOptions(com.google.protobuf.DescriptorProtos.ServiceOptions) ExtendedOperationsProto(com.google.cloud.ExtendedOperationsProto) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) Preconditions(com.google.common.base.Preconditions) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) OperationResponse(com.google.api.generator.gapic.model.OperationResponse) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Message(com.google.api.generator.gapic.model.Message) MethodOptions(com.google.protobuf.DescriptorProtos.MethodOptions) Collections(java.util.Collections) ClientProto(com.google.api.ClientProto) MessageOptions(com.google.protobuf.DescriptorProtos.MessageOptions) SourceCodeInfoLocation(com.google.api.generator.gapic.model.SourceCodeInfoLocation) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) ArrayList(java.util.ArrayList) GapicLanguageSettings(com.google.api.generator.gapic.model.GapicLanguageSettings) List(java.util.List) ArrayList(java.util.ArrayList) ResourceReference(com.google.api.generator.gapic.model.ResourceReference) HashSet(java.util.HashSet) Service(com.google.api.generator.gapic.model.Service) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) Transport(com.google.api.generator.gapic.model.Transport)

Example 8 with GapicBatchingSettings

use of com.google.api.generator.gapic.model.GapicBatchingSettings in project gapic-generator-java by googleapis.

the class RetrySettingsComposerTest method batchingSettings_minimalFlowControlSettings.

@Test
public void batchingSettings_minimalFlowControlSettings() {
    String filename = "pubsub_gapic.yaml";
    Path path = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), filename);
    Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
    assertTrue(batchingSettingsOpt.isPresent());
    String jsonFilename = "pubsub_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    config.setBatchingSettings(batchingSettingsOpt);
    GapicContext context = TestProtoLoader.instance().parsePubSubPublisher();
    Service service = context.services().get(0);
    assertEquals("Publisher", service.name());
    VariableExpr builderVarExpr = createBuilderVarExpr(service);
    String methodSettingsName = "publishSettings";
    GapicBatchingSettings batchingSettings = GapicBatchingSettings.builder().setProtoPakkage("com.google.pubsub.v1").setServiceName("Publishing").setMethodName("Publish").setElementCountThreshold(100).setRequestByteThreshold(1048576).setDelayThresholdMillis(10).setBatchedFieldName("messages").setDiscriminatorFieldNames(Arrays.asList("topic")).setSubresponseFieldName("message_ids").build();
    Expr builderExpr = RetrySettingsComposer.createBatchingBuilderSettingsExpr(methodSettingsName, batchingSettings, builderVarExpr);
    builderExpr.accept(writerVisitor);
    String expected = "builder" + ".publishSettings()" + ".setBatchingSettings(" + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(100L)" + ".setRequestByteThreshold(1048576L)" + ".setDelayThreshold(Duration.ofMillis(10L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore)" + ".build())" + ".build())";
    assertEquals(expected, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Expr(com.google.api.generator.engine.ast.Expr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Service(com.google.api.generator.gapic.model.Service) List(java.util.List) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) GapicContext(com.google.api.generator.gapic.model.GapicContext) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) Test(org.junit.Test)

Example 9 with GapicBatchingSettings

use of com.google.api.generator.gapic.model.GapicBatchingSettings in project gapic-generator-java by googleapis.

the class BatchingSettingsConfigParserTest method parseBatchingSettings_logging.

@Test
public void parseBatchingSettings_logging() {
    String filename = "logging_gapic.yaml";
    Path path = Paths.get(YAML_DIRECTORY, filename);
    Optional<List<GapicBatchingSettings>> settingsOpt = BatchingSettingsConfigParser.parse(path.toString());
    assertTrue(settingsOpt.isPresent());
    List<GapicBatchingSettings> batchingSettings = settingsOpt.get();
    assertEquals(1, batchingSettings.size());
    GapicBatchingSettings setting = batchingSettings.get(0);
    assertEquals("google.logging.v2", setting.protoPakkage());
    assertEquals("LoggingServiceV2", setting.serviceName());
    assertEquals("WriteLogEntries", setting.methodName());
    assertEquals(1000, setting.elementCountThreshold());
    assertEquals(1048576, setting.requestByteThreshold());
    assertEquals(50, setting.delayThresholdMillis());
    assertThat(setting.flowControlElementLimit()).isNotNull();
    assertEquals(100000, (long) setting.flowControlElementLimit());
    assertThat(setting.flowControlByteLimit()).isNotNull();
    assertEquals(10485760, (long) setting.flowControlByteLimit());
    assertEquals(GapicBatchingSettings.FlowControlLimitExceededBehavior.THROW_EXCEPTION, setting.flowControlLimitExceededBehavior());
    assertEquals("entries", setting.batchedFieldName());
    assertThat(setting.discriminatorFieldNames()).containsExactly("log_name", "resource", "labels");
    assertThat(setting.subresponseFieldName()).isNull();
}
Also used : Path(java.nio.file.Path) List(java.util.List) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) Test(org.junit.Test)

Aggregations

GapicBatchingSettings (com.google.api.generator.gapic.model.GapicBatchingSettings)9 List (java.util.List)8 GapicServiceConfig (com.google.api.generator.gapic.model.GapicServiceConfig)6 Service (com.google.api.generator.gapic.model.Service)6 Path (java.nio.file.Path)6 Test (org.junit.Test)6 Expr (com.google.api.generator.engine.ast.Expr)5 Method (com.google.api.generator.gapic.model.Method)5 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)4 GapicContext (com.google.api.generator.gapic.model.GapicContext)4 Message (com.google.api.generator.gapic.model.Message)4 HashSet (java.util.HashSet)4 TypeNode (com.google.api.generator.engine.ast.TypeNode)3 ArrayList (java.util.ArrayList)3 VaporReference (com.google.api.generator.engine.ast.VaporReference)2 Field (com.google.api.generator.gapic.model.Field)2 ResourceName (com.google.api.generator.gapic.model.ResourceName)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)2