From 8dd66d56ae9a0cb25171e466dcd8dc1e78660872 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Wed, 4 Dec 2024 21:10:25 -0500 Subject: [PATCH] feat: introduce `java.time` methods and variables (#2780) This PR introduces `java.time` alternatives to existing `org.threeten.bp.*` methods, as well as switching internal variables (if any) to `java.time` The main constraint is to keep the changes backwards compatible, so for each existing threeten method "`method1(org.threeten.bp.Duration)`" we will add an alternative with a _Duration_ (or _Timestamp_ when applicable) suffix: "`method1Duration(java.time.Duration)`". For most cases, the implementation will be held in the `java.time` method and the old threeten method will just delegate the call to it. However, for the case of abstract classes, the implementation will be kept in the threeten method to avoid breaking changes (i.e. users that already overloaded the method in their user code). --- .../clirr-ignored-differences.xml | 16 +++ .../cloud/bigquery/storage/util/Errors.java | 2 +- .../storage/util/TimeConversionUtils.java | 61 +++++++++++ .../bigquery/storage/v1/CivilTimeEncoder.java | 98 ++++++++++++----- .../storage/v1/JsonToProtoMessage.java | 31 +++--- .../bigquery/storage/v1/StreamWriter.java | 4 +- .../readrows/ApiResultRetryAlgorithm.java | 8 +- .../readrows/ReadRowsAttemptCallable.java | 6 +- .../readrows/ApiResultRetryAlgorithm.java | 8 +- .../readrows/ReadRowsAttemptCallable.java | 6 +- .../storage/v1beta2/CivilTimeEncoder.java | 103 +++++++++++++----- .../storage/v1beta2/JsonToProtoMessage.java | 16 ++- .../readrows/ApiResultRetryAlgorithm.java | 8 +- .../readrows/ReadRowsAttemptCallable.java | 6 +- .../bigquery/storage/util/ErrorsTest.java | 2 +- .../storage/v1/ConnectionWorkerPoolTest.java | 4 +- .../storage/v1/ConnectionWorkerTest.java | 10 +- .../storage/v1/FakeBigQueryWrite.java | 2 +- .../storage/v1/FakeBigQueryWriteImpl.java | 2 +- .../v1/FakeScheduledExecutorService.java | 4 +- .../storage/v1/JsonStreamWriterTest.java | 6 +- .../storage/v1/JsonToProtoMessageTest.java | 18 ++- .../bigquery/storage/v1/StreamWriterTest.java | 35 +++--- .../storage/v1/it/ITBigQueryStorageTest.java | 22 ++-- .../v1/it/ITBigQueryTimeEncoderTest.java | 26 +++-- .../it/ITBigQueryWriteManualClientTest.java | 14 ++- .../storage/v1/it/WriteRetryTestUtil.java | 10 +- .../EnhancedBigQueryReadStubSettingsTest.java | 30 ++--- .../v1beta1/it/ITBigQueryStorageTest.java | 18 +-- ...hancedBigQueryStorageStubSettingsTest.java | 30 ++--- .../storage/v1beta2/CivilTimeEncoderTest.java | 60 +++++----- .../storage/v1beta2/FakeBigQueryWrite.java | 2 +- .../v1beta2/FakeBigQueryWriteImpl.java | 2 +- .../v1beta2/FakeScheduledExecutorService.java | 4 +- .../storage/v1beta2/JsonStreamWriterTest.java | 6 +- .../v1beta2/JsonToProtoMessageTest.java | 7 +- .../storage/v1beta2/StreamWriterV2Test.java | 2 +- .../v1beta2/it/ITBigQueryStorageTest.java | 18 +-- .../EnhancedBigQueryReadStubSettingsTest.java | 30 ++--- .../src/test/proto/jsonTest.proto | 10 +- 40 files changed, 473 insertions(+), 274 deletions(-) create mode 100644 google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/TimeConversionUtils.java diff --git a/google-cloud-bigquerystorage/clirr-ignored-differences.xml b/google-cloud-bigquerystorage/clirr-ignored-differences.xml index 8e6c8958df..cc4806cc7b 100644 --- a/google-cloud-bigquerystorage/clirr-ignored-differences.xml +++ b/google-cloud-bigquerystorage/clirr-ignored-differences.xml @@ -212,5 +212,21 @@ com/google/cloud/bigquery/storage/v1/StreamWriter void setMissingValueInterpretationMap(java.util.Map) + + + 6004 + com/google/cloud/bigquery/storage/*/stub/readrows/ApiResultRetryAlgorithm + DEADLINE_SLEEP_DURATION + org.threeten.bp.Duration + java.time.Duration + + + + 6004 + com/google/cloud/bigquery/storage/util/Errors$IsRetryableStatusResult + retryDelay + org.threeten.bp.Duration + java.time.Duration + diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java index c0adc0a151..30fc70dc45 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/Errors.java @@ -19,7 +19,7 @@ import io.grpc.Metadata; import io.grpc.Status; import io.grpc.protobuf.ProtoUtils; -import org.threeten.bp.Duration; +import java.time.Duration; /** Static utility methods for working with Errors returned from the service. */ public class Errors { diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/TimeConversionUtils.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/TimeConversionUtils.java new file mode 100644 index 0000000000..ff72b4846b --- /dev/null +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/util/TimeConversionUtils.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.bigquery.storage.util; + +import com.google.api.core.InternalApi; + +/** + * Convenience methods for conversions between {@link java.time} and {@link org.threeten.bp} + * objects. This will be kept until this issue is solved. + */ +@InternalApi("https://github.com/googleapis/sdk-platform-java/issues/3412") +public class TimeConversionUtils { + public static java.time.LocalDateTime toJavaTimeLocalDateTime( + org.threeten.bp.LocalDateTime result) { + return java.time.LocalDateTime.of( + result.getYear(), + java.time.Month.of(result.getMonth().getValue()), + result.getDayOfMonth(), + result.getHour(), + result.getMinute(), + result.getSecond(), + result.getNano()); + } + + public static org.threeten.bp.LocalDateTime toThreetenLocalDateTime( + java.time.LocalDateTime result) { + return org.threeten.bp.LocalDateTime.of( + result.getYear(), + org.threeten.bp.Month.of(result.getMonth().getValue()), + result.getDayOfMonth(), + result.getHour(), + result.getMinute(), + result.getSecond(), + result.getNano()); + } + + public static java.time.LocalTime toJavaTimeLocalTime(org.threeten.bp.LocalTime result) { + return java.time.LocalTime.of( + result.getHour(), result.getMinute(), result.getSecond(), result.getNano()); + } + + public static org.threeten.bp.LocalTime toThreetenLocalTime(java.time.LocalTime result) { + return org.threeten.bp.LocalTime.of( + result.getHour(), result.getMinute(), result.getSecond(), result.getNano()); + } +} diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/CivilTimeEncoder.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/CivilTimeEncoder.java index e52ada64d8..30a3b0176d 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/CivilTimeEncoder.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/CivilTimeEncoder.java @@ -15,12 +15,15 @@ */ package com.google.cloud.bigquery.storage.v1; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toJavaTimeLocalDateTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toJavaTimeLocalTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toThreetenLocalDateTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toThreetenLocalTime; import static com.google.common.base.Preconditions.checkArgument; -import org.threeten.bp.DateTimeException; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; -import org.threeten.bp.temporal.ChronoUnit; +import com.google.api.core.ObsoleteApi; +import java.time.DateTimeException; +import java.time.temporal.ChronoUnit; /** * Ported from ZetaSQL CivilTimeEncoder Original code can be found at: @@ -89,7 +92,7 @@ public final class CivilTimeEncoder { * @see #decodePacked32TimeSeconds(int) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static int encodePacked32TimeSeconds(LocalTime time) { + private static int encodePacked32TimeSeconds(java.time.LocalTime time) { checkValidTimeSeconds(time); int bitFieldTimeSeconds = 0x0; bitFieldTimeSeconds |= time.getHour() << HOUR_SHIFT; @@ -112,19 +115,29 @@ private static int encodePacked32TimeSeconds(LocalTime time) { * @see #encodePacked32TimeSeconds(LocalTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { + private static java.time.LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { checkValidBitField(bitFieldTimeSeconds, TIME_SECONDS_MASK); int hourOfDay = getFieldFromBitField(bitFieldTimeSeconds, HOUR_MASK, HOUR_SHIFT); int minuteOfHour = getFieldFromBitField(bitFieldTimeSeconds, MINUTE_MASK, MINUTE_SHIFT); int secondOfMinute = getFieldFromBitField(bitFieldTimeSeconds, SECOND_MASK, SECOND_SHIFT); // LocalTime validates the input parameters. try { - return LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute); + return java.time.LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute); } catch (DateTimeException e) { throw new IllegalArgumentException(e.getMessage(), e); } } + /** + * This method is obsolete. Use {@link #encodePacked64TimeMicrosLocalTime(java.time.LocalTime)} + * instead. + */ + @ObsoleteApi("Use encodePacked64TimeMicrosLocalTime(java.time.LocalTime) instead") + @SuppressWarnings("GoodTime") + public static long encodePacked64TimeMicros(org.threeten.bp.LocalTime time) { + return encodePacked64TimeMicrosLocalTime(toJavaTimeLocalTime(time)); + } + /** * Encodes {@code time} as a 8-byte integer with microseconds precision. * @@ -140,13 +153,21 @@ private static LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { * @see #encodePacked64TimeMicros(LocalTime) */ @SuppressWarnings("GoodTime") - public static long encodePacked64TimeMicros(LocalTime time) { + public static long encodePacked64TimeMicrosLocalTime(java.time.LocalTime time) { checkValidTimeMicros(time); return (((long) encodePacked32TimeSeconds(time)) << MICRO_LENGTH) | (time.getNano() / 1_000L); } + /** This method is obsolete. Use {@link #decodePacked64TimeMicrosLocalTime(long)} instead. */ + @ObsoleteApi("Use decodePacked64TimeMicrosLocalTime(long) instead") + @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") + public static org.threeten.bp.LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { + return toThreetenLocalTime(decodePacked64TimeMicrosLocalTime(bitFieldTimeMicros)); + } + /** - * Decodes {@code bitFieldTimeMicros} as a {@link LocalTime} with microseconds precision. + * Decodes {@code bitFieldTimeMicros} as a {@link java.time.LocalTime} with microseconds + * precision. * *

Encoding is as the following: * @@ -159,13 +180,13 @@ public static long encodePacked64TimeMicros(LocalTime time) { * @see #encodePacked64TimeMicros(LocalTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { + public static java.time.LocalTime decodePacked64TimeMicrosLocalTime(long bitFieldTimeMicros) { checkValidBitField(bitFieldTimeMicros, TIME_MICROS_MASK); int bitFieldTimeSeconds = (int) (bitFieldTimeMicros >> MICRO_LENGTH); - LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); + java.time.LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); int microOfSecond = getFieldFromBitField(bitFieldTimeMicros, MICRO_MASK, MICRO_SHIFT); checkValidMicroOfSecond(microOfSecond); - LocalTime time = timeSeconds.withNano(microOfSecond * 1000); + java.time.LocalTime time = timeSeconds.withNano(microOfSecond * 1000); checkValidTimeMicros(time); return time; } @@ -184,7 +205,7 @@ public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { * @see #decodePacked64DatetimeSeconds(long) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static long encodePacked64DatetimeSeconds(LocalDateTime dateTime) { + private static long encodePacked64DatetimeSeconds(java.time.LocalDateTime dateTime) { checkValidDateTimeSeconds(dateTime); long bitFieldDatetimeSeconds = 0x0L; bitFieldDatetimeSeconds |= (long) dateTime.getYear() << YEAR_SHIFT; @@ -208,16 +229,17 @@ private static long encodePacked64DatetimeSeconds(LocalDateTime dateTime) { * @see #encodePacked64DatetimeSeconds(LocalDateTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetimeSeconds) { + private static java.time.LocalDateTime decodePacked64DatetimeSeconds( + long bitFieldDatetimeSeconds) { checkValidBitField(bitFieldDatetimeSeconds, DATETIME_SECONDS_MASK); int bitFieldTimeSeconds = (int) (bitFieldDatetimeSeconds & TIME_SECONDS_MASK); - LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); + java.time.LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); int year = getFieldFromBitField(bitFieldDatetimeSeconds, YEAR_MASK, YEAR_SHIFT); int monthOfYear = getFieldFromBitField(bitFieldDatetimeSeconds, MONTH_MASK, MONTH_SHIFT); int dayOfMonth = getFieldFromBitField(bitFieldDatetimeSeconds, DAY_MASK, DAY_SHIFT); try { - LocalDateTime dateTime = - LocalDateTime.of( + java.time.LocalDateTime dateTime = + java.time.LocalDateTime.of( year, monthOfYear, dayOfMonth, @@ -231,6 +253,16 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime } } + /** + * This method is obsolete. Use {@link + * #encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime)} instead. + */ + @ObsoleteApi("Use encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime) instead") + @SuppressWarnings({"GoodTime-ApiWithNumericTimeUnit", "JavaLocalDateTimeGetNano"}) + public static long encodePacked64DatetimeMicros(org.threeten.bp.LocalDateTime dateTime) { + return encodePacked64DatetimeMicrosLocalDateTime(toJavaTimeLocalDateTime(dateTime)); + } + /** * Encodes {@code dateTime} as a 8-byte integer with microseconds precision. * @@ -245,14 +277,26 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime * @see #decodePacked64DatetimeMicros(long) */ @SuppressWarnings({"GoodTime-ApiWithNumericTimeUnit", "JavaLocalDateTimeGetNano"}) - public static long encodePacked64DatetimeMicros(LocalDateTime dateTime) { + public static long encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime dateTime) { checkValidDateTimeMicros(dateTime); return (encodePacked64DatetimeSeconds(dateTime) << MICRO_LENGTH) | (dateTime.getNano() / 1_000L); } /** - * Decodes {@code bitFieldDatetimeMicros} as a {@link LocalDateTime} with microseconds precision. + * This method is obsolete. Use {@link #decodePacked64DatetimeMicrosLocalDateTime(long)} instead. + */ + @ObsoleteApi("Use decodePacked64DatetimeMicrosLocalDateTime(long) instead") + @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") + public static org.threeten.bp.LocalDateTime decodePacked64DatetimeMicros( + long bitFieldDatetimeMicros) { + return toThreetenLocalDateTime( + decodePacked64DatetimeMicrosLocalDateTime(bitFieldDatetimeMicros)); + } + + /** + * Decodes {@code bitFieldDatetimeMicros} as a {@link java.time.LocalDateTime} with microseconds + * precision. * *

Encoding is as the following: * @@ -265,13 +309,15 @@ public static long encodePacked64DatetimeMicros(LocalDateTime dateTime) { * @see #encodePacked64DatetimeMicros(LocalDateTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - public static LocalDateTime decodePacked64DatetimeMicros(long bitFieldDatetimeMicros) { + public static java.time.LocalDateTime decodePacked64DatetimeMicrosLocalDateTime( + long bitFieldDatetimeMicros) { checkValidBitField(bitFieldDatetimeMicros, DATETIME_MICROS_MASK); long bitFieldDatetimeSeconds = bitFieldDatetimeMicros >> MICRO_LENGTH; - LocalDateTime dateTimeSeconds = decodePacked64DatetimeSeconds(bitFieldDatetimeSeconds); + java.time.LocalDateTime dateTimeSeconds = + decodePacked64DatetimeSeconds(bitFieldDatetimeSeconds); int microOfSecond = getFieldFromBitField(bitFieldDatetimeMicros, MICRO_MASK, MICRO_SHIFT); checkValidMicroOfSecond(microOfSecond); - LocalDateTime dateTime = dateTimeSeconds.withNano(microOfSecond * 1_000); + java.time.LocalDateTime dateTime = dateTimeSeconds.withNano(microOfSecond * 1_000); checkValidDateTimeMicros(dateTime); return dateTime; } @@ -280,25 +326,25 @@ private static int getFieldFromBitField(long bitField, long mask, int shift) { return (int) ((bitField & mask) >> shift); } - private static void checkValidTimeSeconds(LocalTime time) { + private static void checkValidTimeSeconds(java.time.LocalTime time) { checkArgument(time.getHour() >= 0 && time.getHour() <= 23); checkArgument(time.getMinute() >= 0 && time.getMinute() <= 59); checkArgument(time.getSecond() >= 0 && time.getSecond() <= 59); } - private static void checkValidDateTimeSeconds(LocalDateTime dateTime) { + private static void checkValidDateTimeSeconds(java.time.LocalDateTime dateTime) { checkArgument(dateTime.getYear() >= 1 && dateTime.getYear() <= 9999); checkArgument(dateTime.getMonthValue() >= 1 && dateTime.getMonthValue() <= 12); checkArgument(dateTime.getDayOfMonth() >= 1 && dateTime.getDayOfMonth() <= 31); checkValidTimeSeconds(dateTime.toLocalTime()); } - private static void checkValidTimeMicros(LocalTime time) { + private static void checkValidTimeMicros(java.time.LocalTime time) { checkValidTimeSeconds(time); checkArgument(time.equals(time.truncatedTo(ChronoUnit.MICROS))); } - private static void checkValidDateTimeMicros(LocalDateTime dateTime) { + private static void checkValidDateTimeMicros(java.time.LocalDateTime dateTime) { checkValidDateTimeSeconds(dateTime); checkArgument(dateTime.equals(dateTime.truncatedTo(ChronoUnit.MICROS))); } diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java index 7aefe30626..c7c63aa6f3 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java @@ -30,6 +30,14 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.TextStyle; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -37,14 +45,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; -import org.threeten.bp.ZoneOffset; -import org.threeten.bp.format.DateTimeFormatter; -import org.threeten.bp.format.DateTimeFormatterBuilder; -import org.threeten.bp.format.TextStyle; -import org.threeten.bp.temporal.ChronoField; -import org.threeten.bp.temporal.TemporalAccessor; /** * Converts JSON data to Protobuf messages given the Protobuf descriptor and BigQuery table schema. @@ -93,14 +93,11 @@ public class JsonToProtoMessage implements ToProtoConverter { .appendLiteral(' ') .optionalEnd() .optionalStart() - .appendOffset("+HH:MM", "+00:00") + .appendZoneOrOffsetId() .optionalEnd() .optionalStart() .appendZoneText(TextStyle.SHORT) .optionalEnd() - .optionalStart() - .appendLiteral('Z') - .optionalEnd() .toFormatter() .withZone(ZoneOffset.UTC); @@ -604,7 +601,7 @@ private void fillField( if (val instanceof String) { protoMsg.setField( fieldDescriptor, - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.parse((String) val, DATETIME_FORMATTER))); return; } else if (val instanceof Long) { @@ -615,7 +612,8 @@ private void fillField( if (val instanceof String) { protoMsg.setField( fieldDescriptor, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.parse((String) val))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.parse((String) val))); return; } else if (val instanceof Long) { protoMsg.setField(fieldDescriptor, val); @@ -872,7 +870,7 @@ private void fillRepeatedField( if (val instanceof String) { protoMsg.addRepeatedField( fieldDescriptor, - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.parse((String) val, DATETIME_FORMATTER))); } else if (val instanceof Long) { protoMsg.addRepeatedField(fieldDescriptor, val); @@ -883,7 +881,8 @@ private void fillRepeatedField( if (val instanceof String) { protoMsg.addRepeatedField( fieldDescriptor, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.parse((String) val))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.parse((String) val))); } else if (val instanceof Long) { protoMsg.addRepeatedField(fieldDescriptor, val); } else { diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java index 2e5c5881ce..fbeadef872 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java @@ -372,8 +372,8 @@ static BigQueryWriteSettings getBigQueryWriteSettings(Builder builder) throws IO new BigQueryWriteSettings.Builder() .setTransportChannelProvider( BigQueryWriteSettings.defaultGrpcTransportProviderBuilder() - .setKeepAliveTime(org.threeten.bp.Duration.ofMinutes(1)) - .setKeepAliveTimeout(org.threeten.bp.Duration.ofMinutes(1)) + .setKeepAliveTimeDuration(java.time.Duration.ofMinutes(1)) + .setKeepAliveTimeoutDuration(java.time.Duration.ofMinutes(1)) .setKeepAliveWithoutCalls(true) .setChannelsPerCpu(2) .build()) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ApiResultRetryAlgorithm.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ApiResultRetryAlgorithm.java index 10bb440e5a..9411320c7a 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ApiResultRetryAlgorithm.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ApiResultRetryAlgorithm.java @@ -24,7 +24,7 @@ import com.google.cloud.bigquery.storage.v1.BigQueryReadSettings; import io.grpc.Metadata; import io.grpc.Status; -import org.threeten.bp.Duration; +import java.time.Duration; /** For internal use, public for technical reasons. */ @InternalApi @@ -56,7 +56,7 @@ public TimedAttemptSettings createNextAttempt( Duration retryDelay = result.retryDelay; Duration randomizedRetryDelay = result.retryDelay; if (retryDelay == null) { - retryDelay = prevSettings.getRetryDelay(); + retryDelay = prevSettings.getRetryDelayDuration(); randomizedRetryDelay = DEADLINE_SLEEP_DURATION; } if (retryAttemptListener != null) { @@ -64,9 +64,9 @@ public TimedAttemptSettings createNextAttempt( } return TimedAttemptSettings.newBuilder() .setGlobalSettings(prevSettings.getGlobalSettings()) - .setRetryDelay(retryDelay) + .setRetryDelayDuration(retryDelay) .setRpcTimeout(prevSettings.getRpcTimeout()) - .setRandomizedRetryDelay(randomizedRetryDelay) + .setRandomizedRetryDelayDuration(randomizedRetryDelay) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .build(); diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ReadRowsAttemptCallable.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ReadRowsAttemptCallable.java index 478b277af7..df8c6f2839 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ReadRowsAttemptCallable.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/stub/readrows/ReadRowsAttemptCallable.java @@ -28,10 +28,10 @@ import com.google.cloud.bigquery.storage.v1.ReadRowsRequest; import com.google.cloud.bigquery.storage.v1.ReadRowsResponse; import com.google.common.base.Preconditions; +import java.time.Duration; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; final class ReadRowsAttemptCallable implements Callable { private final Object lock = new Object(); @@ -122,10 +122,10 @@ public void cancel() { // Propagate the totalTimeout as the overall stream deadline. Duration totalTimeout = - outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeout(); + outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeoutDuration(); if (totalTimeout != null && context != null) { - context = context.withTimeout(totalTimeout); + context = context.withTimeoutDuration(totalTimeout); } // Call the inner callable diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ApiResultRetryAlgorithm.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ApiResultRetryAlgorithm.java index da8712584f..2305742528 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ApiResultRetryAlgorithm.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ApiResultRetryAlgorithm.java @@ -24,7 +24,7 @@ import com.google.cloud.bigquery.storage.v1beta1.BigQueryStorageSettings; import io.grpc.Metadata; import io.grpc.Status; -import org.threeten.bp.Duration; +import java.time.Duration; /** For internal use, public for technical reasons. */ @InternalApi @@ -57,7 +57,7 @@ public TimedAttemptSettings createNextAttempt( Duration retryDelay = result.retryDelay; Duration randomizedRetryDelay = result.retryDelay; if (retryDelay == null) { - retryDelay = prevSettings.getRetryDelay(); + retryDelay = prevSettings.getRetryDelayDuration(); randomizedRetryDelay = DEADLINE_SLEEP_DURATION; } if (retryAttemptListener != null) { @@ -65,9 +65,9 @@ public TimedAttemptSettings createNextAttempt( } return TimedAttemptSettings.newBuilder() .setGlobalSettings(prevSettings.getGlobalSettings()) - .setRetryDelay(retryDelay) + .setRetryDelayDuration(retryDelay) .setRpcTimeout(prevSettings.getRpcTimeout()) - .setRandomizedRetryDelay(randomizedRetryDelay) + .setRandomizedRetryDelayDuration(randomizedRetryDelay) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .build(); diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ReadRowsAttemptCallable.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ReadRowsAttemptCallable.java index 8d9d91cbb4..10eedfb9ea 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ReadRowsAttemptCallable.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta1/stub/readrows/ReadRowsAttemptCallable.java @@ -28,10 +28,10 @@ import com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest; import com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse; import com.google.common.base.Preconditions; +import java.time.Duration; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; final class ReadRowsAttemptCallable implements Callable { private final Object lock = new Object(); @@ -122,10 +122,10 @@ public void cancel() { // Propagate the totalTimeout as the overall stream deadline. Duration totalTimeout = - outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeout(); + outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeoutDuration(); if (totalTimeout != null && context != null) { - context = context.withTimeout(totalTimeout); + context = context.withTimeoutDuration(totalTimeout); } // Call the inner callable diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoder.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoder.java index 5ba7017b7a..ebc50d522a 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoder.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoder.java @@ -15,12 +15,13 @@ */ package com.google.cloud.bigquery.storage.v1beta2; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toJavaTimeLocalDateTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toJavaTimeLocalTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toThreetenLocalDateTime; +import static com.google.cloud.bigquery.storage.util.TimeConversionUtils.toThreetenLocalTime; import static com.google.common.base.Preconditions.checkArgument; -import org.threeten.bp.DateTimeException; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; -import org.threeten.bp.temporal.ChronoUnit; +import com.google.api.core.ObsoleteApi; /** * Ported from ZetaSQL CivilTimeEncoder Original code can be found at: @@ -90,7 +91,7 @@ public final class CivilTimeEncoder { * @see #decodePacked32TimeSeconds(int) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static int encodePacked32TimeSeconds(LocalTime time) { + private static int encodePacked32TimeSeconds(java.time.LocalTime time) { checkValidTimeSeconds(time); int bitFieldTimeSeconds = 0x0; bitFieldTimeSeconds |= time.getHour() << HOUR_SHIFT; @@ -113,19 +114,28 @@ private static int encodePacked32TimeSeconds(LocalTime time) { * @see #encodePacked32TimeSeconds(LocalTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { + private static java.time.LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { checkValidBitField(bitFieldTimeSeconds, TIME_SECONDS_MASK); int hourOfDay = getFieldFromBitField(bitFieldTimeSeconds, HOUR_MASK, HOUR_SHIFT); int minuteOfHour = getFieldFromBitField(bitFieldTimeSeconds, MINUTE_MASK, MINUTE_SHIFT); int secondOfMinute = getFieldFromBitField(bitFieldTimeSeconds, SECOND_MASK, SECOND_SHIFT); // LocalTime validates the input parameters. try { - return LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute); - } catch (DateTimeException e) { + return java.time.LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute); + } catch (java.time.DateTimeException e) { throw new IllegalArgumentException(e.getMessage(), e); } } + /** + * This method is obsolete. Use {@link #encodePacked64TimeMicrosLocalTime(java.time.LocalTime)} + * instead. + */ + @ObsoleteApi("Use encodePacked64TimeMicrosLocalTime(java.time.LocalTime) instead") + public static long encodePacked64TimeMicros(org.threeten.bp.LocalTime time) { + return encodePacked64TimeMicrosLocalTime(toJavaTimeLocalTime(time)); + } + /** * Encodes {@code time} as a 8-byte integer with microseconds precision. * @@ -141,13 +151,21 @@ private static LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) { * @see #encodePacked64TimeMicros(LocalTime) */ @SuppressWarnings("GoodTime") - public static long encodePacked64TimeMicros(LocalTime time) { + public static long encodePacked64TimeMicrosLocalTime(java.time.LocalTime time) { checkValidTimeMicros(time); return (((long) encodePacked32TimeSeconds(time)) << MICRO_LENGTH) | (time.getNano() / 1_000L); } + /** This method is obsolete. Use {@link #decodePacked64TimeMicrosLocalTime(long)} instead. */ + @ObsoleteApi("Use decodePacked64TimeMicrosLocalTime(long) instead") + @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") + public static org.threeten.bp.LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { + return toThreetenLocalTime(decodePacked64TimeMicrosLocalTime(bitFieldTimeMicros)); + } + /** - * Decodes {@code bitFieldTimeMicros} as a {@link LocalTime} with microseconds precision. + * Decodes {@code bitFieldTimeMicros} as a {@link java.time.LocalTime} with microseconds + * precision. * *

Encoding is as the following: * @@ -160,13 +178,13 @@ public static long encodePacked64TimeMicros(LocalTime time) { * @see #encodePacked64TimeMicros(LocalTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { + public static java.time.LocalTime decodePacked64TimeMicrosLocalTime(long bitFieldTimeMicros) { checkValidBitField(bitFieldTimeMicros, TIME_MICROS_MASK); int bitFieldTimeSeconds = (int) (bitFieldTimeMicros >> MICRO_LENGTH); - LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); + java.time.LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); int microOfSecond = getFieldFromBitField(bitFieldTimeMicros, MICRO_MASK, MICRO_SHIFT); checkValidMicroOfSecond(microOfSecond); - LocalTime time = timeSeconds.withNano(microOfSecond * 1000); + java.time.LocalTime time = timeSeconds.withNano(microOfSecond * 1000); checkValidTimeMicros(time); return time; } @@ -185,7 +203,7 @@ public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) { * @see #decodePacked64DatetimeSeconds(long) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static long encodePacked64DatetimeSeconds(LocalDateTime dateTime) { + private static long encodePacked64DatetimeSeconds(java.time.LocalDateTime dateTime) { checkValidDateTimeSeconds(dateTime); long bitFieldDatetimeSeconds = 0x0L; bitFieldDatetimeSeconds |= (long) dateTime.getYear() << YEAR_SHIFT; @@ -209,16 +227,17 @@ private static long encodePacked64DatetimeSeconds(LocalDateTime dateTime) { * @see #encodePacked64DatetimeSeconds(LocalDateTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetimeSeconds) { + private static java.time.LocalDateTime decodePacked64DatetimeSeconds( + long bitFieldDatetimeSeconds) { checkValidBitField(bitFieldDatetimeSeconds, DATETIME_SECONDS_MASK); int bitFieldTimeSeconds = (int) (bitFieldDatetimeSeconds & TIME_SECONDS_MASK); - LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); + java.time.LocalTime timeSeconds = decodePacked32TimeSeconds(bitFieldTimeSeconds); int year = getFieldFromBitField(bitFieldDatetimeSeconds, YEAR_MASK, YEAR_SHIFT); int monthOfYear = getFieldFromBitField(bitFieldDatetimeSeconds, MONTH_MASK, MONTH_SHIFT); int dayOfMonth = getFieldFromBitField(bitFieldDatetimeSeconds, DAY_MASK, DAY_SHIFT); try { - LocalDateTime dateTime = - LocalDateTime.of( + java.time.LocalDateTime dateTime = + java.time.LocalDateTime.of( year, monthOfYear, dayOfMonth, @@ -227,11 +246,21 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime timeSeconds.getSecond()); checkValidDateTimeSeconds(dateTime); return dateTime; - } catch (DateTimeException e) { + } catch (java.time.DateTimeException e) { throw new IllegalArgumentException(e.getMessage(), e); } } + /** + * This method is obsolete. Use {@link + * #encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime)} instead. + */ + @ObsoleteApi("Use encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime) instead") + @SuppressWarnings({"GoodTime-ApiWithNumericTimeUnit", "JavaLocalDateTimeGetNano"}) + public static long encodePacked64DatetimeMicros(org.threeten.bp.LocalDateTime dateTime) { + return encodePacked64DatetimeMicrosLocalDateTime(toJavaTimeLocalDateTime(dateTime)); + } + /** * Encodes {@code dateTime} as a 8-byte integer with microseconds precision. * @@ -246,14 +275,26 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime * @see #decodePacked64DatetimeMicros(long) */ @SuppressWarnings({"GoodTime-ApiWithNumericTimeUnit", "JavaLocalDateTimeGetNano"}) - public static long encodePacked64DatetimeMicros(LocalDateTime dateTime) { + public static long encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime dateTime) { checkValidDateTimeMicros(dateTime); return (encodePacked64DatetimeSeconds(dateTime) << MICRO_LENGTH) | (dateTime.getNano() / 1_000L); } /** - * Decodes {@code bitFieldDatetimeMicros} as a {@link LocalDateTime} with microseconds precision. + * This method is obsolete. Use {@link #decodePacked64DatetimeMicrosLocalDateTime(long)} instead. + */ + @ObsoleteApi("Use decodePacked64DatetimeMicrosLocalDateTime(long) instead") + @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") + public static org.threeten.bp.LocalDateTime decodePacked64DatetimeMicros( + long bitFieldDatetimeMicros) { + return toThreetenLocalDateTime( + decodePacked64DatetimeMicrosLocalDateTime(bitFieldDatetimeMicros)); + } + + /** + * Decodes {@code bitFieldDatetimeMicros} as a {@link java.time.LocalDateTime} with microseconds + * precision. * *

Encoding is as the following: * @@ -266,13 +307,15 @@ public static long encodePacked64DatetimeMicros(LocalDateTime dateTime) { * @see #encodePacked64DatetimeMicros(LocalDateTime) */ @SuppressWarnings("GoodTime-ApiWithNumericTimeUnit") - public static LocalDateTime decodePacked64DatetimeMicros(long bitFieldDatetimeMicros) { + public static java.time.LocalDateTime decodePacked64DatetimeMicrosLocalDateTime( + long bitFieldDatetimeMicros) { checkValidBitField(bitFieldDatetimeMicros, DATETIME_MICROS_MASK); long bitFieldDatetimeSeconds = bitFieldDatetimeMicros >> MICRO_LENGTH; - LocalDateTime dateTimeSeconds = decodePacked64DatetimeSeconds(bitFieldDatetimeSeconds); + java.time.LocalDateTime dateTimeSeconds = + decodePacked64DatetimeSeconds(bitFieldDatetimeSeconds); int microOfSecond = getFieldFromBitField(bitFieldDatetimeMicros, MICRO_MASK, MICRO_SHIFT); checkValidMicroOfSecond(microOfSecond); - LocalDateTime dateTime = dateTimeSeconds.withNano(microOfSecond * 1_000); + java.time.LocalDateTime dateTime = dateTimeSeconds.withNano(microOfSecond * 1_000); checkValidDateTimeMicros(dateTime); return dateTime; } @@ -281,27 +324,27 @@ private static int getFieldFromBitField(long bitField, long mask, int shift) { return (int) ((bitField & mask) >> shift); } - private static void checkValidTimeSeconds(LocalTime time) { + private static void checkValidTimeSeconds(java.time.LocalTime time) { checkArgument(time.getHour() >= 0 && time.getHour() <= 23); checkArgument(time.getMinute() >= 0 && time.getMinute() <= 59); checkArgument(time.getSecond() >= 0 && time.getSecond() <= 59); } - private static void checkValidDateTimeSeconds(LocalDateTime dateTime) { + private static void checkValidDateTimeSeconds(java.time.LocalDateTime dateTime) { checkArgument(dateTime.getYear() >= 1 && dateTime.getYear() <= 9999); checkArgument(dateTime.getMonthValue() >= 1 && dateTime.getMonthValue() <= 12); checkArgument(dateTime.getDayOfMonth() >= 1 && dateTime.getDayOfMonth() <= 31); checkValidTimeSeconds(dateTime.toLocalTime()); } - private static void checkValidTimeMicros(LocalTime time) { + private static void checkValidTimeMicros(java.time.LocalTime time) { checkValidTimeSeconds(time); - checkArgument(time.equals(time.truncatedTo(ChronoUnit.MICROS))); + checkArgument(time.equals(time.truncatedTo(java.time.temporal.ChronoUnit.MICROS))); } - private static void checkValidDateTimeMicros(LocalDateTime dateTime) { + private static void checkValidDateTimeMicros(java.time.LocalDateTime dateTime) { checkValidDateTimeSeconds(dateTime); - checkArgument(dateTime.equals(dateTime.truncatedTo(ChronoUnit.MICROS))); + checkArgument(dateTime.equals(dateTime.truncatedTo(java.time.temporal.ChronoUnit.MICROS))); } private static void checkValidMicroOfSecond(int microOfSecond) { diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessage.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessage.java index f6d4130376..dd6dfdb1d5 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessage.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessage.java @@ -25,13 +25,13 @@ import com.google.protobuf.Message; import com.google.protobuf.UninitializedMessageException; import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; import java.util.logging.Logger; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; /** * Converts Json data to protocol buffer messages given the protocol buffer descriptor. The protobuf @@ -267,7 +267,8 @@ private static void fillField( if (val instanceof String) { protoMsg.setField( fieldDescriptor, - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.parse((String) val))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.parse((String) val))); return; } else if (val instanceof Long) { protoMsg.setField(fieldDescriptor, (Long) val); @@ -277,7 +278,8 @@ private static void fillField( if (val instanceof String) { protoMsg.setField( fieldDescriptor, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.parse((String) val))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.parse((String) val))); return; } else if (val instanceof Long) { protoMsg.setField(fieldDescriptor, (Long) val); @@ -458,7 +460,8 @@ private static void fillRepeatedField( if (val instanceof String) { protoMsg.addRepeatedField( fieldDescriptor, - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.parse((String) val))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.parse((String) val))); } else if (val instanceof Long) { protoMsg.addRepeatedField(fieldDescriptor, (Long) val); } else { @@ -468,7 +471,8 @@ private static void fillRepeatedField( if (val instanceof String) { protoMsg.addRepeatedField( fieldDescriptor, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.parse((String) val))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.parse((String) val))); } else if (val instanceof Long) { protoMsg.addRepeatedField(fieldDescriptor, (Long) val); } else { diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ApiResultRetryAlgorithm.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ApiResultRetryAlgorithm.java index 1d9cad46bd..fadfc5b312 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ApiResultRetryAlgorithm.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ApiResultRetryAlgorithm.java @@ -24,7 +24,7 @@ import com.google.cloud.bigquery.storage.v1beta2.BigQueryReadSettings; import io.grpc.Metadata; import io.grpc.Status; -import org.threeten.bp.Duration; +import java.time.Duration; /** For internal use, public for technical reasons. */ @InternalApi @@ -56,7 +56,7 @@ public TimedAttemptSettings createNextAttempt( Duration retryDelay = result.retryDelay; Duration randomizedRetryDelay = result.retryDelay; if (retryDelay == null) { - retryDelay = prevSettings.getRetryDelay(); + retryDelay = prevSettings.getRetryDelayDuration(); randomizedRetryDelay = DEADLINE_SLEEP_DURATION; } if (retryAttemptListener != null) { @@ -64,9 +64,9 @@ public TimedAttemptSettings createNextAttempt( } return TimedAttemptSettings.newBuilder() .setGlobalSettings(prevSettings.getGlobalSettings()) - .setRetryDelay(retryDelay) + .setRetryDelayDuration(retryDelay) .setRpcTimeout(prevSettings.getRpcTimeout()) - .setRandomizedRetryDelay(randomizedRetryDelay) + .setRandomizedRetryDelayDuration(randomizedRetryDelay) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos()) .build(); diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ReadRowsAttemptCallable.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ReadRowsAttemptCallable.java index 3dea54a119..a8674793d5 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ReadRowsAttemptCallable.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/stub/readrows/ReadRowsAttemptCallable.java @@ -28,10 +28,10 @@ import com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest; import com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse; import com.google.common.base.Preconditions; +import java.time.Duration; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import javax.annotation.concurrent.GuardedBy; -import org.threeten.bp.Duration; final class ReadRowsAttemptCallable implements Callable { private final Object lock = new Object(); @@ -122,10 +122,10 @@ public void cancel() { // Propagate the totalTimeout as the overall stream deadline. Duration totalTimeout = - outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeout(); + outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeoutDuration(); if (totalTimeout != null && context != null) { - context = context.withTimeout(totalTimeout); + context = context.withTimeoutDuration(totalTimeout); } // Call the inner callable diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java index 07e298c698..2acfbae123 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/util/ErrorsTest.java @@ -130,6 +130,6 @@ public RetryInfo parseBytes(byte[] serialized) { Errors.isRetryableStatus( Status.RESOURCE_EXHAUSTED.withDescription("Stop for a while"), metadata); assertTrue(result.isRetryable); - assertEquals(result.retryDelay, org.threeten.bp.Duration.ofSeconds(123, 456)); + assertEquals(result.retryDelay, java.time.Duration.ofSeconds(123, 456)); } } diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerPoolTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerPoolTest.java index 0ed2fc5705..4f3a7d30d7 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerPoolTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerPoolTest.java @@ -34,6 +34,7 @@ import com.google.protobuf.Int64Value; import io.grpc.Status; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -48,7 +49,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class ConnectionWorkerPoolTest { @@ -67,7 +67,7 @@ public class ConnectionWorkerPoolTest { private static final int MAX_RETRY_DELAY_MINUTES = 5; private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(INITIAL_RETRY_MILLIS)) + .setInitialRetryDelayDuration(Duration.ofMillis(INITIAL_RETRY_MILLIS)) .setRetryDelayMultiplier(RETRY_MULTIPLIER) .setMaxAttempts(MAX_RETRY_NUM_ATTEMPTS) .setMaxRetryDelay(org.threeten.bp.Duration.ofMinutes(MAX_RETRY_DELAY_MINUTES)) diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java index 8c6c8ae815..7332960caa 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java @@ -55,10 +55,10 @@ public class ConnectionWorkerTest { private static final String TEST_TRACE_ID = "DATAFLOW:job_id"; private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(500)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(500)) .setRetryDelayMultiplier(1.1) .setMaxAttempts(3) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMinutes(5)) + .setMaxRetryDelayDuration(java.time.Duration.ofMinutes(5)) .build(); private FakeBigQueryWrite testBigQueryWrite; @@ -338,7 +338,7 @@ public void testAppendButInflightQueueFull() throws Exception { /*enableRequestProfiler=*/ false, /*enableOpenTelemetry=*/ false, /*isMultiplexing=*/ false); - testBigQueryWrite.setResponseSleep(org.threeten.bp.Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); ConnectionWorker.setMaxInflightQueueWaitTime(500); long appendCount = 6; @@ -398,7 +398,7 @@ public void testThrowExceptionWhileWithinAppendLoop() throws Exception { /*enableRequestProfiler=*/ false, /*enableOpenTelemetry=*/ false, /*isMultiplexing=*/ true); - testBigQueryWrite.setResponseSleep(org.threeten.bp.Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); ConnectionWorker.setMaxInflightQueueWaitTime(500); long appendCount = 10; @@ -660,7 +660,7 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E /*enableRequestProfiler=*/ false, /*enableOpenTelemetry=*/ false, /*isMultiplexing*/ false); - org.threeten.bp.Duration durationSleep = org.threeten.bp.Duration.ofSeconds(2); + java.time.Duration durationSleep = java.time.Duration.ofSeconds(2); testBigQueryWrite.setResponseSleep(durationSleep); long appendCount = 2; diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWrite.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWrite.java index 120e004b7d..15cda4029d 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWrite.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWrite.java @@ -19,13 +19,13 @@ import com.google.protobuf.AbstractMessage; import io.grpc.ServerServiceDefinition; import io.grpc.Status; +import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Supplier; -import org.threeten.bp.Duration; /** * A fake implementation of {@link MockGrpcService}, that can be used to test clients of a diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWriteImpl.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWriteImpl.java index abf08bd0e1..7998680444 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWriteImpl.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeBigQueryWriteImpl.java @@ -20,6 +20,7 @@ import com.google.rpc.Code; import io.grpc.Status; import io.grpc.stub.StreamObserver; +import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -33,7 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.logging.Logger; -import org.threeten.bp.Duration; /** * A fake implementation of {@link BigQueryWriteImplBase} that can acts like server in StreamWriter diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeScheduledExecutorService.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeScheduledExecutorService.java index 0869fdc788..68bdfbf6d1 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeScheduledExecutorService.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/FakeScheduledExecutorService.java @@ -18,6 +18,8 @@ import com.google.api.core.ApiClock; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.SettableFuture; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Deque; import java.util.LinkedList; @@ -33,8 +35,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; /** * Fake implementation of {@link ScheduledExecutorService} that allows tests control the reference diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java index c6e920192b..24e4ce89a8 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java @@ -47,6 +47,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.Instant; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -63,8 +65,6 @@ import org.junit.function.ThrowingRunnable; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; -import org.threeten.bp.LocalTime; @RunWith(JUnit4.class) public class JsonStreamWriterTest { @@ -310,7 +310,7 @@ public void testSpecialTypeAppend() throws Exception { JsonTest.TestTime expectedProto = JsonTest.TestTime.newBuilder() - .addTime(CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))) + .addTime(CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))) .build(); JSONObject foo = new JSONObject(); foo.put("time", new JSONArray(new String[] {"01:00:01"})); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java index b8094b7c12..6b3e0637dd 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java @@ -28,6 +28,7 @@ import com.google.protobuf.DynamicMessage; import com.google.protobuf.Message; import java.math.BigDecimal; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -39,7 +40,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.LocalTime; @RunWith(JUnit4.class) public class JsonToProtoMessageTest { @@ -798,6 +798,8 @@ public void testTimestamp() throws Exception { .addFields(TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_int").build()) .addFields(TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_float").build()) .addFields(TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_offset").build()) + .addFields( + TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_zero_offset").build()) .addFields(TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_timezone").build()) .addFields(TableFieldSchema.newBuilder(TEST_TIMESTAMP).setName("test_saformat").build()) .build(); @@ -809,6 +811,7 @@ public void testTimestamp() throws Exception { .setTestInt(153480695L) .setTestFloat(153468069500L) .setTestOffset(1649135171000000L) + .setTestZeroOffset(1648493279010000L) .setTestTimezone(1649174771000000L) .setTestSaformat(1534680660000000L) .build(); @@ -819,6 +822,7 @@ public void testTimestamp() throws Exception { json.put("test_int", 153480695); json.put("test_float", "1.534680695e11"); json.put("test_offset", "2022-04-05T09:06:11+04:00"); + json.put("test_zero_offset", "2022-03-28T18:47:59.01+00:00"); json.put("test_timezone", "2022-04-05 09:06:11 PST"); json.put("test_saformat", "2018/08/19 12:11"); DynamicMessage protoMsg = @@ -855,6 +859,10 @@ public void testTimestampRepeated() throws Exception { TableFieldSchema.newBuilder(TEST_TIMESTAMP_REPEATED) .setName("test_offset_repeated") .build()) + .addFields( + TableFieldSchema.newBuilder(TEST_TIMESTAMP_REPEATED) + .setName("test_zero_offset_repeated") + .build()) .addFields( TableFieldSchema.newBuilder(TEST_TIMESTAMP_REPEATED) .setName("test_timezone_repeated") @@ -872,6 +880,7 @@ public void testTimestampRepeated() throws Exception { .addTestIntRepeated(153480695L) .addTestFloatRepeated(153468069500L) .addTestOffsetRepeated(1649135171000000L) + .addTestZeroOffsetRepeated(1648493279010000L) .addTestTimezoneRepeated(1649174771000000L) .addTestSaformatRepeated(1534680660000000L) .build(); @@ -882,6 +891,8 @@ public void testTimestampRepeated() throws Exception { json.put("test_int_repeated", new JSONArray(new Integer[] {153480695})); json.put("test_float_repeated", new JSONArray(new String[] {"1.534680695e11"})); json.put("test_offset_repeated", new JSONArray(new String[] {"2022-04-05T09:06:11+04:00"})); + json.put( + "test_zero_offset_repeated", new JSONArray(new String[] {"2022-03-28T18:47:59.01+00:00"})); json.put("test_timezone_repeated", new JSONArray(new String[] {"2022-04-05 09:06:11 PST"})); json.put("test_saformat_repeated", new JSONArray(new String[] {"2018/08/19 12:11"})); DynamicMessage protoMsg = @@ -1212,7 +1223,7 @@ public void testStructComplex() throws Exception { BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("1.23456"))) .setTestGeo("POINT(1,1)") .setTestTimestamp(12345678L) - .setTestTime(CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))) + .setTestTime(CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))) .setTestTimeStr(89332507144L) .addTestNumericRepeated( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("0"))) @@ -1297,7 +1308,8 @@ public void testStructComplex() throws Exception { })); json.put("test_geo", "POINT(1,1)"); json.put("test_timestamp", 12345678); - json.put("test_time", CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))); + json.put( + "test_time", CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))); json.put("test_time_str", "20:51:10.1234"); json.put("test_numeric_str", "12.4"); json.put("test_numeric_short", 1); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java index 027dd3f15d..625713bc8c 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java @@ -78,7 +78,6 @@ import org.junit.function.ThrowingRunnable; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class StreamWriterTest { @@ -96,10 +95,10 @@ public class StreamWriterTest { private static final int MAX_RETRY_DELAY_MINUTES = 5; private static final RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(INITIAL_RETRY_MILLIS)) + .setInitialRetryDelayDuration(java.time.Duration.ofMillis(INITIAL_RETRY_MILLIS)) .setRetryDelayMultiplier(RETRY_MULTIPLIER) .setMaxAttempts(MAX_RETRY_NUM_ATTEMPTS) - .setMaxRetryDelay(org.threeten.bp.Duration.ofMinutes(MAX_RETRY_DELAY_MINUTES)) + .setMaxRetryDelayDuration(java.time.Duration.ofMinutes(MAX_RETRY_DELAY_MINUTES)) .build(); private FakeScheduledExecutorService fakeExecutor; private FakeBigQueryWrite testBigQueryWrite; @@ -694,7 +693,7 @@ public void testAppendAfterServerClose() throws Exception { public void userCloseWhileRequestInflight() throws Exception { final StreamWriter writer = getTestStreamWriter(); // Server will sleep 2 seconds before sending back the response. - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(2)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(2)); testBigQueryWrite.addResponse(createAppendResponse(0)); // Send a request and close the stream in separate thread while the request is inflight. @@ -730,7 +729,7 @@ public void run() throws Throwable { public void serverCloseWhileRequestsInflight() throws Exception { StreamWriter writer = getTestStreamWriter(); // Server will sleep 2 seconds before closing the connection. - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(2)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(2)); testBigQueryWrite.addException(Status.INVALID_ARGUMENT.asException()); // Send 10 requests, so that there are 10 inflight requests. @@ -785,7 +784,7 @@ public void testOneMaxInflightRequests() throws Exception { .setMaxInflightRequests(1) .build(); // Server will sleep 1 second before every response. - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); testBigQueryWrite.addResponse(createAppendResponse(0)); ApiFuture appendFuture1 = sendTestMessage(writer, new String[] {"A"}); @@ -814,7 +813,7 @@ public void testOneMaxInflightRequests_MultiplexingCase() throws Exception { .build(); // Server will sleep 1 second before every response. - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); testBigQueryWrite.addResponse(createAppendResponse(0)); testBigQueryWrite.addResponse(createAppendResponse(1)); @@ -1142,7 +1141,7 @@ public void testAppendsWithTinyMaxInflightBytes() throws Exception { .setMaxInflightBytes(1) .build(); // Server will sleep 100ms before every response. - testBigQueryWrite.setResponseSleep(Duration.ofMillis(100)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofMillis(100)); long appendCount = 10; for (int i = 0; i < appendCount; i++) { testBigQueryWrite.addResponse(createAppendResponse(i)); @@ -1254,7 +1253,7 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E StreamWriter.setMaxRequestCallbackWaitTime(java.time.Duration.ofSeconds(1)); StreamWriter writer = StreamWriter.newBuilder(TEST_STREAM_1, client).setWriterSchema(schema1).build(); - testBigQueryWrite.setResponseSleep(org.threeten.bp.Duration.ofSeconds(3)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(3)); long appendCount = 10; for (int i = 0; i < appendCount; i++) { @@ -1741,12 +1740,12 @@ public void testBuilderDefaultSetting() throws Exception { .getKeepAliveWithoutCalls()); assertEquals( ((InstantiatingGrpcChannelProvider) writeSettings.getTransportChannelProvider()) - .getKeepAliveTimeout(), - org.threeten.bp.Duration.ofMinutes(1)); + .getKeepAliveTimeoutDuration(), + java.time.Duration.ofMinutes(1)); assertEquals( ((InstantiatingGrpcChannelProvider) writeSettings.getTransportChannelProvider()) - .getKeepAliveTime(), - org.threeten.bp.Duration.ofMinutes(1)); + .getKeepAliveTimeDuration(), + java.time.Duration.ofMinutes(1)); assertEquals( BigQueryWriteSettings.getDefaultEndpoint(), writeSettings.getEndpoint().toString()); } @@ -1781,7 +1780,7 @@ public void testBuilderExplicitSetting() throws Exception { InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(14).build()) .setChannelProvider( BigQueryWriteSettings.defaultGrpcTransportProviderBuilder() - .setKeepAliveTimeout(Duration.ofSeconds(500)) + .setKeepAliveTimeoutDuration(java.time.Duration.ofSeconds(500)) .build()) .setCredentialsProvider( BigQueryWriteSettings.defaultCredentialsProviderBuilder() @@ -1799,9 +1798,9 @@ public void testBuilderExplicitSetting() throws Exception { assertTrue( writerSettings2.getTransportChannelProvider() instanceof InstantiatingGrpcChannelProvider); assertEquals( - Duration.ofSeconds(500), + java.time.Duration.ofSeconds(500), ((InstantiatingGrpcChannelProvider) writerSettings2.getTransportChannelProvider()) - .getKeepAliveTimeout()); + .getKeepAliveTimeoutDuration()); assertTrue(writerSettings2.getCredentialsProvider() instanceof GoogleCredentialsProvider); assertEquals( 2, @@ -2104,7 +2103,7 @@ public void testAppendSuccessAndQuotaErrorMaxRetryNumAttempts() throws Exception public void testExclusiveAppendSuccessAndInternalErrorRetryMaxRetry() throws Exception { testBigQueryWrite.setReturnErrorDuringExclusiveStreamRetry(true); // Ensure messages will be in the inflight queue - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); StreamWriter writer = getTestStreamWriterExclusiveRetryEnabled(); int appendCount = 10; @@ -2140,7 +2139,7 @@ public void testExclusiveAppendSuccessAndInternalErrorRetryMaxRetry() throws Exc public void testExclusiveAppendSuccessAndQuotaErrorRetryMaxRetry() throws Exception { testBigQueryWrite.setReturnErrorDuringExclusiveStreamRetry(true); // Ensure messages will be in the inflight queue - testBigQueryWrite.setResponseSleep(Duration.ofSeconds(1)); + testBigQueryWrite.setResponseSleep(java.time.Duration.ofSeconds(1)); StreamWriter writer = getTestStreamWriterExclusiveRetryEnabled(); int appendCount = 10; diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java index 8078255904..97c456e675 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java @@ -81,6 +81,13 @@ import java.io.InputStream; import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -98,13 +105,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; -import org.threeten.bp.LocalDate; -import org.threeten.bp.LocalTime; -import org.threeten.bp.ZoneOffset; -import org.threeten.bp.ZonedDateTime; -import org.threeten.bp.format.DateTimeFormatter; /** Integration tests for BigQuery Storage API. */ public class ITBigQueryStorageTest { @@ -618,10 +618,10 @@ public void testRangeTypeWrite() TableName parentTable = TableName.of(projectName, DATASET, tableName); RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(500)) + .setInitialRetryDelayDuration(Duration.ofMillis(500)) .setRetryDelayMultiplier(1.1) .setMaxAttempts(5) - .setMaxRetryDelay(Duration.ofMinutes(1)) + .setMaxRetryDelayDuration(Duration.ofMinutes(1)) .build(); try (JsonStreamWriter writer = JsonStreamWriter.newBuilder(parentTable.toString(), RANGE_TABLE_SCHEMA) @@ -1712,8 +1712,8 @@ private Job RunQueryJobAndExpectSuccess(QueryJobConfiguration configuration) Job job = bigquery.create(JobInfo.of(configuration)); Job completedJob = job.waitFor( - RetryOption.initialRetryDelay(Duration.ofSeconds(1)), - RetryOption.totalTimeout(Duration.ofMinutes(1))); + RetryOption.initialRetryDelayDuration(Duration.ofSeconds(1)), + RetryOption.totalTimeoutDuration(Duration.ofMinutes(1))); assertNotNull(completedJob); assertNull( diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryTimeEncoderTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryTimeEncoderTest.java index 5907404a77..6333a88dd4 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryTimeEncoderTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryTimeEncoderTest.java @@ -40,6 +40,8 @@ import com.google.cloud.bigquery.testing.RemoteBigQueryHelper; import com.google.protobuf.Descriptors; import java.io.IOException; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.Iterator; import java.util.concurrent.ExecutionException; import org.json.JSONArray; @@ -48,8 +50,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; public class ITBigQueryTimeEncoderTest { private static final String DATASET = RemoteBigQueryHelper.generateDatasetName(); @@ -158,25 +158,27 @@ public void TestTimeEncoding() "test_time_micros", new JSONArray( new long[] { - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(13, 14, 15, 16_000_000)), - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(23, 59, 59, 999_999_000)), - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(0, 0, 0, 0)), - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 2, 3, 4_000)), - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(5, 6, 7, 8_000)) + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.of(13, 14, 15, 16_000_000)), + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime( + LocalTime.of(23, 59, 59, 999_999_000)), + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(0, 0, 0, 0)), + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 2, 3, 4_000)), + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(5, 6, 7, 8_000)) })); row.put( "test_datetime_micros", new JSONArray( new long[] { - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(1, 1, 1, 12, 0, 0, 0)), - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(1995, 5, 19, 10, 30, 45, 0)), - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(2000, 1, 1, 0, 0, 0, 0)), - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(2026, 3, 11, 5, 45, 12, 9_000_000)), - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(2050, 1, 2, 3, 4, 5, 6_000)), })); row.put("test_date_repeated", new JSONArray(new int[] {0, 300, 14238})); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java index 58f80dbce4..fdcdb34ac4 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java @@ -54,6 +54,7 @@ import java.text.ParseException; import java.time.Duration; import java.time.Instant; +import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.*; @@ -66,7 +67,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.threeten.bp.LocalDateTime; /** Integration tests for BigQuery Write API. */ public class ITBigQueryWriteManualClientTest { @@ -387,7 +387,8 @@ public void testJsonStreamWriterCommittedStream() })); row1.put( "test_datetime", - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(2020, 10, 1, 12, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(2020, 10, 1, 12, 0))); JSONArray jsonArr1 = new JSONArray(new JSONObject[] {row1}); ApiFuture response1 = jsonStreamWriter.append(jsonArr1, -1); @@ -629,7 +630,8 @@ public void testJsonStreamWriterWithDefaultSchema() row1.put("unknown_field", "a"); row1.put( "test_datetime", - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(2020, 10, 1, 12, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(2020, 10, 1, 12, 0))); row1.put( "test_bytestring_repeated", new JSONArray( @@ -801,7 +803,8 @@ public void testJsonStreamWriterWithDefaultStream() row1.put("unknown_field", "a"); row1.put( "test_datetime", - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(2020, 10, 1, 12, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(2020, 10, 1, 12, 0))); row1.put( "test_bytestring_repeated", new JSONArray( @@ -1475,7 +1478,8 @@ public void testJsonStreamWriterWithFlexibleColumnName() })); row1.put( "test-datetime列", - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(2020, 10, 1, 12, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(2020, 10, 1, 12, 0))); JSONArray jsonArr1 = new JSONArray(new JSONObject[] {row1}); ApiFuture response1 = jsonStreamWriter.append(jsonArr1, -1); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/WriteRetryTestUtil.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/WriteRetryTestUtil.java index c3d34a3694..e11e0707df 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/WriteRetryTestUtil.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/WriteRetryTestUtil.java @@ -37,13 +37,13 @@ import com.google.cloud.bigquery.storage.v1.WriteStream; import com.google.protobuf.Descriptors.DescriptorValidationException; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Assert; -import org.threeten.bp.Duration; public class WriteRetryTestUtil { private static final Logger LOG = @@ -61,10 +61,10 @@ public static void runExclusiveRetryTest( throws IOException, InterruptedException, DescriptorValidationException { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(500)) + .setInitialRetryDelayDuration(Duration.ofMillis(500)) .setRetryDelayMultiplier(1.1) .setMaxAttempts(5) - .setMaxRetryDelay(Duration.ofMinutes(1)) + .setMaxRetryDelayDuration(Duration.ofMinutes(1)) .build(); String tableName = "RetryTest"; TableId tableId = TableId.of(dataset, tableName); @@ -122,10 +122,10 @@ private static void runDefaultRetryTestInternal( throws IOException, InterruptedException, DescriptorValidationException { RetrySettings retrySettings = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(500)) + .setInitialRetryDelayDuration(Duration.ofMillis(500)) .setRetryDelayMultiplier(1.1) .setMaxAttempts(5) - .setMaxRetryDelay(Duration.ofMinutes(1)) + .setMaxRetryDelayDuration(Duration.ofMinutes(1)) .build(); ArrayList> allResponses = new ArrayList<>(requestCount); try (JsonStreamWriter jsonStreamWriter = diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/stub/EnhancedBigQueryReadStubSettingsTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/stub/EnhancedBigQueryReadStubSettingsTest.java index d86067b1bc..ab6a8d1298 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/stub/EnhancedBigQueryReadStubSettingsTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/stub/EnhancedBigQueryReadStubSettingsTest.java @@ -30,12 +30,12 @@ import com.google.cloud.bigquery.storage.v1.ReadSession; import com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest; import com.google.cloud.bigquery.storage.v1.SplitReadStreamResponse; +import java.time.Duration; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class EnhancedBigQueryReadStubSettingsTest { @@ -51,7 +51,7 @@ public void testSettingsArePreserved() { EnhancedBigQueryReadStubSettings.newBuilder() .setEndpoint(endpoint) .setCredentialsProvider(credentialsProvider) - .setStreamWatchdogCheckInterval(watchdogInterval) + .setStreamWatchdogCheckIntervalDuration(watchdogInterval) .setStreamWatchdogProvider(watchdogProvider); verifyBuilder(builder, endpoint, credentialsProvider, watchdogInterval, watchdogProvider); @@ -75,7 +75,7 @@ private void verifyBuilder( WatchdogProvider watchdogProvider) { assertThat(builder.getEndpoint()).isEqualTo(endpoint); assertThat(builder.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(builder.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(builder.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(builder.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -91,7 +91,7 @@ private void verifySettings( WatchdogProvider watchdogProvider) { assertThat(settings.getEndpoint()).isEqualTo(endpoint); assertThat(settings.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(settings.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(settings.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(settings.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -112,14 +112,14 @@ public void testReadRowsSettings() { EnhancedBigQueryReadStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).contains(Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); - assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); + assertThat(retrySettings.getInitialRetryDelayDuration()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); - assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); - assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getMaxRetryDelayDuration()).isEqualTo(Duration.ofMinutes(1L)); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(builder.getIdleTimeoutDuration()).isEqualTo(Duration.ZERO); } @Test @@ -131,12 +131,12 @@ public void testSplitReadStreamSettings() { private void verifyRetrySettings(Set retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).contains(Code.UNAVAILABLE); - assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getTotalTimeoutDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRetryDelayDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRetryDelayDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); } } diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/it/ITBigQueryStorageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/it/ITBigQueryStorageTest.java index 26cab629b3..04367183b9 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/it/ITBigQueryStorageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/it/ITBigQueryStorageTest.java @@ -66,6 +66,13 @@ import java.io.InputStream; import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -81,13 +88,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; -import org.threeten.bp.LocalDate; -import org.threeten.bp.LocalTime; -import org.threeten.bp.ZoneOffset; -import org.threeten.bp.ZonedDateTime; -import org.threeten.bp.format.DateTimeFormatter; /** Integration tests for BigQuery Storage API. */ public class ITBigQueryStorageTest { @@ -1284,8 +1284,8 @@ private Job RunQueryJobAndExpectSuccess(QueryJobConfiguration configuration) Job job = bigquery.create(JobInfo.of(configuration)); Job completedJob = job.waitFor( - RetryOption.initialRetryDelay(Duration.ofSeconds(1)), - RetryOption.totalTimeout(Duration.ofMinutes(1))); + RetryOption.initialRetryDelayDuration(Duration.ofSeconds(1)), + RetryOption.totalTimeoutDuration(Duration.ofMinutes(1))); assertNotNull(completedJob); assertNull( diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/stub/EnhancedBigQueryStorageStubSettingsTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/stub/EnhancedBigQueryStorageStubSettingsTest.java index b45dd797fd..a81a1da255 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/stub/EnhancedBigQueryStorageStubSettingsTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta1/stub/EnhancedBigQueryStorageStubSettingsTest.java @@ -34,12 +34,12 @@ import com.google.cloud.bigquery.storage.v1beta1.Storage.SplitReadStreamRequest; import com.google.cloud.bigquery.storage.v1beta1.Storage.SplitReadStreamResponse; import com.google.protobuf.Empty; +import java.time.Duration; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class EnhancedBigQueryStorageStubSettingsTest { @@ -55,7 +55,7 @@ public void testSettingsArePreserved() { EnhancedBigQueryStorageStubSettings.newBuilder() .setEndpoint(endpoint) .setCredentialsProvider(credentialsProvider) - .setStreamWatchdogCheckInterval(watchdogInterval) + .setStreamWatchdogCheckIntervalDuration(watchdogInterval) .setStreamWatchdogProvider(watchdogProvider); verifyBuilder(builder, endpoint, credentialsProvider, watchdogInterval, watchdogProvider); @@ -79,7 +79,7 @@ private void verifyBuilder( WatchdogProvider watchdogProvider) { assertThat(builder.getEndpoint()).isEqualTo(endpoint); assertThat(builder.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(builder.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(builder.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(builder.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -95,7 +95,7 @@ private void verifySettings( WatchdogProvider watchdogProvider) { assertThat(settings.getEndpoint()).isEqualTo(endpoint); assertThat(settings.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(settings.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(settings.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(settings.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -116,14 +116,14 @@ public void testReadRowsSettings() { EnhancedBigQueryStorageStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).contains(Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); - assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); + assertThat(retrySettings.getInitialRetryDelayDuration()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); - assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); - assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getMaxRetryDelayDuration()).isEqualTo(Duration.ofMinutes(1L)); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(builder.getIdleTimeoutDuration()).isEqualTo(Duration.ZERO); } @Test @@ -152,12 +152,12 @@ public void testSplitReadStreamSettings() { private void verifyRetrySettings(Set retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).contains(Code.UNAVAILABLE); - assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getTotalTimeoutDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRetryDelayDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRetryDelayDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); } } diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoderTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoderTest.java index 673d3b0eab..393babd189 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoderTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/CivilTimeEncoderTest.java @@ -18,13 +18,13 @@ import static org.junit.Assert.assertEquals; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.logging.Logger; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.LocalDateTime; -import org.threeten.bp.LocalTime; @RunWith(JUnit4.class) public class CivilTimeEncoderTest { @@ -36,44 +36,50 @@ public void encodeAndDecodePacked64TimeMicros_validTime() { // 00:00:00.000000 // 0b000000000000000000000000000|00000|000000|000000|00000000000000000000 // 0x0 - assertEquals(0x0L, CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(0, 0, 0, 0))); - assertEquals(LocalTime.of(0, 0, 0, 0), CivilTimeEncoder.decodePacked64TimeMicros(0x0L)); + assertEquals( + 0x0L, CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(0, 0, 0, 0))); + assertEquals( + LocalTime.of(0, 0, 0, 0), CivilTimeEncoder.decodePacked64TimeMicrosLocalTime(0x0L)); // 00:01:02.003000 // 0b000000000000000000000000000|00000|000001|000010|00000000101110111000 // 0x4200BB8 assertEquals( - 0x4200BB8L, CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(0, 1, 2, 3_000_000))); + 0x4200BB8L, + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(0, 1, 2, 3_000_000))); assertEquals( - LocalTime.of(0, 1, 2, 3_000_000), CivilTimeEncoder.decodePacked64TimeMicros(0x4200BB8L)); + LocalTime.of(0, 1, 2, 3_000_000), + CivilTimeEncoder.decodePacked64TimeMicrosLocalTime(0x4200BB8L)); // 12:00:00.000000 // 0b000000000000000000000000000|01100|000000|000000|00000000000000000000 // 0xC00000000 assertEquals( - 0xC00000000L, CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(12, 0, 0, 0))); + 0xC00000000L, + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(12, 0, 0, 0))); assertEquals( - LocalTime.of(12, 0, 0, 0), CivilTimeEncoder.decodePacked64TimeMicros(0xC00000000L)); + LocalTime.of(12, 0, 0, 0), + CivilTimeEncoder.decodePacked64TimeMicrosLocalTime(0xC00000000L)); // 13:14:15.016000 // 0b000000000000000000000000000|01101|001110|001111|00000011111010000000 // 0xD38F03E80 assertEquals( 0xD38F03E80L, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(13, 14, 15, 16_000_000))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(13, 14, 15, 16_000_000))); assertEquals( LocalTime.of(13, 14, 15, 16_000_000), - CivilTimeEncoder.decodePacked64TimeMicros(0xD38F03E80L)); + CivilTimeEncoder.decodePacked64TimeMicrosLocalTime(0xD38F03E80L)); // 23:59:59.999000 // 0b000000000000000000000000000|10111|111011|111011|11110011111001011000 // 0x17EFBF3E58 assertEquals( 0x17EFBF3E58L, - CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(23, 59, 59, 999_000_000))); + CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(23, 59, 59, 999_000_000))); assertEquals( LocalTime.of(23, 59, 59, 999_000_000), - CivilTimeEncoder.decodePacked64TimeMicros(0x17EFBF3E58L)); + CivilTimeEncoder.decodePacked64TimeMicrosLocalTime(0x17EFBF3E58L)); } @Test @@ -81,7 +87,8 @@ public void encodePacked64TimeMicros_giveErrorWhenPrecisionIsLost() { try { // 00:00:00.000000999 // 0b000000000000000000000000000|00000|000000|000000|00000000000000000000 // 0x0 - assertEquals(0x0L, CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(0, 0, 0, 999))); + assertEquals( + 0x0L, CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(0, 0, 0, 999))); Assert.fail(); } catch (IllegalArgumentException e) { } @@ -159,53 +166,55 @@ public void encodeAndDecodePacked64DatetimeMicros_validDateTime() { // 0x4420000 assertEquals( 0x442000000000L, - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(1, 1, 1, 0, 0, 0, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(1, 1, 1, 0, 0, 0, 0))); assertEquals( LocalDateTime.of(1, 1, 1, 0, 0, 0, 0), - CivilTimeEncoder.decodePacked64DatetimeMicros(0x442000000000L)); + CivilTimeEncoder.decodePacked64DatetimeMicrosLocalDateTime(0x442000000000L)); // 0001/02/03 00:01:02 // 0b0000000000000000000000|00000000000001|0010|00011|00000|000001|000010 // 0x4860042 assertEquals( 0x486004200BB8L, - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(1, 2, 3, 0, 1, 2, 3_000_000))); assertEquals( LocalDateTime.of(1, 2, 3, 0, 1, 2, 3_000_000), - CivilTimeEncoder.decodePacked64DatetimeMicros(0x486004200BB8L)); + CivilTimeEncoder.decodePacked64DatetimeMicrosLocalDateTime(0x486004200BB8L)); // 0001/01/01 12:00:00 // 0b0000000000000000000000|00000000000001|0001|00001|01100|000000|000000 // 0x442C000 assertEquals( 0x442C00000000L, - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(1, 1, 1, 12, 0, 0, 0))); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(1, 1, 1, 12, 0, 0, 0))); assertEquals( LocalDateTime.of(1, 1, 1, 12, 0, 0, 0), - CivilTimeEncoder.decodePacked64DatetimeMicros(0x442C00000000L)); + CivilTimeEncoder.decodePacked64DatetimeMicrosLocalDateTime(0x442C00000000L)); // 0001/01/01 13:14:15 // 0b0000000000000000000000|00000000000001|0001|00001|01101|001110|001111 // 0x442D38F assertEquals( 0x442D38F03E80L, - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(1, 1, 1, 13, 14, 15, 16_000_000))); assertEquals( LocalDateTime.of(1, 1, 1, 13, 14, 15, 16_000_000), - CivilTimeEncoder.decodePacked64DatetimeMicros(0x442D38F03E80L)); + CivilTimeEncoder.decodePacked64DatetimeMicrosLocalDateTime(0x442D38F03E80L)); // 9999/12/31 23:59:59 // 0b0000000000000000000000|10011100001111|1100|11111|10111|111011|111011 // 0x9C3F3F7EFB assertEquals( 0x9C3F3F7EFBF3E58L, - CivilTimeEncoder.encodePacked64DatetimeMicros( + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( LocalDateTime.of(9999, 12, 31, 23, 59, 59, 999_000_000))); assertEquals( LocalDateTime.of(9999, 12, 31, 23, 59, 59, 999_000_000), - CivilTimeEncoder.decodePacked64DatetimeMicros(0x9C3F3F7EFBF3E58L)); + CivilTimeEncoder.decodePacked64DatetimeMicrosLocalDateTime(0x9C3F3F7EFBF3E58L)); } @Test @@ -214,7 +223,8 @@ public void encodePacked64DateTimeMicros_giveErrorWhenPrecisionIsLost() { // 0b0000000000000000000000|00000000000001|0001|00001|00000|000000|000000 // 0x4420000 try { - CivilTimeEncoder.encodePacked64DatetimeMicros(LocalDateTime.of(1, 1, 1, 0, 0, 0, 999)); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime( + LocalDateTime.of(1, 1, 1, 0, 0, 0, 999)); Assert.fail(); } catch (IllegalArgumentException e) { } @@ -227,7 +237,7 @@ public void encodePacked64DatetimeMicros_invalidYear_throwsIllegalArgumentExcept // 0x9C4042000000000 LocalDateTime dateTime = LocalDateTime.of(10000, 1, 1, 0, 0, 0, 0); try { - CivilTimeEncoder.encodePacked64DatetimeMicros(dateTime); + CivilTimeEncoder.encodePacked64DatetimeMicrosLocalDateTime(dateTime); Assert.fail(); } catch (IllegalArgumentException expected) { } diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWrite.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWrite.java index 69279f01e7..3b8b936e53 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWrite.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWrite.java @@ -18,10 +18,10 @@ import com.google.api.gax.grpc.testing.MockGrpcService; import com.google.protobuf.AbstractMessage; import io.grpc.ServerServiceDefinition; +import java.time.Duration; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ScheduledExecutorService; -import org.threeten.bp.Duration; /** * A fake implementation of {@link MockGrpcService}, that can be used to test clients of a diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWriteImpl.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWriteImpl.java index e706f8198a..595ea4bc63 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWriteImpl.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeBigQueryWriteImpl.java @@ -18,6 +18,7 @@ import com.google.common.base.Optional; import com.google.common.util.concurrent.Uninterruptibles; import io.grpc.stub.StreamObserver; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; @@ -26,7 +27,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; -import org.threeten.bp.Duration; /** * A fake implementation of {@link BigQueryWriteImplBase} that can acts like server in StreamWriter diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeScheduledExecutorService.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeScheduledExecutorService.java index 11a8311014..bc4ec137dd 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeScheduledExecutorService.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/FakeScheduledExecutorService.java @@ -18,6 +18,8 @@ import com.google.api.core.ApiClock; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.SettableFuture; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Deque; import java.util.LinkedList; @@ -33,8 +35,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; /** * Fake implementation of {@link ScheduledExecutorService} that allows tests control the reference diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriterTest.java index 85c83dbf25..37f82d6698 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriterTest.java @@ -30,6 +30,8 @@ import com.google.protobuf.Int64Value; import com.google.protobuf.Timestamp; import java.io.IOException; +import java.time.Instant; +import java.time.LocalTime; import java.util.Arrays; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -42,8 +44,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; -import org.threeten.bp.LocalTime; @RunWith(JUnit4.class) public class JsonStreamWriterTest { @@ -209,7 +209,7 @@ public void testSpecialTypeAppend() throws Exception { JsonTest.TestTime expectedProto = JsonTest.TestTime.newBuilder() - .addTime(CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))) + .addTime(CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))) .build(); JSONObject foo = new JSONObject(); foo.put("time", new JSONArray(new String[] {"01:00:01"})); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java index 9827e72588..3c6c8154c1 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/JsonToProtoMessageTest.java @@ -26,6 +26,7 @@ import com.google.protobuf.DynamicMessage; import com.google.protobuf.Message; import java.math.BigDecimal; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Map; import java.util.logging.Logger; @@ -35,7 +36,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.LocalTime; @RunWith(JUnit4.class) public class JsonToProtoMessageTest { @@ -794,7 +794,7 @@ public void testStructComplex() throws Exception { BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("1.23456"))) .setTestGeo("POINT(1,1)") .setTestTimestamp(12345678) - .setTestTime(CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))) + .setTestTime(CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))) .setTestTimeStr(89332507144L) .addTestNumericRepeated( BigDecimalByteStringEncoder.encodeToNumericByteString(new BigDecimal("0"))) @@ -871,7 +871,8 @@ public void testStructComplex() throws Exception { })); json.put("test_geo", "POINT(1,1)"); json.put("test_timestamp", 12345678); - json.put("test_time", CivilTimeEncoder.encodePacked64TimeMicros(LocalTime.of(1, 0, 1))); + json.put( + "test_time", CivilTimeEncoder.encodePacked64TimeMicrosLocalTime(LocalTime.of(1, 0, 1))); json.put("test_time_str", "20:51:10.1234"); json.put("test_numeric_str", "12.4"); json.put("test_numeric_short", 1); diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java index 6f2d3767cb..de541e7932 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterV2Test.java @@ -33,6 +33,7 @@ import io.grpc.Status; import io.grpc.StatusRuntimeException; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -48,7 +49,6 @@ import org.junit.function.ThrowingRunnable; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class StreamWriterV2Test { diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/it/ITBigQueryStorageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/it/ITBigQueryStorageTest.java index 539b3b2d05..48f5fc5f38 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/it/ITBigQueryStorageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/it/ITBigQueryStorageTest.java @@ -63,6 +63,13 @@ import java.io.InputStream; import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -78,13 +85,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; -import org.threeten.bp.LocalDate; -import org.threeten.bp.LocalTime; -import org.threeten.bp.ZoneOffset; -import org.threeten.bp.ZonedDateTime; -import org.threeten.bp.format.DateTimeFormatter; /** Integration tests for BigQuery Storage API. */ public class ITBigQueryStorageTest { @@ -1265,8 +1265,8 @@ private Job RunQueryJobAndExpectSuccess(QueryJobConfiguration configuration) Job job = bigquery.create(JobInfo.of(configuration)); Job completedJob = job.waitFor( - RetryOption.initialRetryDelay(Duration.ofSeconds(1)), - RetryOption.totalTimeout(Duration.ofMinutes(1))); + RetryOption.initialRetryDelayDuration(Duration.ofSeconds(1)), + RetryOption.totalTimeoutDuration(Duration.ofMinutes(1))); assertNotNull(completedJob); assertNull( diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/stub/EnhancedBigQueryReadStubSettingsTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/stub/EnhancedBigQueryReadStubSettingsTest.java index 000959b62c..f28b855877 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/stub/EnhancedBigQueryReadStubSettingsTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/stub/EnhancedBigQueryReadStubSettingsTest.java @@ -30,12 +30,12 @@ import com.google.cloud.bigquery.storage.v1beta2.ReadSession; import com.google.cloud.bigquery.storage.v1beta2.SplitReadStreamRequest; import com.google.cloud.bigquery.storage.v1beta2.SplitReadStreamResponse; +import java.time.Duration; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class EnhancedBigQueryReadStubSettingsTest { @@ -51,7 +51,7 @@ public void testSettingsArePreserved() { EnhancedBigQueryReadStubSettings.newBuilder() .setEndpoint(endpoint) .setCredentialsProvider(credentialsProvider) - .setStreamWatchdogCheckInterval(watchdogInterval) + .setStreamWatchdogCheckIntervalDuration(watchdogInterval) .setStreamWatchdogProvider(watchdogProvider); verifyBuilder(builder, endpoint, credentialsProvider, watchdogInterval, watchdogProvider); @@ -75,7 +75,7 @@ private void verifyBuilder( WatchdogProvider watchdogProvider) { assertThat(builder.getEndpoint()).isEqualTo(endpoint); assertThat(builder.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(builder.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(builder.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(builder.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -91,7 +91,7 @@ private void verifySettings( WatchdogProvider watchdogProvider) { assertThat(settings.getEndpoint()).isEqualTo(endpoint); assertThat(settings.getCredentialsProvider()).isEqualTo(credentialsProvider); - assertThat(settings.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(settings.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(settings.getStreamWatchdogProvider()).isEqualTo(watchdogProvider); InstantiatingGrpcChannelProvider channelProvider = @@ -112,14 +112,14 @@ public void testReadRowsSettings() { EnhancedBigQueryReadStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).contains(Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); - assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); + assertThat(retrySettings.getInitialRetryDelayDuration()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); - assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); - assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getMaxRetryDelayDuration()).isEqualTo(Duration.ofMinutes(1L)); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); - assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(retrySettings.getTotalTimeoutDuration()).isEqualTo(Duration.ofDays(1L)); + assertThat(builder.getIdleTimeoutDuration()).isEqualTo(Duration.ZERO); } @Test @@ -131,12 +131,12 @@ public void testSplitReadStreamSettings() { private void verifyRetrySettings(Set retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).contains(Code.UNAVAILABLE); - assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getTotalTimeoutDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRetryDelayDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRetryDelayDuration()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRpcTimeoutDuration()).isGreaterThan(Duration.ZERO); } } diff --git a/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto b/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto index fc6b6ce48e..618bcc0a03 100644 --- a/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto +++ b/google-cloud-bigquerystorage/src/test/proto/jsonTest.proto @@ -152,8 +152,9 @@ message TestTimestamp { optional int64 test_int = 4; optional int64 test_float = 5; optional int64 test_offset = 6; - optional int64 test_timezone = 7; - optional int64 test_saformat = 8; + optional int64 test_zero_offset = 7; + optional int64 test_timezone = 8; + optional int64 test_saformat = 9; } message TestRepeatedTimestamp { @@ -163,8 +164,9 @@ message TestRepeatedTimestamp { repeated int64 test_int_repeated = 4; repeated int64 test_float_repeated = 5; repeated int64 test_offset_repeated = 6; - repeated int64 test_timezone_repeated = 7; - repeated int64 test_saformat_repeated = 8; + repeated int64 test_zero_offset_repeated = 7; + repeated int64 test_timezone_repeated = 8; + repeated int64 test_saformat_repeated = 9; } message TestDate {