Search in sources :

Example 6 with BlockStatement

use of com.google.api.generator.engine.ast.BlockStatement in project gapic-generator-java by googleapis.

the class RetrySettingsComposerTest method paramDefinitionsBlock_noConfigsFound.

@Test
public void paramDefinitionsBlock_noConfigsFound() {
    GapicContext context = TestProtoLoader.instance().parseShowcaseEcho();
    Service service = context.services().get(0);
    String jsonFilename = "retrying_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(serviceConfigOpt.isPresent());
    GapicServiceConfig serviceConfig = serviceConfigOpt.get();
    BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryParamDefinitionsBlock(service, serviceConfig, RETRY_PARAM_DEFINITIONS_VAR_EXPR);
    paramDefinitionsBlock.accept(writerVisitor);
    String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();\n", "RetrySettings settings = null;\n", "settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build();\n", "definitions.put(\"no_retry_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n");
    assertEquals(expected, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Service(com.google.api.generator.gapic.model.Service) BlockStatement(com.google.api.generator.engine.ast.BlockStatement) GapicContext(com.google.api.generator.gapic.model.GapicContext) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) Test(org.junit.Test)

Example 7 with BlockStatement

use of com.google.api.generator.engine.ast.BlockStatement in project gapic-generator-java by googleapis.

the class RetrySettingsComposerTest method codesDefinitionsBlock_noConfigsFound.

@Test
public void codesDefinitionsBlock_noConfigsFound() {
    FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    assertEquals(1, services.size());
    Service service = services.get(0);
    String jsonFilename = "retrying_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(serviceConfigOpt.isPresent());
    GapicServiceConfig serviceConfig = serviceConfigOpt.get();
    BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryCodesDefinitionsBlock(service, serviceConfig, RETRY_CODES_DEFINITIONS_VAR_EXPR);
    paramDefinitionsBlock.accept(writerVisitor);
    String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =" + " ImmutableMap.builder();\n", "definitions.put(\"no_retry_codes\"," + " ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));\n", "RETRYABLE_CODE_DEFINITIONS = definitions.build();\n", "}\n");
    assertEquals(expected, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) BlockStatement(com.google.api.generator.engine.ast.BlockStatement) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with BlockStatement

use of com.google.api.generator.engine.ast.BlockStatement in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeBlockStatement_static.

@Test
public void writeBlockStatement_static() {
    TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.some.pakkage").build());
    MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("foobar").setStaticReferenceType(someType).build();
    BlockStatement blockStatement = BlockStatement.builder().setIsStatic(true).setBody(Arrays.asList(ExprStatement.withExpr(methodExpr), ExprStatement.withExpr(methodExpr))).build();
    blockStatement.accept(writerVisitor);
    assertEquals("static {\nSomeClass.foobar();\nSomeClass.foobar();\n}\n", writerVisitor.write());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) BlockStatement(com.google.api.generator.engine.ast.BlockStatement) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 9 with BlockStatement

use of com.google.api.generator.engine.ast.BlockStatement in project gapic-generator-java by googleapis.

the class RetrySettingsComposerTest method paramDefinitionsBlock_basic.

@Test
public void paramDefinitionsBlock_basic() {
    GapicContext context = TestProtoLoader.instance().parseShowcaseEcho();
    Service service = context.services().get(0);
    String jsonFilename = "showcase_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(serviceConfigOpt.isPresent());
    GapicServiceConfig serviceConfig = serviceConfigOpt.get();
    BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryParamDefinitionsBlock(service, serviceConfig, RETRY_PARAM_DEFINITIONS_VAR_EXPR);
    paramDefinitionsBlock.accept(writerVisitor);
    String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();\n", "RetrySettings settings = null;\n", "settings =" + " RetrySettings.newBuilder().setInitialRetryDelay(" + "Duration.ofMillis(100L)).setRetryDelayMultiplier(2.0)" + ".setMaxRetryDelay(Duration.ofMillis(3000L))" + ".setInitialRpcTimeout(Duration.ofMillis(10000L))" + ".setRpcTimeoutMultiplier(1.0)" + ".setMaxRpcTimeout(Duration.ofMillis(10000L))" + ".setTotalTimeout(Duration.ofMillis(10000L)).build();\n", "definitions.put(\"retry_policy_1_params\", settings);\n", "settings =" + " RetrySettings.newBuilder()" + ".setInitialRpcTimeout(Duration.ofMillis(5000L))" + ".setRpcTimeoutMultiplier(1.0)" + ".setMaxRpcTimeout(Duration.ofMillis(5000L))" + ".setTotalTimeout(Duration.ofMillis(5000L)).build();\n", "definitions.put(\"no_retry_0_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n");
    assertEquals(expected, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Service(com.google.api.generator.gapic.model.Service) BlockStatement(com.google.api.generator.engine.ast.BlockStatement) GapicContext(com.google.api.generator.gapic.model.GapicContext) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) Test(org.junit.Test)

Aggregations

BlockStatement (com.google.api.generator.engine.ast.BlockStatement)9 Test (org.junit.Test)7 GapicServiceConfig (com.google.api.generator.gapic.model.GapicServiceConfig)6 Service (com.google.api.generator.gapic.model.Service)6 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)4 TypeNode (com.google.api.generator.engine.ast.TypeNode)4 Path (java.nio.file.Path)4 BatchingSettings (com.google.api.gax.batching.BatchingSettings)2 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)2 FlowController (com.google.api.gax.batching.FlowController)2 ProtoOperationTransformers (com.google.api.gax.grpc.ProtoOperationTransformers)2 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)2 OperationTimedPollAlgorithm (com.google.api.gax.longrunning.OperationTimedPollAlgorithm)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)2 StatusCode (com.google.api.gax.rpc.StatusCode)2 UnaryCallSettings (com.google.api.gax.rpc.UnaryCallSettings)2 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)2 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)2 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)2 Expr (com.google.api.generator.engine.ast.Expr)2