use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class RetrySettingsComposerTest method batchingSettings_fullFlowControlSettings.
@Test
public void batchingSettings_fullFlowControlSettings() {
String filename = "logging_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 = "logging_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().parseLogging();
Service service = context.services().get(0);
assertEquals("LoggingServiceV2", service.name());
VariableExpr builderVarExpr = createBuilderVarExpr(service);
String methodSettingsName = "writeLogEntriesSettings";
GapicBatchingSettings batchingSettings = GapicBatchingSettings.builder().setProtoPakkage("com.google.logging.v2").setServiceName("LoggingServiceV2").setMethodName("WriteLogEntries").setElementCountThreshold(1000).setRequestByteThreshold(1048576).setDelayThresholdMillis(50).setFlowControlElementLimit(100000).setFlowControlByteLimit(10485760).setFlowControlLimitExceededBehavior(GapicBatchingSettings.FlowControlLimitExceededBehavior.THROW_EXCEPTION).setBatchedFieldName("entries").setDiscriminatorFieldNames(Arrays.asList("log_name", "resource", "labels")).build();
Expr builderExpr = RetrySettingsComposer.createBatchingBuilderSettingsExpr(methodSettingsName, batchingSettings, builderVarExpr);
builderExpr.accept(writerVisitor);
String expected = "builder" + ".writeLogEntriesSettings()" + ".setBatchingSettings(" + "BatchingSettings.newBuilder()" + ".setElementCountThreshold(1000L)" + ".setRequestByteThreshold(1048576L)" + ".setDelayThreshold(Duration.ofMillis(50L))" + ".setFlowControlSettings(" + "FlowControlSettings.newBuilder()" + ".setMaxOutstandingElementCount(100000L)" + ".setMaxOutstandingRequestBytes(10485760L)" + ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.ThrowException)" + ".build())" + ".build())";
assertEquals(expected, writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class SampleCodeWriterTest method createAssignmentExpr.
private static AssignmentExpr createAssignmentExpr(String varName, String varValue, TypeNode type) {
Variable variable = Variable.builder().setName(varName).setType(type).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).setIsDecl(true).build();
return AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(ValueExpr.withValue(PrimitiveValue.builder().setType(type).setValue(varValue).build())).build();
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class SampleCodeWriterTest method setUp.
@BeforeClass
public static void setUp() {
TypeNode settingType = TypeNode.withReference(ConcreteReference.withClazz(ClientSettings.class));
Variable aVar = Variable.builder().setName("clientSettings").setType(settingType).build();
VariableExpr aVarExpr = VariableExpr.withVariable(aVar);
MethodInvocationExpr aValueExpr = MethodInvocationExpr.builder().setExprReferenceExpr(MethodInvocationExpr.builder().setMethodName("newBuilder").setStaticReferenceType(settingType).build()).setReturnType(settingType).setMethodName("build").build();
AssignmentExpr assignmentExpr = AssignmentExpr.builder().setVariableExpr(aVarExpr.toBuilder().setIsDecl(true).build()).setValueExpr(aValueExpr).build();
TryCatchStatement sampleStatement = TryCatchStatement.builder().setTryResourceExpr(createAssignmentExpr("aBool", "false", TypeNode.BOOLEAN)).setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("x", "3", TypeNode.INT)))).setIsSampleCode(true).build();
testingSampleStatements = Arrays.asList(ExprStatement.withExpr(assignmentExpr), sampleStatement);
regionTag = RegionTag.builder().setApiShortName("testing").setApiVersion("v1").setServiceName("samples").setRpcName("write").build();
testingSample = Sample.builder().setFileHeader(Arrays.asList(CommentStatement.withComment(BlockComment.withComment("Apache License")))).setBody(testingSampleStatements).setRegionTag(regionTag).build();
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class SampleComposerUtilTest method handleDuplicateSamples_distinctDuplicates.
@Test
public void handleDuplicateSamples_distinctDuplicates() {
VariableExpr echoClientVariableExprDiffVarName = VariableExpr.withVariable(Variable.builder().setName("echoClient2").setType(clientType).build());
Sample echoClientSampleDiffVarName = echoClientSample.toBuilder().setBody(Arrays.asList(ExprStatement.withExpr(SampleComposerUtil.assignClientVariableWithCreateMethodExpr(echoClientVariableExprDiffVarName)))).build();
List<Sample> samples = Arrays.asList(echoClientSample, echoClientSample, echoClientSampleDiffVarName);
assertEquals(samples.size(), 3);
assertEquals(samples.get(0).name(), "SyncCreate");
assertEquals(samples.get(1).name(), "SyncCreate");
assertEquals(samples.get(2).name(), "SyncCreate");
List<Sample> result = SampleComposerUtil.handleDuplicateSamples(samples);
assertEquals(result.size(), 2);
assertTrue(result.contains(echoClientSample));
assertTrue(result.stream().filter(s -> s.name().equals("SyncCreate1")).findFirst().isPresent());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeWhileStatement_simple.
@Test
public void writeWhileStatement_simple() {
AssignmentExpr assignExpr = createAssignmentExpr("x", "3", TypeNode.INT);
Statement assignExprStatement = ExprStatement.withExpr(assignExpr);
List<Statement> whileBody = Arrays.asList(assignExprStatement, assignExprStatement);
VariableExpr condExpr = createVariableExpr("condition", TypeNode.BOOLEAN);
WhileStatement whileStatement = WhileStatement.builder().setConditionExpr(condExpr).setBody(whileBody).build();
whileStatement.accept(writerVisitor);
assertEquals(LineFormatter.lines("while (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), writerVisitor.write());
}
Aggregations