Skip to content

Commit

Permalink
[ggj][codegen] fix: use BatchingCallSettings for batching methods in …
Browse files Browse the repository at this point in the history
…ServiceSettings (#610)

* fix: delete unused IamCredietialsClientTest golden

* fix: use BatchingCallSettings for batching methods in ServiceSettings
  • Loading branch information
miraleung authored Dec 17, 2020
1 parent bda8a87 commit 6534445
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.BatchingCallSettings;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.OperationCallSettings;
Expand Down Expand Up @@ -797,6 +798,9 @@ private static TypeNode getCallSettingsTypeHelper(
Class callSettingsClazz = isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class;
if (protoMethod.isPaged()) {
callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class;
} else if (protoMethod.isBatching()) {
callSettingsClazz =
isBuilder ? BatchingCallSettings.Builder.class : BatchingCallSettings.class;
} else {
switch (protoMethod.stream()) {
case CLIENT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ public boolean hasBatchingSetting(Service service, Method method) {
return batchingSettingsTable.containsKey(toName(service, method));
}

public boolean hasBatchingSetting(String protoPakkage, String serviceName, String methodName) {
return batchingSettingsTable.containsKey(
MethodConfig.Name.newBuilder()
.setService(String.format("%s.%s", protoPakkage, serviceName))
.setMethod(methodName)
.build());
}

public Optional<GapicLroRetrySettings> getLroRetrySetting(Service service, Method method) {
return hasLroRetrySetting(service, method)
? Optional.of(lroRetrySettingsTable.get(toName(service, method)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum Stream {

public abstract TypeNode outputType();

public abstract boolean isBatching();

public abstract boolean isPaged();

@Nullable
Expand Down Expand Up @@ -70,6 +72,7 @@ public static Builder builder() {
.setStream(Stream.NONE)
.setMethodSignatures(ImmutableList.of())
.setHttpBindings(ImmutableList.of())
.setIsBatching(false)
.setIsPaged(false);
}

Expand Down Expand Up @@ -104,6 +107,8 @@ public abstract static class Builder {

public abstract Builder setMethodSignatures(List<List<MethodArgument>> methodSignature);

public abstract Builder setIsBatching(boolean isBatching);

public abstract Builder setIsPaged(boolean isPaged);

public abstract Method build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ public static List<Service> parseService(
.setOriginalJavaPackage(originalJavaPackage)
.setProtoPakkage(fileDescriptor.getPackage())
.setMethods(
parseMethods(s, pakkage, messageTypes, resourceNames, outputArgResourceNames))
parseMethods(
s,
pakkage,
messageTypes,
resourceNames,
serviceConfigOpt,
outputArgResourceNames))
.build();
})
.collect(Collectors.toList());
Expand Down Expand Up @@ -433,6 +439,7 @@ static List<Method> parseMethods(
String servicePackage,
Map<String, Message> messageTypes,
Map<String, ResourceName> resourceNames,
Optional<GapicServiceConfig> serviceConfigOpt,
Set<ResourceName> outputArgResourceNames) {
List<Method> methods = new ArrayList<>();
for (MethodDescriptor protoMethod : serviceDescriptor.getMethods()) {
Expand All @@ -456,6 +463,15 @@ static List<Method> parseMethods(
HttpRuleParser.parseHttpBindings(protoMethod, inputMessage, messageTypes);
List<String> httpBindings =
httpBindingsOpt.isPresent() ? httpBindingsOpt.get() : Collections.emptyList();
boolean isBatching =
!serviceConfigOpt.isPresent()
? false
: serviceConfigOpt
.get()
.hasBatchingSetting(
/* protoPakkage */ protoMethod.getFile().getPackage(),
serviceDescriptor.getName(),
protoMethod.getName());

methods.add(
methodBuilder
Expand All @@ -474,6 +490,7 @@ static List<Method> parseMethods(
resourceNames,
outputArgResourceNames))
.setHttpBindings(httpBindings)
.setIsBatching(isBatching)
.setIsPaged(parseIsPaged(protoMethod, messageTypes))
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ public void parseMethods_basic() {
Set<ResourceName> outputResourceNames = new HashSet<>();
List<Method> methods =
Parser.parseMethods(
echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames);
echoService,
ECHO_PACKAGE,
messageTypes,
resourceNames,
Optional.empty(),
outputResourceNames);

assertEquals(9, methods.size());

Expand Down Expand Up @@ -153,7 +158,12 @@ public void parseMethods_basicLro() {
Set<ResourceName> outputResourceNames = new HashSet<>();
List<Method> methods =
Parser.parseMethods(
echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames);
echoService,
ECHO_PACKAGE,
messageTypes,
resourceNames,
Optional.empty(),
outputResourceNames);

assertEquals(9, methods.size());

Expand Down Expand Up @@ -199,7 +209,12 @@ public void parseMethodSignatures_empty() {

List<Method> methods =
Parser.parseMethods(
echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames);
echoService,
ECHO_PACKAGE,
messageTypes,
resourceNames,
Optional.empty(),
outputResourceNames);
assertThat(
MethodSignatureParser.parseMethodSignatures(
methodDescriptor,
Expand All @@ -223,7 +238,12 @@ public void parseMethodSignatures_validArgstAndEmptyString() {

List<Method> methods =
Parser.parseMethods(
echoService, ECHO_PACKAGE, messageTypes, resourceNames, outputResourceNames);
echoService,
ECHO_PACKAGE,
messageTypes,
resourceNames,
Optional.empty(),
outputResourceNames);
List<List<MethodArgument>> methodArgs =
MethodSignatureParser.parseMethodSignatures(
methodDescriptor,
Expand Down
5 changes: 3 additions & 2 deletions test/integration/goldens/logging/LoggingSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.BatchingCallSettings;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.PagedCallSettings;
Expand Down Expand Up @@ -87,7 +88,7 @@ public UnaryCallSettings<DeleteLogRequest, Empty> deleteLogSettings() {
}

/** Returns the object with the settings used for calls to writeLogEntries. */
public UnaryCallSettings<WriteLogEntriesRequest, WriteLogEntriesResponse>
public BatchingCallSettings<WriteLogEntriesRequest, WriteLogEntriesResponse>
writeLogEntriesSettings() {
return ((LoggingServiceV2StubSettings) getStubSettings()).writeLogEntriesSettings();
}
Expand Down Expand Up @@ -218,7 +219,7 @@ public UnaryCallSettings.Builder<DeleteLogRequest, Empty> deleteLogSettings() {
}

/** Returns the builder for the settings used for calls to writeLogEntries. */
public UnaryCallSettings.Builder<WriteLogEntriesRequest, WriteLogEntriesResponse>
public BatchingCallSettings.Builder<WriteLogEntriesRequest, WriteLogEntriesResponse>
writeLogEntriesSettings() {
return getStubSettingsBuilder().writeLogEntriesSettings();
}
Expand Down

0 comments on commit 6534445

Please sign in to comment.