Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Gapic-Generator to generate libraries using java.time methods #3321

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ target/
**/build/
**/dist/
library_generation/**/*.jar

**/google-java-format.jar
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -120,7 +121,6 @@
import java.util.stream.Collectors;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.threeten.bp.Duration;

public abstract class AbstractServiceStubSettingsClassComposer implements ClassComposer {
private static final Statement EMPTY_LINE_STATEMENT = EmptyLineStatement.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static Expr createBatchingBuilderSettingsExpr(
batchingSettingsBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(batchingSettingsBuilderExpr)
.setMethodName("setDelayThreshold")
.setMethodName("setDelayThresholdDuration")
.setArguments(
createDurationOfMillisExpr(toValExpr(batchingSettings.delayThresholdMillis())))
.build();
Expand Down Expand Up @@ -511,7 +511,7 @@ private static List<Expr> createRetrySettingsExprs(
settingsBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(settingsBuilderExpr)
.setMethodName("setInitialRetryDelay")
.setMethodName("setInitialRetryDelayDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(retryPolicy.getInitialBackoff())))
.build();

Expand All @@ -528,7 +528,7 @@ private static List<Expr> createRetrySettingsExprs(
settingsBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(settingsBuilderExpr)
.setMethodName("setMaxRetryDelay")
.setMethodName("setMaxRetryDelayDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(retryPolicy.getMaxBackoff())))
.build();
}
Expand All @@ -537,7 +537,7 @@ private static List<Expr> createRetrySettingsExprs(
settingsBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(settingsBuilderExpr)
.setMethodName("setInitialRpcTimeout")
.setMethodName("setInitialRpcTimeoutDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(settings.timeout())))
.build();
}
Expand All @@ -553,7 +553,8 @@ private static List<Expr> createRetrySettingsExprs(
.build();

if (!settings.kind().equals(GapicRetrySettings.Kind.NONE)) {
for (String setterMethodName : Arrays.asList("setMaxRpcTimeout", "setTotalTimeout")) {
for (String setterMethodName :
Arrays.asList("setMaxRpcTimeoutDuration", "setTotalTimeoutDuration")) {
settingsBuilderExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(settingsBuilderExpr)
Expand Down Expand Up @@ -614,7 +615,7 @@ private static Expr createLroRetrySettingsExpr(
lroRetrySettingsExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(lroRetrySettingsExpr)
.setMethodName("setInitialRetryDelay")
.setMethodName("setInitialRetryDelayDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(initialPollDelayMillis)))
.build();

Expand All @@ -628,7 +629,7 @@ private static Expr createLroRetrySettingsExpr(
lroRetrySettingsExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(lroRetrySettingsExpr)
.setMethodName("setMaxRetryDelay")
.setMethodName("setMaxRetryDelayDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(maxPollDelayMillis)))
.build();

Expand All @@ -638,7 +639,7 @@ private static Expr createLroRetrySettingsExpr(
lroRetrySettingsExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(lroRetrySettingsExpr)
.setMethodName("setInitialRpcTimeout")
.setMethodName("setInitialRpcTimeoutDuration")
.setArguments(zeroDurationExpr)
.build();

Expand All @@ -654,14 +655,14 @@ private static Expr createLroRetrySettingsExpr(
lroRetrySettingsExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(lroRetrySettingsExpr)
.setMethodName("setMaxRpcTimeout")
.setMethodName("setMaxRpcTimeoutDuration")
.setArguments(zeroDurationExpr)
.build();

lroRetrySettingsExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(lroRetrySettingsExpr)
.setMethodName("setTotalTimeout")
.setMethodName("setTotalTimeoutDuration")
.setArguments(createDurationOfMillisExpr(toValExpr(totalPollTimeoutMillis)))
.build();

Expand Down Expand Up @@ -714,7 +715,7 @@ private static TypeStore createStaticTypes() {
List<Class<?>> concreteClazzes =
Arrays.asList(
BatchingSettings.class,
org.threeten.bp.Duration.class,
java.time.Duration.class,
FlowControlSettings.class,
FlowController.LimitExceededBehavior.class,
ImmutableMap.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public static Optional<Sample> composeSettingsSample(
.build();

// Builder with set value method
// e.g foobarSettingBuilder.fooSetting().setRetrySettings(
// echoSettingsBuilder.echoSettings().getRetrySettings().toBuilder().setTotalTimeout(Duration.ofSeconds(30)).build());
// e.g. foobarSettingBuilder.fooSetting().setRetrySettings(
// echoSettingsBuilder.echoSettings().getRetrySettings().toBuilder()
// .setTotalTimeoutDuration(Duration.ofSeconds(30)).build());
MethodInvocationExpr settingBuilderMethodInvocationExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(localSettingsVarExpr)
.setMethodName(
JavaStyle.toLowerCamelCase(String.format("%sSettings", methodNameOpt.get())))
.build();
String disambiguation = "Settings";
MethodInvocationExpr retrySettingsArgExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(settingBuilderMethodInvocationExpr)
Expand Down Expand Up @@ -364,7 +364,7 @@ public static Optional<Sample> composeLroSettingsSample(
retrySettingsArgExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(retrySettingsArgExpr)
.setMethodName("setMaxRetryDelay")
.setMethodName("setMaxRetryDelayDuration")
.setArguments(ofFiveThousandMillisMethodInvocationExpr)
.build();
retrySettingsArgExpr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ void paramDefinitionsBlock_basic() {
"ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();\n",
"RetrySettings settings = null;\n",
"settings ="
+ " RetrySettings.newBuilder().setInitialRetryDelay("
+ " RetrySettings.newBuilder().setInitialRetryDelayDuration("
+ "Duration.ofMillis(100L)).setRetryDelayMultiplier(2.0)"
+ ".setMaxRetryDelay(Duration.ofMillis(3000L))"
+ ".setInitialRpcTimeout(Duration.ofMillis(10000L))"
+ ".setMaxRetryDelayDuration(Duration.ofMillis(3000L))"
+ ".setInitialRpcTimeoutDuration(Duration.ofMillis(10000L))"
+ ".setRpcTimeoutMultiplier(1.0)"
+ ".setMaxRpcTimeout(Duration.ofMillis(10000L))"
+ ".setTotalTimeout(Duration.ofMillis(10000L)).build();\n",
+ ".setMaxRpcTimeoutDuration(Duration.ofMillis(10000L))"
+ ".setTotalTimeoutDuration(Duration.ofMillis(10000L)).build();\n",
"definitions.put(\"retry_policy_1_params\", settings);\n",
"settings ="
+ " RetrySettings.newBuilder()"
+ ".setInitialRpcTimeout(Duration.ofMillis(5000L))"
+ ".setInitialRpcTimeoutDuration(Duration.ofMillis(5000L))"
+ ".setRpcTimeoutMultiplier(1.0)"
+ ".setMaxRpcTimeout(Duration.ofMillis(5000L))"
+ ".setTotalTimeout(Duration.ofMillis(5000L)).build();\n",
+ ".setMaxRpcTimeoutDuration(Duration.ofMillis(5000L))"
+ ".setTotalTimeoutDuration(Duration.ofMillis(5000L)).build();\n",
"definitions.put(\"no_retry_0_params\", settings);\n",
"RETRY_PARAM_DEFINITIONS = definitions.build();\n",
"}\n");
Expand Down Expand Up @@ -341,10 +341,10 @@ void lroBuilderExpr() {
+ "WaitResponse.class))"
+ ".setMetadataTransformer(ProtoOperationTransformers.MetadataTransformer.create("
+ "WaitMetadata.class)).setPollingAlgorithm(OperationTimedPollAlgorithm.create("
+ "RetrySettings.newBuilder().setInitialRetryDelay(Duration.ofMillis(5000L))"
+ ".setRetryDelayMultiplier(1.5).setMaxRetryDelay(Duration.ofMillis(45000L))"
+ ".setInitialRpcTimeout(Duration.ZERO).setRpcTimeoutMultiplier(1.0)"
+ ".setMaxRpcTimeout(Duration.ZERO).setTotalTimeout(Duration.ofMillis(300000L))"
+ "RetrySettings.newBuilder().setInitialRetryDelayDuration(Duration.ofMillis(5000L))"
+ ".setRetryDelayMultiplier(1.5).setMaxRetryDelayDuration(Duration.ofMillis(45000L))"
+ ".setInitialRpcTimeoutDuration(Duration.ZERO).setRpcTimeoutMultiplier(1.0)"
+ ".setMaxRpcTimeoutDuration(Duration.ZERO).setTotalTimeoutDuration(Duration.ofMillis(300000L))"
+ ".build()))");
assertEquals(expected, writerVisitor.write());
}
Expand Down Expand Up @@ -394,7 +394,7 @@ void batchingSettings_minimalFlowControlSettings() {
+ "BatchingSettings.newBuilder()"
+ ".setElementCountThreshold(100L)"
+ ".setRequestByteThreshold(1048576L)"
+ ".setDelayThreshold(Duration.ofMillis(10L))"
+ ".setDelayThresholdDuration(Duration.ofMillis(10L))"
+ ".setFlowControlSettings("
+ "FlowControlSettings.newBuilder()"
+ ".setLimitExceededBehavior(FlowController.LimitExceededBehavior.Ignore)"
Expand Down Expand Up @@ -451,7 +451,7 @@ void batchingSettings_fullFlowControlSettings() {
+ "BatchingSettings.newBuilder()"
+ ".setElementCountThreshold(1000L)"
+ ".setRequestByteThreshold(1048576L)"
+ ".setDelayThreshold(Duration.ofMillis(50L))"
+ ".setDelayThresholdDuration(Duration.ofMillis(50L))"
+ ".setFlowControlSettings("
+ "FlowControlSettings.newBuilder()"
+ ".setMaxOutstandingElementCount(100000L)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import com.google.common.collect.Lists;
import com.google.protobuf.Empty;
import com.google.testdata.v1.FibonacciRequest;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import javax.annotation.Generated;
import org.threeten.bp.Duration;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
Expand Down Expand Up @@ -206,10 +206,10 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRpcTimeout(Duration.ofMillis(60000L))
.setInitialRpcTimeoutDuration(Duration.ofMillis(60000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(60000L))
.setTotalTimeout(Duration.ofMillis(60000L))
.setMaxRpcTimeoutDuration(Duration.ofMillis(60000L))
.setTotalTimeoutDuration(Duration.ofMillis(60000L))
.build();
definitions.put("no_retry_0_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import javax.annotation.Generated;
* RetrySettings.newBuilder()
* .setInitialRetryDelayDuration(Duration.ofMillis(500))
* .setRetryDelayMultiplier(1.5)
* .setMaxRetryDelay(Duration.ofMillis(5000))
* .setMaxRetryDelayDuration(Duration.ofMillis(5000))
* .setTotalTimeoutDuration(Duration.ofHours(24))
* .build());
* echoSettingsBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import com.google.showcase.v1beta1.WaitMetadata;
import com.google.showcase.v1beta1.WaitRequest;
import com.google.showcase.v1beta1.WaitResponse;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import javax.annotation.Generated;
import org.threeten.bp.Duration;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
Expand Down Expand Up @@ -118,7 +118,7 @@ import org.threeten.bp.Duration;
* RetrySettings.newBuilder()
* .setInitialRetryDelayDuration(Duration.ofMillis(500))
* .setRetryDelayMultiplier(1.5)
* .setMaxRetryDelay(Duration.ofMillis(5000))
* .setMaxRetryDelayDuration(Duration.ofMillis(5000))
* .setTotalTimeoutDuration(Duration.ofHours(24))
* .build());
* echoSettingsBuilder
Expand Down Expand Up @@ -438,21 +438,21 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setInitialRetryDelayDuration(Duration.ofMillis(100L))
.setRetryDelayMultiplier(2.0)
.setMaxRetryDelay(Duration.ofMillis(3000L))
.setInitialRpcTimeout(Duration.ofMillis(10000L))
.setMaxRetryDelayDuration(Duration.ofMillis(3000L))
.setInitialRpcTimeoutDuration(Duration.ofMillis(10000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(10000L))
.setTotalTimeout(Duration.ofMillis(10000L))
.setMaxRpcTimeoutDuration(Duration.ofMillis(10000L))
.setTotalTimeoutDuration(Duration.ofMillis(10000L))
.build();
definitions.put("retry_policy_1_params", settings);
settings =
RetrySettings.newBuilder()
.setInitialRpcTimeout(Duration.ofMillis(5000L))
.setInitialRpcTimeoutDuration(Duration.ofMillis(5000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(5000L))
.setTotalTimeout(Duration.ofMillis(5000L))
.setMaxRpcTimeoutDuration(Duration.ofMillis(5000L))
.setTotalTimeoutDuration(Duration.ofMillis(5000L))
.build();
definitions.put("no_retry_0_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
Expand Down Expand Up @@ -575,13 +575,13 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(5000L))
.setInitialRetryDelayDuration(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelay(Duration.ofMillis(45000L))
.setInitialRpcTimeout(Duration.ZERO)
.setMaxRetryDelayDuration(Duration.ofMillis(45000L))
.setInitialRpcTimeoutDuration(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ZERO)
.setTotalTimeout(Duration.ofMillis(300000L))
.setMaxRpcTimeoutDuration(Duration.ZERO)
.setTotalTimeoutDuration(Duration.ofMillis(300000L))
.build()));

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ import com.google.logging.v2.WriteLogEntriesRequest;
import com.google.logging.v2.WriteLogEntriesResponse;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.time.Duration;
import java.util.Collection;
import java.util.List;
import javax.annotation.Generated;
import org.threeten.bp.Duration;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
Expand Down Expand Up @@ -557,24 +557,24 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setInitialRetryDelayDuration(Duration.ofMillis(100L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(60000L))
.setMaxRetryDelayDuration(Duration.ofMillis(60000L))
.setInitialRpcTimeoutDuration(Duration.ofMillis(60000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(60000L))
.setTotalTimeout(Duration.ofMillis(60000L))
.setMaxRpcTimeoutDuration(Duration.ofMillis(60000L))
.setTotalTimeoutDuration(Duration.ofMillis(60000L))
.build();
definitions.put("retry_policy_1_params", settings);
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setInitialRetryDelayDuration(Duration.ofMillis(100L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(3600000L))
.setMaxRetryDelayDuration(Duration.ofMillis(60000L))
.setInitialRpcTimeoutDuration(Duration.ofMillis(3600000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(3600000L))
.setTotalTimeout(Duration.ofMillis(3600000L))
.setMaxRpcTimeoutDuration(Duration.ofMillis(3600000L))
.setTotalTimeoutDuration(Duration.ofMillis(3600000L))
.build();
definitions.put("retry_policy_2_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
Expand Down Expand Up @@ -651,7 +651,7 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
BatchingSettings.newBuilder()
.setElementCountThreshold(1000L)
.setRequestByteThreshold(1048576L)
.setDelayThreshold(Duration.ofMillis(50L))
.setDelayThresholdDuration(Duration.ofMillis(50L))
.setFlowControlSettings(
FlowControlSettings.newBuilder()
.setMaxOutstandingElementCount(100000L)
Expand Down
Loading
Loading