From 71aa9a870db67b99631557c2364a3cb7c4f1842e Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 14 Nov 2024 11:21:20 -0500 Subject: [PATCH 01/30] feat: introduce java.time to java-bigtable --- .../bigtable/admin/v2/models/Backup.java | 45 ++++++++-- .../admin/v2/models/CopyBackupRequest.java | 12 ++- .../admin/v2/models/CreateBackupRequest.java | 22 ++++- .../admin/v2/models/CreateTableRequest.java | 18 +++- .../bigtable/admin/v2/models/GCRules.java | 32 +++++-- .../cloud/bigtable/admin/v2/models/Table.java | 20 +++-- .../admin/v2/models/UpdateBackupRequest.java | 21 ++++- .../admin/v2/models/UpdateTableRequest.java | 17 +++- .../google/cloud/bigtable/common/Type.java | 2 +- .../data/v2/BigtableDataSettings.java | 9 +- .../internal/AbstractProtoStructReader.java | 24 +++-- .../data/v2/internal/ResultSetImpl.java | 24 +++-- .../data/v2/models/ChangeStreamMutation.java | 50 +++++++++-- .../v2/models/ChangeStreamRecordAdapter.java | 50 +++++++++-- .../DefaultChangeStreamRecordAdapter.java | 30 +++++-- .../bigtable/data/v2/models/Heartbeat.java | 17 +++- .../data/v2/models/ReadChangeStreamQuery.java | 31 ++++++- .../bigtable/data/v2/models/sql/SqlType.java | 3 +- .../data/v2/models/sql/Statement.java | 14 +-- .../data/v2/models/sql/StructReader.java | 24 +++-- .../RateLimitingServerStreamingCallable.java | 4 +- .../ChangeStreamStateMachine.java | 13 ++- .../BigtableCloudMonitoringExporter.java | 5 +- .../v2/stub/metrics/BuiltinMetricsTracer.java | 17 +++- .../data/v2/stub/metrics/CompositeTracer.java | 19 +++- .../data/v2/stub/metrics/MetricsTracer.java | 16 +++- .../metrics/TracedBatcherUnaryCallable.java | 4 +- .../gaxx/retrying/AttemptCallable.java | 5 +- .../retrying/RetryInfoRetryAlgorithm.java | 10 +-- .../v2/BigtableInstanceAdminSettingsTest.java | 4 +- .../v2/BigtableTableAdminClientTests.java | 78 ++++++++-------- .../v2/BigtableTableAdminSettingsTest.java | 5 +- .../admin/v2/it/BigtableBackupIT.java | 28 +++--- .../bigtable/admin/v2/it/BigtableCmekIT.java | 6 +- .../v2/it/BigtableTableAdminClientIT.java | 17 ++-- .../bigtable/admin/v2/models/BackupTest.java | 11 +-- .../v2/models/CopyBackupRequestTest.java | 46 +++++----- .../v2/models/CreateBackupRequestTest.java | 40 ++++----- .../v2/models/CreateTableRequestTest.java | 6 +- .../bigtable/admin/v2/models/GCRulesTest.java | 38 ++++---- .../v2/models/UpdateBackupRequestTest.java | 36 ++++---- .../v2/models/UpdateTableRequestTest.java | 6 +- .../v2/stub/AwaitConsistencyCallableTest.java | 12 +-- .../AbstractProtoStructReaderTest.java | 10 +-- .../data/v2/internal/ProtoStructTest.java | 7 +- .../data/v2/internal/ResultSetImplTest.java | 6 +- .../bigtable/data/v2/it/BuiltinMetricsIT.java | 4 +- .../bigtable/data/v2/it/BulkMutateIT.java | 6 +- .../bigtable/data/v2/it/ExecuteQueryIT.java | 12 +-- .../v2/models/ChangeStreamMutationTest.java | 26 +++--- .../v2/models/ChangeStreamRecordTest.java | 4 +- .../DefaultChangeStreamRecordAdapterTest.java | 83 +++++++++-------- .../v2/models/ReadChangeStreamQueryTest.java | 46 +++++----- .../data/v2/models/sql/StatementTest.java | 4 +- .../BigtableBatchingCallSettingsTest.java | 6 +- .../BigtableBulkReadRowsCallSettingsTest.java | 6 +- .../data/v2/stub/CookiesHolderTest.java | 10 +-- .../EnhancedBigtableStubSettingsTest.java | 90 ++++++++++--------- .../v2/stub/EnhancedBigtableStubTest.java | 24 ++--- .../v2/stub/RateLimitingCallableTest.java | 18 ++-- ...ChangeStreamRecordMergingCallableTest.java | 4 +- .../ReadChangeStreamRetryTest.java | 4 +- .../ReadChangeStreamUserCallableTest.java | 10 +-- .../v2/stub/metrics/CompositeTracerTest.java | 12 +-- .../MutateRowsAttemptCallableTest.java | 13 +-- .../v2/stub/sql/ExecuteQueryCallableTest.java | 6 +- .../test_helpers/env/PrefixGenerator.java | 2 +- .../test_helpers/env/TestEnvRule.java | 4 +- .../bigtable/testproxy/CbtTestProxy.java | 15 ++-- .../testproxy/ResultSetSerializer.java | 1 - .../testproxy/StatementDeserializer.java | 1 - 71 files changed, 830 insertions(+), 495 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java index 1c340910a0..b0f093c7de 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java @@ -16,7 +16,10 @@ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.BackupName; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; @@ -24,7 +27,6 @@ import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** * A backup lets you save a copy of a table's schema and data and restore the backup to a new table @@ -166,23 +168,41 @@ public String getInstanceId() { return instanceId; } + /** This method is obsolete. Use {@link #getExpireTimeInstant()} instead. */ + @ObsoleteApi("Use getExpireTimeInstant() instead") + public org.threeten.bp.Instant getExpireTime() { + return toThreetenInstant(getExpireTimeInstant()); + } + /** Get the expire time of this backup. */ - public Instant getExpireTime() { - return Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); + public java.time.Instant getExpireTimeInstant() { + return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); + } + + /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ + @ObsoleteApi("Use getStartTimeInstant() instead") + public @Nullable org.threeten.bp.Instant getStartTime() { + return toThreetenInstant(getStartTimeInstant()); } /** Get the start time when this backup is taken. */ - public @Nullable Instant getStartTime() { + public @Nullable java.time.Instant getStartTimeInstant() { if (proto.hasStartTime()) { - return Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime())); + return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime())); } return null; } + /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ + @ObsoleteApi("Use getStartTimeInstant() instead") + public @Nullable org.threeten.bp.Instant getEndTime() { + return toThreetenInstant(getEndTimeInstant()); + } + /** Get the end time when the creation of this backup has completed. */ - public @Nullable Instant getEndTime() { + public @Nullable java.time.Instant getEndTimeInstant() { if (proto.hasEndTime()) { - return Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime())); + return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime())); } return null; } @@ -202,11 +222,18 @@ public BackupType getBackupType() { return BackupType.fromProto(proto.getBackupType()); } + /** This method is obsolete. Use {@link #getHotToStandardTimeInstant()} instead. */ + @ObsoleteApi("Use getHotToStandardTimeInstant() instead.") + @Nullable + public org.threeten.bp.Instant getHotToStandardTime() { + return toThreetenInstant(getHotToStandardTimeInstant()); + } + /** Get the time at which this backup will be converted from a hot backup to a standard backup. */ @Nullable - public Instant getHotToStandardTime() { + public java.time.Instant getHotToStandardTimeInstant() { if (proto.hasHotToStandardTime()) { - return Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime())); + return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime())); } return null; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java index 88b50376be..c42ec5ffa7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java @@ -15,13 +15,15 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** Build CopyBackupRequest for {@link com.google.bigtable.admin.v2.CopyBackupRequest}. */ public final class CopyBackupRequest { @@ -75,7 +77,13 @@ public CopyBackupRequest setDestination(String clusterId, String backupId) { return this; } - public CopyBackupRequest setExpireTime(Instant expireTime) { + /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ + @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") + public CopyBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { + return setExpireTimeInstant(toJavaTimeInstant(expireTime)); + } + + public CopyBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder.setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); return this; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index 542ba8da20..d4c6f315ec 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -15,13 +15,15 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateBackupRequest} */ public final class CreateBackupRequest { @@ -50,7 +52,13 @@ public CreateBackupRequest setSourceTableId(String sourceTableId) { return this; } - public CreateBackupRequest setExpireTime(Instant expireTime) { + /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ + @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") + public CreateBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { + return setExpireTimeInstant(toJavaTimeInstant(expireTime)); + } + + public CreateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() @@ -64,10 +72,18 @@ public CreateBackupRequest setBackupType(Backup.BackupType backupType) { return this; } + /** + * This method is obsolete. Use {@link #setHotToStandardTimeInstant(java.time.Instant)} instead. + */ + @ObsoleteApi("Use setHotToStandardTimeInstant(java.time.Instant) instead.") + public CreateBackupRequest setHotToStandardTime(org.threeten.bp.Instant hotToStandardTime) { + return setHotToStandardTimeInstant(toJavaTimeInstant(hotToStandardTime)); + } + // The time at which this backup will be converted from a hot backup to a standard backup. Only // applicable for hot backups. If not set, the backup will remain as a hot backup until it is // deleted. - public CreateBackupRequest setHotToStandardTime(Instant hotToStandardTime) { + public CreateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToStandardTime) { Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java index 0fbffcb190..0e28798d82 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java @@ -15,7 +15,10 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.ChangeStreamConfig; import com.google.bigtable.admin.v2.ColumnFamily; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; @@ -23,8 +26,8 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; /** * Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateTableRequest} @@ -107,15 +110,24 @@ public CreateTableRequest addSplit(ByteString key) { return this; } + /** + * This method is obsolete. Use {@link #addChangeStreamRetentionDuration(java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use addChangeStreamRetentionDuration(java.time.Duration) instead.") + public CreateTableRequest addChangeStreamRetention(org.threeten.bp.Duration retention) { + return addChangeStreamRetentionDuration(toJavaTimeDuration(retention)); + } + /** Add change stream retention period between 1 day and 7 days */ - public CreateTableRequest addChangeStreamRetention(Duration retention) { + public CreateTableRequest addChangeStreamRetentionDuration(java.time.Duration retention) { Preconditions.checkNotNull(retention); requestBuilder .getTableBuilder() .setChangeStreamConfig( ChangeStreamConfig.newBuilder() .setRetentionPeriod( - com.google.protobuf.Duration.newBuilder() + Duration.newBuilder() .setSeconds(retention.getSeconds()) .setNanos(retention.getNano()) .build()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java index 35f48c5260..6971967f0a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java @@ -15,8 +15,12 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.GcRule; import com.google.bigtable.admin.v2.GcRule.Intersection; import com.google.bigtable.admin.v2.GcRule.Union; @@ -26,7 +30,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; // TODO(igorbernstein2): the distinction between GcRule & GCRule is too subtle, use fully qualified // names for the protos. @@ -70,15 +73,21 @@ public VersionRule maxVersions(int maxVersion) { * @param timeUnit - timeunit for the age */ public DurationRule maxAge(long maxAge, TimeUnit timeUnit) { - return maxAge(Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit))); + return maxAgeDuration( + java.time.Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit))); } + /** This method is obsolete. Use {@link #maxAgeDuration(java.time.Duration)} instead. */ + @ObsoleteApi("Use maxAgeDuration(java.time.Duration) instead.") + public DurationRule maxAge(org.threeten.bp.Duration duration) { + return maxAgeDuration(toJavaTimeDuration(duration)); + } /** * Creates a new instance of the DurationRule * * @param duration - age expressed as duration */ - public DurationRule maxAge(Duration duration) { + public DurationRule maxAgeDuration(java.time.Duration duration) { return new DurationRule(duration); } @@ -91,8 +100,9 @@ public DefaultRule defaultRule() { public GCRule fromProto(GcRule source) { switch (source.getRuleCase()) { case MAX_AGE: - return GCRULES.maxAge( - Duration.ofSeconds(source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); + return GCRULES.maxAgeDuration( + java.time.Duration.ofSeconds( + source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); case MAX_NUM_VERSIONS: return GCRULES.maxVersions(source.getMaxNumVersions()); @@ -287,16 +297,22 @@ public GcRule toProto() { public static final class DurationRule implements GCRule { private final com.google.protobuf.Duration.Builder builder; - private DurationRule(Duration duration) { + private DurationRule(java.time.Duration duration) { this.builder = com.google.protobuf.Duration.newBuilder() .setSeconds(duration.getSeconds()) .setNanos(duration.getNano()); } + /** This method is obsolete. Use {@link #getMaxAgeDuration()} instead. */ + @ObsoleteApi("Use getMaxAgeDuration() instead.") + public org.threeten.bp.Duration getMaxAge() { + return toThreetenDuration(getMaxAgeDuration()); + } + /** Gets the configured maximum age */ - public Duration getMaxAge() { - return Duration.ofSeconds(builder.getSeconds(), builder.getNanos()); + public java.time.Duration getMaxAgeDuration() { + return java.time.Duration.ofSeconds(builder.getSeconds(), builder.getNanos()); } @Override diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java index 31aa612f18..28d260ccd0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java @@ -15,7 +15,10 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.TableName; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -25,7 +28,6 @@ import java.util.Map; import java.util.Map.Entry; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; /** Wrapper for {@link Table} protocol buffer object */ public final class Table { @@ -104,7 +106,7 @@ public com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState toProto( private final Map replicationStatesByClusterId; private final List columnFamilies; - private final Duration changeStreamRetention; + private final java.time.Duration changeStreamRetention; @InternalApi public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) { @@ -123,10 +125,10 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) columnFamilies.add(ColumnFamily.fromProto(entry.getKey(), entry.getValue())); } - Duration changeStreamConfig = null; + java.time.Duration changeStreamConfig = null; if (proto.hasChangeStreamConfig()) { changeStreamConfig = - Duration.ofSeconds( + java.time.Duration.ofSeconds( proto.getChangeStreamConfig().getRetentionPeriod().getSeconds(), proto.getChangeStreamConfig().getRetentionPeriod().getNanos()); } @@ -142,7 +144,7 @@ private Table( TableName tableName, Map replicationStatesByClusterId, List columnFamilies, - Duration changeStreamRetention) { + java.time.Duration changeStreamRetention) { this.instanceId = tableName.getInstance(); this.id = tableName.getTable(); this.replicationStatesByClusterId = replicationStatesByClusterId; @@ -168,7 +170,13 @@ public List getColumnFamilies() { return columnFamilies; } - public Duration getChangeStreamRetention() { + /** This method is obsolete. Use {@link #getChangeStreamRetentionDuration()} instead. */ + @ObsoleteApi("Use getChangeStreamRetention() instead.") + public org.threeten.bp.Duration getChangeStreamRetention() { + return toThreetenDuration(getChangeStreamRetentionDuration()); + } + + public java.time.Duration getChangeStreamRetentionDuration() { return changeStreamRetention; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java index 9bf9076b0c..565dbac61c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java @@ -15,7 +15,10 @@ */ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; @@ -24,7 +27,6 @@ import com.google.protobuf.util.FieldMaskUtil; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.UpdateBackupRequest} */ public final class UpdateBackupRequest { @@ -50,7 +52,13 @@ private void updateFieldMask(int fieldNumber) { requestBuilder.setUpdateMask(FieldMaskUtil.union(requestBuilder.getUpdateMask(), newMask)); } - public UpdateBackupRequest setExpireTime(Instant expireTime) { + /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ + @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") + public UpdateBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { + return setExpireTimeInstant(toJavaTimeInstant(expireTime)); + } + + public UpdateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() @@ -58,11 +66,18 @@ public UpdateBackupRequest setExpireTime(Instant expireTime) { updateFieldMask(Backup.EXPIRE_TIME_FIELD_NUMBER); return this; } + /** + * This method is obsolete. Use {@link #setHotToStandardTimeInstant(java.time.Instant)} instead. + */ + @ObsoleteApi("Use setHotToStandardTimeInstant(java.time.Instant) instead.") + public UpdateBackupRequest setHotToStandardTime(org.threeten.bp.Instant hotToStandardTime) { + return setHotToStandardTimeInstant(toJavaTimeInstant(hotToStandardTime)); + } // The time at which this backup will be converted from a hot backup to a standard backup. Only // applicable for hot backups. If not set, the backup will remain as a hot backup until it is // deleted. - public UpdateBackupRequest setHotToStandardTime(Instant hotToStandardTime) { + public UpdateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToStandardTime) { Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java index 034736aa56..4f9622d47e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java @@ -16,12 +16,14 @@ package com.google.cloud.bigtable.admin.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.ChangeStreamConfig; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Preconditions; import java.util.Objects; -import org.threeten.bp.Duration; /** * Wrapper for {@link com.google.bigtable.admin.v2.UpdateTableRequest} @@ -47,8 +49,17 @@ private UpdateTableRequest(String tableId) { this.tableId = tableId; } + /** + * This method is obsolete. Use {@link #addChangeStreamRetentionDuration(java.time.Duration + * retention)} instead. + */ + @ObsoleteApi("Use addChangeStreamRetentionDuration(java.time.Duration) instead.") + public UpdateTableRequest addChangeStreamRetention(org.threeten.bp.Duration retention) { + return addChangeStreamRetentionDuration(toJavaTimeDuration(retention)); + } + /** Update change stream retention period between 1 day and 7 days. */ - public UpdateTableRequest addChangeStreamRetention(Duration retention) { + public UpdateTableRequest addChangeStreamRetentionDuration(java.time.Duration retention) { Preconditions.checkNotNull(retention); if (!retention.isZero()) { requestBuilder @@ -71,7 +82,7 @@ public UpdateTableRequest addChangeStreamRetention(Duration retention) { /** Disable change stream for table */ public UpdateTableRequest disableChangeStreamRetention() { - return addChangeStreamRetention(Duration.ZERO); + return addChangeStreamRetentionDuration(java.time.Duration.ZERO); } @InternalApi diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java index df5c6dcd95..cd6a0a5407 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/common/Type.java @@ -23,8 +23,8 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.List; -import org.threeten.bp.Instant; /** * Shared type implementations. Right now this is only used by SqlType but this will become a shared diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java index 928159aa6d..f21639d57a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java @@ -38,7 +38,6 @@ import java.util.logging.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Settings class to configure an instance of {@link BigtableDataClient}. @@ -132,9 +131,11 @@ public static Builder newBuilderForEmulator(String hostname, int port) { .setMaxInboundMessageSize(256 * 1024 * 1024) .setChannelPoolSettings(ChannelPoolSettings.staticallySized(1)) .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) - .setKeepAliveTime(Duration.ofSeconds(61)) // sends ping in this interval - .setKeepAliveTimeout( - Duration.ofSeconds(10)) // wait this long before considering the connection dead + .setKeepAliveTimeDuration( + java.time.Duration.ofSeconds(61)) // sends ping in this interval + .setKeepAliveTimeoutDuration( + java.time.Duration.ofSeconds( + 10)) // wait this long before considering the connection dead .build()); LOGGER.info("Connecting to the Bigtable emulator at " + hostname + ":" + port); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java index dff4d4e0b2..f6e611c878 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java @@ -15,7 +15,10 @@ */ package com.google.cloud.bigtable.data.v2.internal; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.Value; import com.google.bigtable.v2.Value.KindCase; import com.google.cloud.Date; @@ -30,7 +33,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.threeten.bp.Instant; @InternalApi public abstract class AbstractProtoStructReader implements StructReader { @@ -166,14 +168,26 @@ public boolean getBoolean(String columnName) { } @Override - public Instant getTimestamp(int columnIndex) { + @ObsoleteApi("Use getTimestampInstant(int) instead") + public org.threeten.bp.Instant getTimestamp(int columnIndex) { + return toThreetenInstant(getTimestampInstant(columnIndex)); + } + + @Override + public java.time.Instant getTimestampInstant(int columnIndex) { checkNonNullOfType(columnIndex, SqlType.timestamp(), columnIndex); Value value = values().get(columnIndex); return toInstant(value.getTimestampValue()); } @Override - public Instant getTimestamp(String columnName) { + @ObsoleteApi("Use getTimestampInstant(String) instead") + public org.threeten.bp.Instant getTimestamp(String columnName) { + return toThreetenInstant(getTimestampInstant(columnName)); + } + + @Override + public java.time.Instant getTimestampInstant(String columnName) { int columnIndex = getColumnIndex(columnName); checkNonNullOfType(columnIndex, SqlType.timestamp(), columnName); Value value = values().get(columnIndex); @@ -329,8 +343,8 @@ private void checkNonNullOfType( } } - private Instant toInstant(Timestamp timestamp) { - return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); + private java.time.Instant toInstant(Timestamp timestamp) { + return java.time.Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); } private Date fromProto(com.google.type.Date proto) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java index 1d2bd37f2d..5dd242d64b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java @@ -15,8 +15,11 @@ */ package com.google.cloud.bigtable.data.v2.internal; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.rpc.ApiExceptions; import com.google.api.gax.rpc.ServerStream; import com.google.cloud.Date; @@ -31,7 +34,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.threeten.bp.Instant; /** * The primary implementation of a ResultSet. @@ -167,13 +169,25 @@ public boolean getBoolean(String columnName) { } @Override - public Instant getTimestamp(int columnIndex) { - return getCurrentRow().getTimestamp(columnIndex); + @ObsoleteApi("Use getTimestampInstant(int) instead") + public org.threeten.bp.Instant getTimestamp(int columnIndex) { + return toThreetenInstant(getTimestampInstant(columnIndex)); + } + + @Override + public java.time.Instant getTimestampInstant(int columnIndex) { + return getCurrentRow().getTimestampInstant(columnIndex); + } + + @Override + @ObsoleteApi("Use getTimestampInstant(String) instead") + public org.threeten.bp.Instant getTimestamp(String columnName) { + return toThreetenInstant(getTimestampInstant(columnName)); } @Override - public Instant getTimestamp(String columnName) { - return getCurrentRow().getTimestamp(columnName); + public java.time.Instant getTimestampInstant(String columnName) { + return getCurrentRow().getTimestampInstant(columnName); } @Override diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java index 23fb47bd82..1afa8a2358 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java @@ -15,7 +15,11 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.auto.value.AutoValue; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.cloud.bigtable.data.v2.stub.changestream.ChangeStreamRecordMerger; @@ -23,7 +27,6 @@ import com.google.protobuf.ByteString; import java.io.Serializable; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** * A ChangeStreamMutation represents a list of mods(represented by List<{@link Entry}>) targeted at @@ -73,13 +76,13 @@ public enum MutationType { static Builder createUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, - Instant commitTimestamp, + java.time.Instant commitTimestamp, int tieBreaker) { return builder() .setRowKey(rowKey) .setType(MutationType.USER) .setSourceClusterId(sourceClusterId) - .setCommitTimestamp(commitTimestamp) + .setCommitTimestampInstant(commitTimestamp) .setTieBreaker(tieBreaker); } @@ -89,12 +92,12 @@ static Builder createUserMutation( * mutation. */ static Builder createGcMutation( - @Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker) { + @Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { return builder() .setRowKey(rowKey) .setType(MutationType.GARBAGE_COLLECTION) .setSourceClusterId("") - .setCommitTimestamp(commitTimestamp) + .setCommitTimestampInstant(commitTimestamp) .setTieBreaker(tieBreaker); } @@ -110,8 +113,14 @@ static Builder createGcMutation( @Nonnull public abstract String getSourceClusterId(); + /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ + @ObsoleteApi("Use getCommitTimestampInstant() instead") + public org.threeten.bp.Instant getCommitTimestamp() { + return toThreetenInstant(getCommitTimestampInstant()); + } + /** Get the commit timestamp of the current mutation. */ - public abstract Instant getCommitTimestamp(); + public abstract java.time.Instant getCommitTimestampInstant(); /** * Get the tie breaker of the current mutation. This is used to resolve conflicts when multiple @@ -123,8 +132,14 @@ static Builder createGcMutation( @Nonnull public abstract String getToken(); + /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ + @ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") + public org.threeten.bp.Instant getEstimatedLowWatermark() { + return toThreetenInstant(getEstimatedLowWatermarkInstant()); + } + /** Get the low watermark of the current mutation. */ - public abstract Instant getEstimatedLowWatermark(); + public abstract java.time.Instant getEstimatedLowWatermarkInstant(); /** Get the list of mods of the current mutation. */ @Nonnull @@ -145,7 +160,15 @@ abstract static class Builder { abstract Builder setSourceClusterId(@Nonnull String sourceClusterId); - abstract Builder setCommitTimestamp(Instant commitTimestamp); + abstract Builder setCommitTimestampInstant(java.time.Instant commitTimestamp); + + /** + * This method is obsolete. Use {@link #setCommitTimestampInstant(java.time.Instant)} instead. + */ + @ObsoleteApi("Use setCommitTimestampInstant(java.time.Instant) instead") + Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp) { + return setCommitTimestampInstant(toJavaTimeInstant(commitTimestamp)); + } abstract Builder setTieBreaker(int tieBreaker); @@ -153,7 +176,16 @@ abstract static class Builder { abstract Builder setToken(@Nonnull String token); - abstract Builder setEstimatedLowWatermark(Instant estimatedLowWatermark); + abstract Builder setEstimatedLowWatermarkInstant(java.time.Instant estimatedLowWatermark); + + /** + * This method is obsolete. Use {@link #setEstimatedLowWatermarkInstant(java.time.Instant)} + * instead. + */ + @ObsoleteApi("Use setEstimatedLowWatermarkInstant(java.time.Instant) instead") + Builder setEstimatedLowWatermark(org.threeten.bp.Instant estimatedLowWatermark) { + return setEstimatedLowWatermarkInstant(toJavaTimeInstant(estimatedLowWatermark)); + } Builder setCell( @Nonnull String familyName, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java index 40a71b1d3c..e7ec59d070 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java @@ -15,12 +15,14 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.protobuf.ByteString; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** * An extension point that allows end users to plug in a custom implementation of logical change @@ -108,23 +110,47 @@ interface ChangeStreamRecordBuilder { */ ChangeStreamRecordT onCloseStream(ReadChangeStreamResponse.CloseStream closeStream); + /** + * This method is obsolete. Use {@link #startUserMutationInstant(ByteString, String, + * java.time.Instant, int)} instead. + */ + @ObsoleteApi("Use startUserMutationInstant(ByteString, String, java.time.Instant, int) instead") + void startUserMutation( + @Nonnull ByteString rowKey, + @Nonnull String sourceClusterId, + org.threeten.bp.Instant commitTimestamp, + int tieBreaker); + /** * Called to start a new user initiated ChangeStreamMutation. This will be called at most once. * If called, the current change stream record must not include any close stream message or * heartbeat. */ - void startUserMutation( + default void startUserMutationInstant( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, - Instant commitTimestamp, - int tieBreaker); + java.time.Instant commitTimestamp, + int tieBreaker) { + startUserMutation(rowKey, sourceClusterId, toThreetenInstant(commitTimestamp), tieBreaker); + } + + /** + * This method is obsolete. Use {@link #startGcMutationInstant(ByteString, java.time.Instant, + * int)} instead. + */ + @ObsoleteApi("Use startGcMutationInstant(ByteString, java.time.Instant, int) instead") + void startGcMutation( + @Nonnull ByteString rowKey, org.threeten.bp.Instant commitTimestamp, int tieBreaker); /** * Called to start a new Garbage Collection ChangeStreamMutation. This will be called at most * once. If called, the current change stream record must not include any close stream message * or heartbeat. */ - void startGcMutation(@Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker); + default void startGcMutationInstant( + @Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { + startGcMutation(rowKey, toThreetenInstant(commitTimestamp), tieBreaker); + } /** Called to add a DeleteFamily mod. */ void deleteFamily(@Nonnull String familyName); @@ -175,9 +201,19 @@ void mergeToCell( /** Called once per cell to signal the end of the value (unless reset). */ void finishCell(); - /** Called once per stream record to signal that all mods have been processed (unless reset). */ + /** + * This method is obsolete. Use {@link #finishChangeStreamMutationInstant(String, + * java.time.Instant)} instead. + */ + @ObsoleteApi("Use finishChangeStreamMutationInstant(String, java.time.Instant) instead") ChangeStreamRecordT finishChangeStreamMutation( - @Nonnull String token, Instant estimatedLowWatermark); + @Nonnull String token, org.threeten.bp.Instant estimatedLowWatermark); + + /** Called once per stream record to signal that all mods have been processed (unless reset). */ + default ChangeStreamRecordT finishChangeStreamMutationInstant( + @Nonnull String token, java.time.Instant estimatedLowWatermark) { + return finishChangeStreamMutation(token, toThreetenInstant(estimatedLowWatermark)); + } /** Called when the current in progress change stream record should be dropped */ void reset(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index d40ad7621c..b8ef0a3b11 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -15,6 +15,8 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.InternalApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; @@ -22,7 +24,6 @@ import com.google.protobuf.ByteString; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** * Default implementation of a {@link ChangeStreamRecordAdapter} that uses {@link @@ -103,17 +104,23 @@ public ChangeStreamRecord onCloseStream(ReadChangeStreamResponse.CloseStream clo public void startUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, - Instant commitTimestamp, + org.threeten.bp.Instant commitTimestamp, int tieBreaker) { - this.changeStreamMutationBuilder = - ChangeStreamMutation.createUserMutation( - rowKey, sourceClusterId, commitTimestamp, tieBreaker); + startUserMutationInstant( + rowKey, sourceClusterId, toJavaTimeInstant(commitTimestamp), tieBreaker); } /** {@inheritDoc} */ @Override public void startGcMutation( - @Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker) { + @Nonnull ByteString rowKey, org.threeten.bp.Instant commitTimestamp, int tieBreaker) { + startGcMutationInstant(rowKey, toJavaTimeInstant(commitTimestamp), tieBreaker); + } + + /** {@inheritDoc} */ + @Override + public void startGcMutationInstant( + ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { this.changeStreamMutationBuilder = ChangeStreamMutation.createGcMutation(rowKey, commitTimestamp, tieBreaker); } @@ -176,9 +183,16 @@ public void finishCell() { /** {@inheritDoc} */ @Override public ChangeStreamRecord finishChangeStreamMutation( - @Nonnull String token, Instant estimatedLowWatermark) { + @Nonnull String token, org.threeten.bp.Instant estimatedLowWatermark) { + return finishChangeStreamMutationInstant(token, toJavaTimeInstant(estimatedLowWatermark)); + } + + /** {@inheritDoc} */ + @Override + public ChangeStreamRecord finishChangeStreamMutationInstant( + String token, java.time.Instant estimatedLowWatermark) { this.changeStreamMutationBuilder.setToken(token); - this.changeStreamMutationBuilder.setEstimatedLowWatermark(estimatedLowWatermark); + this.changeStreamMutationBuilder.setEstimatedLowWatermarkInstant(estimatedLowWatermark); return this.changeStreamMutationBuilder.build(); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java index 8e3d865790..66888cce20 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java @@ -15,12 +15,14 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.auto.value.AutoValue; import com.google.bigtable.v2.ReadChangeStreamResponse; import java.io.Serializable; import javax.annotation.Nonnull; -import org.threeten.bp.Instant; /** A simple wrapper for {@link ReadChangeStreamResponse.Heartbeat}. */ @InternalApi("Intended for use by the BigtableIO in apache/beam only.") @@ -29,7 +31,8 @@ public abstract class Heartbeat implements ChangeStreamRecord, Serializable { private static final long serialVersionUID = 7316215828353608504L; private static Heartbeat create( - ChangeStreamContinuationToken changeStreamContinuationToken, Instant estimatedLowWatermark) { + ChangeStreamContinuationToken changeStreamContinuationToken, + java.time.Instant estimatedLowWatermark) { return new AutoValue_Heartbeat(changeStreamContinuationToken, estimatedLowWatermark); } @@ -37,7 +40,7 @@ private static Heartbeat create( static Heartbeat fromProto(@Nonnull ReadChangeStreamResponse.Heartbeat heartbeat) { return create( ChangeStreamContinuationToken.fromProto(heartbeat.getContinuationToken()), - Instant.ofEpochSecond( + java.time.Instant.ofEpochSecond( heartbeat.getEstimatedLowWatermark().getSeconds(), heartbeat.getEstimatedLowWatermark().getNanos())); } @@ -45,6 +48,12 @@ static Heartbeat fromProto(@Nonnull ReadChangeStreamResponse.Heartbeat heartbeat @InternalApi("Intended for use by the BigtableIO in apache/beam only.") public abstract ChangeStreamContinuationToken getChangeStreamContinuationToken(); + /** This method is obsolete. Use {@link #getEstimatedLowWatermarkInstant()} instead. */ + @ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") + public org.threeten.bp.Instant getEstimatedLowWatermark() { + return toThreetenInstant(getEstimatedLowWatermarkInstant()); + } + @InternalApi("Intended for use by the BigtableIO in apache/beam only.") - public abstract Instant getEstimatedLowWatermark(); + public abstract java.time.Instant getEstimatedLowWatermarkInstant(); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java index a6dfb7666d..e6ae9e526f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java @@ -15,7 +15,11 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ReadChangeStreamRequest; import com.google.bigtable.v2.RowRange; import com.google.bigtable.v2.StreamContinuationTokens; @@ -36,7 +40,6 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** A simple wrapper to construct a query for the ReadChangeStream RPC. */ @InternalApi("Intended for use by the BigtableIO in apache/beam only.") @@ -143,8 +146,14 @@ public ReadChangeStreamQuery streamPartition(ByteStringRange range) { return streamPartition(rangeBuilder.build()); } + /** This method is obsolete. Use {@link #startTimeInstant(java.time.Instant)} instead. */ + @ObsoleteApi("Use startTimeInstant(java.time.Instant) instead") + public ReadChangeStreamQuery startTime(org.threeten.bp.Instant value) { + return startTimeInstant(toJavaTimeInstant(value)); + } + /** Sets the startTime to read the change stream. */ - public ReadChangeStreamQuery startTime(Instant value) { + public ReadChangeStreamQuery startTimeInstant(java.time.Instant value) { Preconditions.checkState( !builder.hasContinuationTokens(), "startTime and continuationTokens can't be specified together"); @@ -156,8 +165,14 @@ public ReadChangeStreamQuery startTime(Instant value) { return this; } + /** This method is obsolete. Use {@link #endTimeInstant(java.time.Instant)} instead. */ + @ObsoleteApi("Use endTimeInstant(java.time.Instant) instead") + public ReadChangeStreamQuery endTime(org.threeten.bp.Instant value) { + return endTimeInstant(toJavaTimeInstant(value)); + } + /** Sets the endTime to read the change stream. */ - public ReadChangeStreamQuery endTime(Instant value) { + public ReadChangeStreamQuery endTimeInstant(java.time.Instant value) { builder.setEndTime( Timestamp.newBuilder() .setSeconds(value.getEpochSecond()) @@ -181,8 +196,16 @@ public ReadChangeStreamQuery continuationTokens( return this; } - /** Sets the heartbeat duration for the change stream. */ + /** + * This method is obsolete. Use {@link #heartbeatDurationDuration(java.time.Duration)} instead. + */ + @ObsoleteApi("Use heartbeatDurationDuration(java.time.Duration) instead") public ReadChangeStreamQuery heartbeatDuration(org.threeten.bp.Duration duration) { + return heartbeatDurationDuration(toJavaTimeDuration(duration)); + } + + /** Sets the heartbeat duration for the change stream. */ + public ReadChangeStreamQuery heartbeatDurationDuration(java.time.Duration duration) { builder.setHeartbeatDuration( Duration.newBuilder() .setSeconds(duration.getSeconds()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java index 50146f292a..697bfd1f04 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java @@ -24,7 +24,6 @@ import com.google.protobuf.ByteString; import java.io.Serializable; import java.util.List; -import org.threeten.bp.Instant; /** * Represents a data type in a SQL query. @@ -150,7 +149,7 @@ static SqlType bool() { } /** returns a {@link SqlType} for the {@code TIMESTAMP} type. */ - static SqlType timestamp() { + static SqlType timestamp() { return Type.Timestamp.create(); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java index 58c16e2c5c..117ae1ae09 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java @@ -15,6 +15,8 @@ */ package com.google.cloud.bigtable.data.v2.models.sql; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.bigtable.v2.ArrayValue; @@ -31,7 +33,6 @@ import java.util.List; import java.util.Map; import javax.annotation.Nullable; -import org.threeten.bp.Instant; /** * A SQL statement that can be executed by calling {@link @@ -163,11 +164,14 @@ public Builder setBooleanParam(String paramName, @Nullable Boolean value) { return this; } + public Builder setTimestampParam(String paramName, @Nullable org.threeten.bp.Instant value) { + return setTimestampParamInstant(paramName, toJavaTimeInstant(value)); + } /** * Sets a query parameter with the name {@code paramName} and the TIMESTAMP typed value {@code * value} */ - public Builder setTimestampParam(String paramName, @Nullable Instant value) { + public Builder setTimestampParamInstant(String paramName, @Nullable java.time.Instant value) { params.put(paramName, timestampParamOf(value)); return this; } @@ -239,7 +243,7 @@ private static Value booleanParamOf(@Nullable Boolean value) { return builder.build(); } - private static Value timestampParamOf(@Nullable Instant value) { + private static Value timestampParamOf(@Nullable java.time.Instant value) { Value.Builder builder = nullValueWithType(TIMESTAMP_TYPE); if (value != null) { builder.setTimestampValue(toTimestamp(value)); @@ -325,7 +329,7 @@ private static ArrayValue arrayValueOf(List value, SqlType.Array arrayType valueBuilder.addValues(Value.newBuilder().setBoolValue(boolElem).build()); break; case TIMESTAMP: - Instant timestampElem = (Instant) element; + java.time.Instant timestampElem = (java.time.Instant) element; valueBuilder.addValues( Value.newBuilder().setTimestampValue(toTimestamp(timestampElem)).build()); break; @@ -341,7 +345,7 @@ private static ArrayValue arrayValueOf(List value, SqlType.Array arrayType return valueBuilder.build(); } - private static Timestamp toTimestamp(Instant instant) { + private static Timestamp toTimestamp(java.time.Instant instant) { return Timestamp.newBuilder() .setSeconds(instant.getEpochSecond()) .setNanos(instant.getNano()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java index 8f450bbd92..fc3e286cf4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java @@ -15,12 +15,14 @@ */ package com.google.cloud.bigtable.data.v2.models.sql; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; + import com.google.api.core.BetaApi; +import com.google.api.core.ObsoleteApi; import com.google.cloud.Date; import com.google.protobuf.ByteString; import java.util.List; import java.util.Map; -import org.threeten.bp.Instant; /** * An interface for reading the columns of a {@code Struct} or {@code @@ -131,17 +133,29 @@ public interface StructReader { */ boolean getBoolean(String columnName); + /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead. */ + @ObsoleteApi("Use getTimestampInstant(int) instead") + org.threeten.bp.Instant getTimestamp(int columnIndex); + /** * @param columnIndex index of the column - * @return {@link Instant} type value of a non-{@code NULL} column + * @return {@link java.time.Instant} type value of a non-{@code NULL} column */ - Instant getTimestamp(int columnIndex); + default java.time.Instant getTimestampInstant(int columnIndex) { + return toJavaTimeInstant(getTimestamp(columnIndex)); + } + + /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead. */ + @ObsoleteApi("Use getTimestampInstant(String) instead") + org.threeten.bp.Instant getTimestamp(String columnName); /** * @param columnName name of the column - * @return {@link Instant} type value of a non-{@code NULL} column + * @return {@link java.time.Instant} type value of a non-{@code NULL} column */ - Instant getTimestamp(String columnName); + default java.time.Instant getTimestampInstant(String columnName) { + return toJavaTimeInstant(getTimestamp(columnName)); + } /** * @param columnIndex index of the column diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java index 62f8b5abf6..c3b0f94ec7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java @@ -30,13 +30,13 @@ import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.RateLimiter; +import java.time.Duration; +import java.time.Instant; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; import javax.annotation.Nonnull; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; class RateLimitingServerStreamingCallable extends ServerStreamingCallable { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java index b41acc4ac3..7627fb4751 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java @@ -22,7 +22,6 @@ import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.cloud.bigtable.data.v2.models.Value; import com.google.common.base.Preconditions; -import org.threeten.bp.Instant; /** * A state machine to produce change stream records from a stream of {@link @@ -332,9 +331,9 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { validate( dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: GC mutation shouldn't have source cluster id."); - builder.startGcMutation( + builder.startGcMutationInstant( dataChange.getRowKey(), - Instant.ofEpochSecond( + java.time.Instant.ofEpochSecond( dataChange.getCommitTimestamp().getSeconds(), dataChange.getCommitTimestamp().getNanos()), dataChange.getTiebreaker()); @@ -342,10 +341,10 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { validate( !dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: User initiated data change missing source cluster id."); - builder.startUserMutation( + builder.startUserMutationInstant( dataChange.getRowKey(), dataChange.getSourceClusterId(), - Instant.ofEpochSecond( + java.time.Instant.ofEpochSecond( dataChange.getCommitTimestamp().getSeconds(), dataChange.getCommitTimestamp().getNanos()), dataChange.getTiebreaker()); @@ -576,9 +575,9 @@ private State checkAndFinishMutationIfNeeded(ReadChangeStreamResponse.DataChange validate(!dataChange.getToken().isEmpty(), "Last data change missing token"); validate(dataChange.hasEstimatedLowWatermark(), "Last data change missing lowWatermark"); completeChangeStreamRecord = - builder.finishChangeStreamMutation( + builder.finishChangeStreamMutationInstant( dataChange.getToken(), - Instant.ofEpochSecond( + java.time.Instant.ofEpochSecond( dataChange.getEstimatedLowWatermark().getSeconds(), dataChange.getEstimatedLowWatermark().getNanos())); return AWAITING_STREAM_RECORD_CONSUME; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporter.java index 8aa53fa198..cddb523c6a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporter.java @@ -64,7 +64,6 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Bigtable Cloud Monitoring OpenTelemetry Exporter. @@ -145,10 +144,10 @@ public static BigtableCloudMonitoringExporter create( settingsBuilder.setEndpoint(endpoint); } - org.threeten.bp.Duration timeout = Duration.ofMinutes(1); + java.time.Duration timeout = java.time.Duration.ofMinutes(1); // TODO: createServiceTimeSeries needs special handling if the request failed. Leaving // it as not retried for now. - settingsBuilder.createServiceTimeSeriesSettings().setSimpleTimeoutNoRetries(timeout); + settingsBuilder.createServiceTimeSeriesSettings().setSimpleTimeoutNoRetriesDuration(timeout); // Detect the resource that the client application is running on. For example, // this could be a GCE instance or a GKE pod. Currently, we only support GCE instance and diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java index e639ea5627..5da062b9f3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java @@ -16,6 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.api.gax.tracing.ApiTracerFactory.OperationType; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METHOD_KEY; @@ -24,6 +25,7 @@ import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.TABLE_ID_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ZONE_ID_KEY; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.SpanName; import com.google.cloud.bigtable.Version; @@ -40,7 +42,6 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Logger; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * A {@link BigtableTracer} that records built-in metrics and publish under the @@ -200,8 +201,18 @@ public void attemptCancelled() { recordAttemptCompletion(new CancellationException()); } + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") @Override - public void attemptFailed(Throwable error, Duration delay) { + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailedDuration(error, toJavaTimeDuration(delay)); + } + + @Override + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { recordAttemptCompletion(error); } @@ -291,7 +302,7 @@ public void setLocations(String zone, String cluster) { @Override public void batchRequestThrottled(long throttledTimeNanos) { - totalClientBlockingTime.addAndGet(Duration.ofNanos(throttledTimeNanos).toMillis()); + totalClientBlockingTime.addAndGet(java.time.Duration.ofNanos(throttledTimeNanos).toMillis()); } @Override diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java index 7882c82d93..cb846f19b7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java @@ -15,12 +15,14 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + +import com.google.api.core.ObsoleteApi; import com.google.api.gax.tracing.ApiTracer; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Combines multiple {@link ApiTracer}s and {@link BigtableTracer}s into a single {@link ApiTracer}. @@ -124,9 +126,20 @@ public void attemptCancelled() { } } - public void attemptFailed(Throwable error, Duration delay) { + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") + @Override + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailedDuration(error, toJavaTimeDuration(delay)); + } + + @Override + public void attemptFailedDuration(Throwable error, java.time.Duration delay) { for (ApiTracer child : children) { - child.attemptFailed(error, delay); + child.attemptFailedDuration(error, delay); } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java index a2c5bdac1f..dda7707af7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java @@ -15,6 +15,9 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + +import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; import com.google.api.gax.tracing.SpanName; @@ -32,7 +35,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; -import org.threeten.bp.Duration; class MetricsTracer extends BigtableTracer { @@ -152,8 +154,18 @@ public void attemptCancelled() { recordAttemptCompletion(new CancellationException()); } + /** + * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} + * instead. + */ + @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") + @Override + public void attemptFailed(Throwable throwable, org.threeten.bp.Duration duration) { + attemptFailedDuration(throwable, toJavaTimeDuration(duration)); + } + @Override - public void attemptFailed(Throwable throwable, Duration duration) { + public void attemptFailedDuration(Throwable throwable, java.time.Duration duration) { recordAttemptCompletion(throwable); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/TracedBatcherUnaryCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/TracedBatcherUnaryCallable.java index ce73d75dc1..44ba688d55 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/TracedBatcherUnaryCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/TracedBatcherUnaryCallable.java @@ -21,7 +21,6 @@ import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.UnaryCallable; import com.google.api.gax.tracing.ApiTracer; -import org.threeten.bp.Duration; /** * This callable will extract total throttled time from {@link ApiCallContext} and add it to {@link @@ -44,7 +43,8 @@ public ApiFuture futureCall(RequestT request, ApiCallContext context) if (tracer instanceof BigtableTracer) { ((BigtableTracer) tracer) .batchRequestThrottled( - Duration.ofMillis(context.getOption(Batcher.THROTTLED_TIME_KEY)).toNanos()); + java.time.Duration.ofMillis(context.getOption(Batcher.THROTTLED_TIME_KEY)) + .toNanos()); } } return innerCallable.futureCall(request, context); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/AttemptCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/AttemptCallable.java index 3599e1e4df..6d5c75ea99 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/AttemptCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/AttemptCallable.java @@ -24,7 +24,6 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.common.base.Preconditions; import java.util.concurrent.Callable; -import org.threeten.bp.Duration; // TODO: remove this once ApiResultRetryAlgorithm is added to gax. /** @@ -59,9 +58,9 @@ public ResponseT call() { try { // Set the RPC timeout if the caller did not provide their own. - Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeout(); + java.time.Duration rpcTimeout = externalFuture.getAttemptSettings().getRpcTimeoutDuration(); if (!rpcTimeout.isZero() && callContext.getTimeout() == null) { - callContext = callContext.withTimeout(rpcTimeout); + callContext = callContext.withTimeoutDuration(rpcTimeout); } externalFuture.setAttemptFuture(new NonCancellableFuture()); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java index 085b48bbb5..dd131f2498 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java @@ -23,7 +23,6 @@ import com.google.protobuf.util.Durations; import com.google.rpc.RetryInfo; import org.checkerframework.checker.nullness.qual.Nullable; -import org.threeten.bp.Duration; // TODO move this algorithm to gax /** @@ -36,11 +35,11 @@ public class RetryInfoRetryAlgorithm extends BasicResultRetryAlgorith @Override public TimedAttemptSettings createNextAttempt( Throwable prevThrowable, ResponseT prevResponse, TimedAttemptSettings prevSettings) { - Duration retryDelay = extractRetryDelay(prevThrowable); + java.time.Duration retryDelay = extractRetryDelay(prevThrowable); if (retryDelay != null) { return prevSettings .toBuilder() - .setRandomizedRetryDelay(retryDelay) + .setRandomizedRetryDelayDuration(retryDelay) .setAttemptCount(prevSettings.getAttemptCount() + 1) .setOverallAttemptCount(prevSettings.getAttemptCount() + 1) .build(); @@ -81,8 +80,7 @@ public boolean shouldRetry( && ((ApiException) previousThrowable).isRetryable(); } - @Nullable - static Duration extractRetryDelay(@Nullable Throwable throwable) { + static java.time.Duration extractRetryDelay(@Nullable Throwable throwable) { if (throwable == null) { return null; } @@ -97,6 +95,6 @@ static Duration extractRetryDelay(@Nullable Throwable throwable) { return null; } RetryInfo retryInfo = exception.getErrorDetails().getRetryInfo(); - return Duration.ofMillis(Durations.toMillis(retryInfo.getRetryDelay())); + return java.time.Duration.ofMillis(Durations.toMillis(retryInfo.getRetryDelay())); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java index 7ac632f29b..fbdab21d3f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java @@ -22,11 +22,11 @@ import com.google.api.gax.rpc.StatusCode.Code; import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStubSettings; import java.io.IOException; +import java.time.Duration; 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 BigtableInstanceAdminSettingsTest { @@ -139,7 +139,7 @@ public void testToString() throws IOException { stubSettings .getInstanceSettings() .setRetrySettings( - RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build()); + RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(812)).build()); BigtableInstanceAdminSettings settings = builder.build(); checkToString(settings); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 3cf3ded747..a242227647 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -105,7 +105,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) /** @@ -307,7 +306,7 @@ public void testUpdateTable() { com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest request = com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest.of(TABLE_ID) - .addChangeStreamRetention(org.threeten.bp.Duration.ofHours(24)); + .addChangeStreamRetentionDuration(java.time.Duration.ofHours(24)); com.google.bigtable.admin.v2.Table expectedResponse = com.google.bigtable.admin.v2.Table.newBuilder() @@ -329,8 +328,10 @@ public void testUpdateTable() { // Verify assertThat(actualResult.getId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getChangeStreamRetention()) - .isEqualTo(org.threeten.bp.Duration.ofHours(24)); + assertThat(actualResult.getChangeStreamRetentionDuration()) + .isEqualTo(java.time.Duration.ofHours(24)); + assertThat(actualResult.getChangeStreamRetentionDuration().toMillis()) + .isEqualTo(actualResult.getChangeStreamRetention().toMillis()); } @Test @@ -644,7 +645,7 @@ public void testCreateBackup() { CreateBackupRequest req = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .setExpireTimeInstant(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); mockOperationResult( mockCreateBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -668,12 +669,12 @@ public void testCreateBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getStartTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getStartTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -692,9 +693,10 @@ public void testCreateHotBackup() { CreateBackupRequest req = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))) + .setExpireTimeInstant(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTime(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + .setHotToStandardTimeInstant( + java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); mockOperationResult( mockCreateBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -720,15 +722,15 @@ public void testCreateHotBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getStartTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getStartTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.HOT); - assertThat(actualResult.getHotToStandardTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + assertThat(actualResult.getHotToStandardTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -767,12 +769,12 @@ public void testGetBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getExpireTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(actualResult.getStartTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getStartTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); assertThat(actualResult.getState()).isEqualTo(Backup.State.fromProto(state)); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.STANDARD); @@ -805,10 +807,10 @@ public void testUpdateBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getExpireTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(actualResult.getHotToStandardTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + assertThat(actualResult.getExpireTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getHotToStandardTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -978,7 +980,7 @@ public void testCopyBackup() { String srcTableId = "src-table"; String srcClusterId = "src-cluster"; String srcBackupId = "src-backup"; - Instant expireTime = Instant.now().plus(org.threeten.bp.Duration.ofDays(15)); + java.time.Instant expireTime = java.time.Instant.now().plus(java.time.Duration.ofDays(15)); long sizeBytes = 123456789; String dstBackupName = @@ -991,7 +993,7 @@ public void testCopyBackup() { CopyBackupRequest.of(srcClusterId, srcBackupId) .setSourceInstance(srcProjectId, srcInstanceId) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(expireTime); + .setExpireTimeInstant(expireTime); mockOperationResult( mockCopyBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -1022,11 +1024,11 @@ public void testCopyBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(srcTableId); assertThat(actualResult.getSourceBackupId()).isEqualTo(srcBackupId); - assertThat(actualResult.getStartTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTime()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTime()).isEqualTo(expireTime); + assertThat(actualResult.getStartTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTimeInstant()) + .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTimeInstant()).isEqualTo(expireTime); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java index 506f73700b..451454c735 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java @@ -31,7 +31,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BigtableTableAdminSettingsTest { @@ -165,7 +164,9 @@ public void testToString() throws IOException { stubSettings .getBackupSettings() .setRetrySettings( - RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build()); + RetrySettings.newBuilder() + .setTotalTimeoutDuration(java.time.Duration.ofMinutes(812)) + .build()); BigtableTableAdminSettings settings = builder.build(); checkToString(settings); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 465bf2d467..9a328185ac 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -45,6 +45,8 @@ import com.google.common.base.Stopwatch; import com.google.protobuf.ByteString; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -59,8 +61,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class BigtableBackupIT { @@ -149,7 +149,7 @@ public void createAndGetBackupTest() { CreateBackupRequest request = CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTime(expireTime); + .setExpireTimeInstant(expireTime); try { Backup response = tableAdmin.createBackup(request); assertWithMessage("Got wrong backup Id in CreateBackup") @@ -196,9 +196,9 @@ public void createAndGetHotBackupTest() { CreateBackupRequest request = CreateBackupRequest.of(targetClusterHot, backupId) .setSourceTableId(testTableHot.getId()) - .setExpireTime(expireTime) + .setExpireTimeInstant(expireTime) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTime(hotToStandardTime); + .setHotToStandardTimeInstant(hotToStandardTime); try { Backup response = tableAdminHot.createBackup(request); assertWithMessage("Got wrong backup Id in CreateBackup") @@ -274,14 +274,14 @@ public void updateBackupTest() { tableAdminHot.createBackup( CreateBackupRequest.of(targetClusterHot, backupId) .setSourceTableId(testTableHot.getId()) - .setExpireTime(Instant.now().plus(Duration.ofDays(15))) + .setExpireTimeInstant(Instant.now().plus(Duration.ofDays(15))) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTime(Instant.now().plus(Duration.ofDays(10)))); + .setHotToStandardTimeInstant(Instant.now().plus(Duration.ofDays(10)))); Instant expireTime = Instant.now().plus(Duration.ofDays(20)); UpdateBackupRequest req = UpdateBackupRequest.of(targetClusterHot, backupId) - .setExpireTime(expireTime) + .setExpireTimeInstant(expireTime) .clearHotToStandardTime(); try { Backup backup = tableAdminHot.updateBackup(req); @@ -347,7 +347,7 @@ public void crossInstanceRestoreTest() tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTime(Instant.now().plus(Duration.ofHours(6)))); + .setExpireTimeInstant(Instant.now().plus(Duration.ofHours(6)))); Stopwatch stopwatch = Stopwatch.createStarted(); @@ -407,13 +407,13 @@ public void copyBackupTest() tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTime(expireTime)); + .setExpireTimeInstant(expireTime)); try { CopyBackupRequest req = CopyBackupRequest.of(targetCluster, backupId) .setDestination(targetCluster, copiedBackupId) - .setExpireTime(expireTime); + .setExpireTimeInstant(expireTime); Backup result = tableAdmin.copyBackup(req); assertWithMessage("Got wrong copied backup id in CopyBackup API") .that(result.getId()) @@ -448,7 +448,7 @@ public void crossInstanceCopyBackupTest() tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTime(expireTime)); + .setExpireTimeInstant(expireTime)); // Set up a new instance to test cross-instance copy. The backup will be copied here String destInstance = prefixGenerator.newPrefix(); @@ -468,7 +468,7 @@ public void crossInstanceCopyBackupTest() CopyBackupRequest.of(targetCluster, backupId) .setSourceInstance(testEnvRule.env().getInstanceId()) .setDestination(destCluster, copiedBackupId) - .setExpireTime(expireTime); + .setExpireTimeInstant(expireTime); Backup result = destTableAdmin.copyBackup(req); assertWithMessage("Got wrong copied backup id in CopyBackup API") .that(result.getId()) @@ -529,7 +529,7 @@ public void backupIamTest() { private CreateBackupRequest createBackupRequest(String backupId) { return CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTime(Instant.now().plus(Duration.ofDays(15))); + .setExpireTimeInstant(Instant.now().plus(Duration.ofDays(15))); } private static Table createAndPopulateTestTable( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java index 11f4a99b1c..7f4c179280 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java @@ -39,6 +39,8 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -50,8 +52,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; -import org.threeten.bp.temporal.ChronoUnit; /** * Tests our CMEK offering. It can take up to 5 mins after a CMEK-protected table is created for the @@ -210,7 +210,7 @@ public void backupTest() { // taken tableAdmin.createBackup( CreateBackupRequest.of(clusterId1, BACKUP_ID) - .setExpireTime(Instant.now().plus(6, ChronoUnit.HOURS)) + .setExpireTimeInstant(Instant.now().plus(6, ChronoUnit.HOURS)) .setSourceTableId(TEST_TABLE_ID)); Backup backup = tableAdmin.getBackup(clusterId1, BACKUP_ID); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index cfcc8d0b42..82965e5ba9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -42,6 +42,7 @@ import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; import com.google.common.collect.Maps; import com.google.protobuf.ByteString; +import java.time.Duration; import java.util.List; import java.util.Map; import org.junit.After; @@ -52,7 +53,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 BigtableTableAdminClientIT { @@ -90,7 +90,7 @@ public void createTable() { .addFamily("cf2", GCRULES.maxVersions(10)) .addSplit(ByteString.copyFromUtf8("b")) .addSplit(ByteString.copyFromUtf8("q")) - .addChangeStreamRetention(Duration.ofDays(2)); + .addChangeStreamRetentionDuration(Duration.ofDays(2)); Table tableResponse = tableAdmin.createTable(createTableReq); assertEquals(tableId, tableResponse.getId()); @@ -121,13 +121,13 @@ public void updateTable() { CreateTableRequest createTableReq = CreateTableRequest.of(tableId) .addFamily("cf1") - .addChangeStreamRetention(Duration.ofDays(2)); + .addChangeStreamRetentionDuration(Duration.ofDays(2)); Table tableResponse = tableAdmin.createTable(createTableReq); assertEquals(tableId, tableResponse.getId()); assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetention()); UpdateTableRequest updateTableRequest = - UpdateTableRequest.of(tableId).addChangeStreamRetention(Duration.ofDays(4)); + UpdateTableRequest.of(tableId).addChangeStreamRetentionDuration(Duration.ofDays(4)); tableResponse = tableAdmin.updateTable(updateTableRequest); assertEquals(tableId, tableResponse.getId()); assertEquals(Duration.ofDays(4), tableResponse.getChangeStreamRetention()); @@ -145,20 +145,21 @@ public void modifyFamilies() { ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId) .addFamily("mf1") - .addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))) + .addFamily("mf2", GCRULES.maxAgeDuration(Duration.ofSeconds(1000, 20000))) .updateFamily( "mf1", GCRULES .union() - .rule(GCRULES.maxAge(Duration.ofSeconds(100))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(100))) .rule(GCRULES.maxVersions(1))) .addFamily( "mf3", GCRULES .intersection() - .rule(GCRULES.maxAge(Duration.ofSeconds(2000))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(2000))) .rule(GCRULES.maxVersions(10))) - .addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))) + .addFamily( + "mf4", GCRULES.intersection().rule(GCRULES.maxAgeDuration(Duration.ofSeconds(360)))) .addFamily("mf5") .addFamily("mf6") .dropFamily("mf5") diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java index 2fc9ad2390..ab87d3bff8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java @@ -23,11 +23,11 @@ import com.google.protobuf.Timestamp; import com.google.protobuf.util.Timestamps; import com.google.rpc.Code; +import java.time.Instant; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class BackupTest { @@ -91,12 +91,13 @@ public void testFromProto() { assertThat(result.getId()).isEqualTo("backup1"); assertThat(result.getSourceTableId()).isEqualTo("table1"); assertThat(result.getSourceBackupId()).isEqualTo("backup2"); - assertThat(result.getExpireTime()) + assertThat(result.getExpireTimeInstant()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(result.getStartTime()) + assertThat(result.getStartTimeInstant()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(result.getEndTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(result.getHotToStandardTime()) + assertThat(result.getEndTimeInstant()) + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(result.getHotToStandardTimeInstant()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(result.getSizeBytes()).isEqualTo(123456); assertThat(result.getState()).isEqualTo(Backup.State.READY); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java index df8830da8e..27300b1a24 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java @@ -19,11 +19,11 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.util.Timestamps; +import java.time.Duration; +import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class CopyBackupRequestTest { @@ -43,7 +43,7 @@ public void testToProto() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -63,7 +63,7 @@ public void testToProtoCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -83,7 +83,7 @@ public void testToProtoCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -102,18 +102,18 @@ public void testEquality() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); } @Test @@ -122,20 +122,20 @@ public void testEqualityCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); } @Test @@ -144,20 +144,20 @@ public void testEqualityCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME)); + .setExpireTimeInstant(EXPIRE_TIME)); } @Test @@ -165,19 +165,19 @@ public void testHashCode() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); } @@ -187,21 +187,21 @@ public void testHashCodeCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); } @@ -211,21 +211,21 @@ public void testHashCodeCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME); + .setExpireTimeInstant(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .hashCode()); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java index 821919264e..8f8b0747cf 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java @@ -21,11 +21,11 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.admin.v2.models.Backup.BackupType; import com.google.protobuf.util.Timestamps; +import java.time.Duration; +import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class CreateBackupRequestTest { @@ -43,9 +43,9 @@ public void testToProto() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); com.google.bigtable.admin.v2.CreateBackupRequest requestProto = com.google.bigtable.admin.v2.CreateBackupRequest.newBuilder() @@ -68,33 +68,33 @@ public void testEquality() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); assertThat(request) .isEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME)); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId("another-table") - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME)); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.STANDARD) - .setHotToStandardTime(HOT_TO_STANDARD_TIME)); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); } @Test @@ -102,35 +102,35 @@ public void testHashCode() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); assertThat(request.hashCode()) .isEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId("another-table") - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTime(HOT_TO_STANDARD_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .setBackupType(BackupType.BACKUP_TYPE_UNSPECIFIED) - .setHotToStandardTime(HOT_TO_STANDARD_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) .hashCode()); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java index 0f7a58c078..07ab421114 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java @@ -24,11 +24,11 @@ import com.google.bigtable.admin.v2.Table; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.ByteString; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CreateTableRequestTest { @@ -48,7 +48,7 @@ public void testToProto() { .addFamily("another-family", GCRULES.maxAge(100, TimeUnit.HOURS)) .addSplit(splitKey) .addSplit(secondSplitKey) - .addChangeStreamRetention(Duration.ofHours(24)); + .addChangeStreamRetentionDuration(Duration.ofHours(24)); com.google.bigtable.admin.v2.CreateTableRequest requestProto = com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() @@ -140,7 +140,7 @@ public void testEquality() { .isEqualTo( CreateTableRequest.of(TABLE_ID) .addFamily("family-id") - .addFamily("another-family", GCRULES.maxAge(Duration.ofHours(100))) + .addFamily("another-family", GCRULES.maxAgeDuration(Duration.ofHours(100))) .addSplit(splitKey)); assertThat(request) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java index 61a1527a34..b9994fa24b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java @@ -27,18 +27,18 @@ import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class GCRulesTest { @Test public void duration() { - DurationRule actual = GCRULES.maxAge(Duration.ofSeconds(61, 9)); + DurationRule actual = GCRULES.maxAgeDuration(Duration.ofSeconds(61, 9)); GcRule expected = buildAgeRule(61, 9); assertNotNull(actual.getMaxAge()); assertThat(actual.toProto()).isEqualTo(expected); @@ -46,14 +46,14 @@ public void duration() { @Test public void durationSeconds() { - GcRule actual = GCRULES.maxAge(Duration.ofSeconds(1)).toProto(); + GcRule actual = GCRULES.maxAgeDuration(Duration.ofSeconds(1)).toProto(); GcRule expected = buildAgeRule(1, 0); assertThat(actual).isEqualTo(expected); } @Test public void durationNanos() { - GcRule actual = GCRULES.maxAge(Duration.ofNanos(11)).toProto(); + GcRule actual = GCRULES.maxAgeDuration(Duration.ofNanos(11)).toProto(); GcRule expected = buildAgeRule(0, 11); assertThat(actual).isEqualTo(expected); } @@ -114,7 +114,7 @@ public void unionTwo() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) .toProto(); GcRule expected = @@ -132,8 +132,8 @@ public void unionThree() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1))) - .rule(GCRULES.maxAge(Duration.ofNanos(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofNanos(1))) .toProto(); GcRule expected = @@ -168,7 +168,7 @@ public void intersectionTwo() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) .toProto(); GcRule expected = @@ -188,8 +188,8 @@ public void intersectionThree() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1))) - .rule(GCRULES.maxAge(Duration.ofNanos(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) + .rule(GCRULES.maxAgeDuration(Duration.ofNanos(1))) .toProto(); GcRule expected = @@ -213,12 +213,12 @@ public void unionOfIntersections() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1)))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))) .rule( GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1)))); + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))); GcRule expected = GcRule.newBuilder() @@ -251,12 +251,12 @@ public void intersectionOfUnions() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1)))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))) .rule( GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1)))); + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))); GcRule expected = GcRule.newBuilder() @@ -294,9 +294,9 @@ public void unionOfRules() { GCRules.GCRule modelGCRule = GCRULES .union() - .rule(GCRULES.maxAge(Duration.ofSeconds(10))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(10))) .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(20, 2))); + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(20, 2))); assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); } @@ -314,7 +314,7 @@ public void intersectionWithFromProto() { GCRules.GCRule modelGCRule = GCRules.GCRULES .intersection() - .rule(GCRULES.maxAge(org.threeten.bp.Duration.ofSeconds(10, 5))) + .rule(GCRULES.maxAgeDuration(java.time.Duration.ofSeconds(10, 5))) .rule(GCRULES.maxVersions(1)) .rule(GCRULES.maxVersions(2)); assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); @@ -351,12 +351,12 @@ public void unionOfIntersectionFromProto() { GCRULES .intersection() .rule(GCRULES.maxVersions(10)) - .rule(GCRULES.maxAge(Duration.ofSeconds(2, 4)))) + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(2, 4)))) .rule( GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAge(Duration.ofSeconds(1, 1)))); + .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1, 1)))); assertThat(GCRules.GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java index 9551fd70c4..54f3b53142 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java @@ -21,11 +21,11 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; import com.google.protobuf.util.Timestamps; +import java.time.Duration; +import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class UpdateBackupRequestTest { @@ -43,8 +43,8 @@ public class UpdateBackupRequestTest { public void testToProto() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setExpireTimeInstant(EXPIRE_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); com.google.bigtable.admin.v2.UpdateBackupRequest requestProto = com.google.bigtable.admin.v2.UpdateBackupRequest.newBuilder() @@ -69,22 +69,22 @@ public void testToProto() { public void testEquality() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setExpireTimeInstant(EXPIRE_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); assertThat(request) .isEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) - .setHotToStandardTime(HOT_TO_STANDARD_TIME)); + .setExpireTimeInstant(EXPIRE_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME_2) - .setHotToStandardTime(HOT_TO_STANDARD_TIME)); + .setExpireTimeInstant(EXPIRE_TIME_2) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .clearHotToStandardTime()); } @@ -92,24 +92,24 @@ public void testEquality() { public void testHashCode() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) - .setHotToStandardTime(HOT_TO_STANDARD_TIME); + .setExpireTimeInstant(EXPIRE_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); assertThat(request.hashCode()) .isEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) - .setHotToStandardTime(HOT_TO_STANDARD_TIME) + .setExpireTimeInstant(EXPIRE_TIME) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME_2) - .setHotToStandardTime(HOT_TO_STANDARD_TIME) + .setExpireTimeInstant(EXPIRE_TIME_2) + .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTime(EXPIRE_TIME) + .setExpireTimeInstant(EXPIRE_TIME) .clearHotToStandardTime() .hashCode()); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java index fabebdccbf..b3515364e1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java @@ -22,10 +22,10 @@ import com.google.bigtable.admin.v2.Table; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; +import java.time.Duration; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class UpdateTableRequestTest { @@ -36,7 +36,7 @@ public class UpdateTableRequestTest { @Test public void testEnableChangeStreamToProto() { UpdateTableRequest request = - UpdateTableRequest.of(TABLE_ID).addChangeStreamRetention(Duration.ofHours(24)); + UpdateTableRequest.of(TABLE_ID).addChangeStreamRetentionDuration(Duration.ofHours(24)); com.google.bigtable.admin.v2.UpdateTableRequest requestProto = com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() @@ -57,7 +57,7 @@ public void testEnableChangeStreamToProto() { @Test public void testDisableChangeStreamToProto() { UpdateTableRequest request = - UpdateTableRequest.of(TABLE_ID).addChangeStreamRetention(Duration.ofHours(0)); + UpdateTableRequest.of(TABLE_ID).addChangeStreamRetentionDuration(Duration.ofHours(0)); com.google.bigtable.admin.v2.UpdateTableRequest requestProto = com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java index 2628cdf224..db199950ce 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/stub/AwaitConsistencyCallableTest.java @@ -35,6 +35,7 @@ import com.google.bigtable.admin.v2.TableName; import com.google.cloud.bigtable.admin.v2.models.ConsistencyRequest; import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext; +import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -47,7 +48,6 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class AwaitConsistencyCallableTest { @@ -80,14 +80,14 @@ public void setUp() { RetrySettings retrySettings = RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofMillis(100)) + .setTotalTimeoutDuration(Duration.ofMillis(100)) // Delay settings: 1 ms const - .setInitialRetryDelay(Duration.ofMillis(1)) - .setMaxRetryDelay(Duration.ofMillis(1)) + .setInitialRetryDelayDuration(Duration.ofMillis(1)) + .setMaxRetryDelayDuration(Duration.ofMillis(1)) .setRetryDelayMultiplier(1.0) // RPC timeout: ignored const 1 s - .setInitialRpcTimeout(Duration.ofSeconds(1)) - .setMaxRpcTimeout(Duration.ofSeconds(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(1)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(1.0) .build(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java index 95955bab94..9a848e38d4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java @@ -57,6 +57,7 @@ import com.google.cloud.bigtable.data.v2.models.sql.Struct; import com.google.cloud.bigtable.data.v2.stub.sql.SqlProtoFactory; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -71,7 +72,6 @@ import org.junit.runners.JUnit4; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; -import org.threeten.bp.Instant; @RunWith(Enclosed.class) public class AbstractProtoStructReaderTest { @@ -311,8 +311,8 @@ public static List parameters() { Collections.singletonList(timestampValue(1000000, 100)), 0, "testField", - (BiFunction) TestProtoStruct::getTimestamp, - (BiFunction) TestProtoStruct::getTimestamp, + (BiFunction) TestProtoStruct::getTimestampInstant, + (BiFunction) TestProtoStruct::getTimestampInstant, Instant.ofEpochSecond(1000000, 100) }, // MAX long timestamp - bigtable allows users to set timestamp micros to any long @@ -323,8 +323,8 @@ public static List parameters() { Collections.singletonList(timestampValue(MAX_TS_SECONDS, 0)), 0, "testField", - (BiFunction) TestProtoStruct::getTimestamp, - (BiFunction) TestProtoStruct::getTimestamp, + (BiFunction) TestProtoStruct::getTimestampInstant, + (BiFunction) TestProtoStruct::getTimestampInstant, Instant.ofEpochSecond(MAX_TS_SECONDS) }, // Date diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java index 6fa71e7fff..a4b364cf9d 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java @@ -47,13 +47,13 @@ import com.google.cloud.Date; import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ProtoStructTest { @@ -101,7 +101,7 @@ public void getByIndex_supportsAllTypes() { assertThat(struct.getDouble(3)).isEqualTo(1.23d); assertThat(struct.getFloat(4)).isEqualTo(1.23f); assertThat(struct.getBoolean(5)).isTrue(); - assertThat(struct.getTimestamp(6)).isEqualTo(Instant.ofEpochSecond(100000, 100)); + assertThat(struct.getTimestampInstant(6)).isEqualTo(Instant.ofEpochSecond(100000, 100)); assertThat(struct.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(struct.getStruct(8)) .isEqualTo( @@ -129,7 +129,8 @@ public void getByNameSupportsAllTypes() { assertThat(struct.getDouble("doubleField")).isEqualTo(1.23d); assertThat(struct.getFloat("floatField")).isEqualTo(1.23f); assertThat(struct.getBoolean("booleanField")).isTrue(); - assertThat(struct.getTimestamp("timestampField")).isEqualTo(Instant.ofEpochSecond(100000, 100)); + assertThat(struct.getTimestampInstant("timestampField")) + .isEqualTo(Instant.ofEpochSecond(100000, 100)); assertThat(struct.getDate("dateField")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(struct.getStruct("structField")) .isEqualTo( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java index a5b823b205..115cf1f279 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java @@ -54,6 +54,7 @@ import com.google.cloud.bigtable.data.v2.stub.sql.SqlServerStreamImpl; import com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -62,7 +63,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ResultSetImplTest { @@ -126,8 +126,8 @@ public void testSingleRow() throws ExecutionException, InterruptedException { assertThat(resultSet.getFloat("float")).isEqualTo(1.23f); assertThat(resultSet.getBoolean(5)).isTrue(); assertThat(resultSet.getBoolean("boolean")).isTrue(); - assertThat(resultSet.getTimestamp(6)).isEqualTo(Instant.ofEpochSecond(10000000, 100)); - assertThat(resultSet.getTimestamp("timestamp")) + assertThat(resultSet.getTimestampInstant(6)).isEqualTo(Instant.ofEpochSecond(10000000, 100)); + assertThat(resultSet.getTimestampInstant("timestamp")) .isEqualTo(Instant.ofEpochSecond(10000000, 100)); assertThat(resultSet.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 5)); assertThat(resultSet.getDate("date")).isEqualTo(Date.fromYearMonthDay(2024, 6, 5)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java index 636042f5d9..41d4b6c0d3 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java @@ -63,6 +63,8 @@ import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -78,8 +80,6 @@ import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class BuiltinMetricsIT { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java index a284f8b7cb..ca580def73 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BulkMutateIT.java @@ -37,13 +37,13 @@ import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; import java.io.IOException; +import java.time.Duration; import java.util.Objects; import java.util.UUID; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BulkMutateIT { @@ -158,7 +158,7 @@ public void testManyMutations() throws IOException, InterruptedException { .stubSettings() .bulkMutateRowsSettings() .setBatchingSettings( - batchingSettings.toBuilder().setDelayThreshold(Duration.ofHours(1)).build()); + batchingSettings.toBuilder().setDelayThresholdDuration(Duration.ofHours(1)).build()); try (BigtableDataClient client = BigtableDataClient.create(settings); BatcherImpl batcher = (BatcherImpl) @@ -207,7 +207,7 @@ public void testManyMutationsOnAuthorizedView() throws IOException, InterruptedE .stubSettings() .bulkMutateRowsSettings() .setBatchingSettings( - batchingSettings.toBuilder().setDelayThreshold(Duration.ofHours(1)).build()); + batchingSettings.toBuilder().setDelayThresholdDuration(Duration.ofHours(1)).build()); try (BigtableDataClient client = BigtableDataClient.create(settings); Batcher batcher = client.newBulkMutationBatcher( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java index 620d290338..b105270472 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java @@ -31,6 +31,7 @@ import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; import com.google.protobuf.ByteString; import java.io.IOException; +import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -41,7 +42,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ExecuteQueryIT { @@ -124,10 +124,10 @@ public void withHistoryQuery() { Struct rowAQual_0 = rowAQual.get(0); assertThat(rowAQual_0.getBytes("value")).isEqualTo(ByteString.copyFromUtf8("val")); // timestamp in micros above so we divide by 1000 - assertThat(rowAQual_0.getTimestamp("timestamp")).isEqualTo(Instant.ofEpochMilli(10)); + assertThat(rowAQual_0.getTimestampInstant("timestamp")).isEqualTo(Instant.ofEpochMilli(10)); Struct rowAQual_1 = rowAQual.get(1); assertThat(rowAQual_1.getBytes("value")).isEqualTo(ByteString.copyFromUtf8("old")); - assertThat(rowAQual_1.getTimestamp("timestamp")).isEqualTo(Instant.ofEpochMilli(1)); + assertThat(rowAQual_1.getTimestampInstant("timestamp")).isEqualTo(Instant.ofEpochMilli(1)); assertThat(rs.next()).isTrue(); assertThat(rs.getBytes("_key")).isEqualTo(ByteString.copyFromUtf8(uniquePrefix + "b")); @@ -169,8 +169,8 @@ public void allTypes() { assertThat(rs.getDouble(4)).isEqualTo(1.3d); assertThat(rs.getBoolean("boolCol")).isTrue(); assertThat(rs.getBoolean(5)).isTrue(); - assertThat(rs.getTimestamp("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); - assertThat(rs.getTimestamp(6)).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestampInstant("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestampInstant(6)).isEqualTo(Instant.ofEpochMilli(1000)); assertThat(rs.getDate("dateCol")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getStruct("structCol").getLong("a")).isEqualTo(1); @@ -222,7 +222,7 @@ public void allQueryParamsTypes() { .setDoubleParam("doubleParam", 1.3d) .setFloatParam("floatParam", 1.4f) .setBooleanParam("boolParam", true) - .setTimestampParam("tsParam", Instant.ofEpochMilli(1000)) + .setTimestampParamInstant("tsParam", Instant.ofEpochMilli(1000)) .setDateParam("dateParam", Date.fromYearMonthDay(2024, 6, 1)) .setListParam( "byteArrayParam", diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java index 61c028cdb6..676497ddb0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java @@ -29,11 +29,11 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.time.Instant; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ChangeStreamMutationTest { @@ -73,17 +73,18 @@ public void userInitiatedMutationTest() throws IOException, ClassNotFoundExcepti Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Test the getters. assertThat(changeStreamMutation.getRowKey()).isEqualTo(ByteString.copyFromUtf8("key")); assertThat(changeStreamMutation.getType()).isEqualTo(ChangeStreamMutation.MutationType.USER); assertThat(changeStreamMutation.getSourceClusterId()).isEqualTo("fake-source-cluster-id"); - assertThat(changeStreamMutation.getCommitTimestamp()).isEqualTo(FAKE_COMMIT_TIMESTAMP); + assertThat(changeStreamMutation.getCommitTimestampInstant()).isEqualTo(FAKE_COMMIT_TIMESTAMP); assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0); assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token"); - assertThat(changeStreamMutation.getEstimatedLowWatermark()).isEqualTo(FAKE_LOW_WATERMARK); + assertThat(changeStreamMutation.getEstimatedLowWatermarkInstant()) + .isEqualTo(FAKE_LOW_WATERMARK); // Test serialization. ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -112,7 +113,7 @@ public void gcMutationTest() throws IOException, ClassNotFoundException { ByteString.copyFromUtf8("fake-qualifier"), Range.TimestampRange.create(1000L, 2000L)) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Test the getters. @@ -120,10 +121,11 @@ public void gcMutationTest() throws IOException, ClassNotFoundException { assertThat(changeStreamMutation.getType()) .isEqualTo(ChangeStreamMutation.MutationType.GARBAGE_COLLECTION); Assert.assertTrue(changeStreamMutation.getSourceClusterId().isEmpty()); - assertThat(changeStreamMutation.getCommitTimestamp()).isEqualTo(FAKE_COMMIT_TIMESTAMP); + assertThat(changeStreamMutation.getCommitTimestampInstant()).isEqualTo(FAKE_COMMIT_TIMESTAMP); assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0); assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token"); - assertThat(changeStreamMutation.getEstimatedLowWatermark()).isEqualTo(FAKE_LOW_WATERMARK); + assertThat(changeStreamMutation.getEstimatedLowWatermarkInstant()) + .isEqualTo(FAKE_LOW_WATERMARK); // Test serialization. ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -161,7 +163,7 @@ public void toRowMutationTest() { Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Convert it to a rowMutation and construct a MutateRowRequest. @@ -204,7 +206,7 @@ public void toRowMutationWithoutTokenShouldFailTest() { ChangeStreamMutation.createUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK); + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); Assert.assertThrows(IllegalStateException.class, builder::build); } @@ -244,7 +246,7 @@ public void toRowMutationEntryTest() { Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Convert it to a rowMutationEntry and construct a MutateRowRequest. @@ -284,7 +286,7 @@ public void toRowMutationEntryWithoutTokenShouldFailTest() { ChangeStreamMutation.createUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK); + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); Assert.assertThrows(IllegalStateException.class, builder::build); } @@ -309,7 +311,7 @@ public void testWithLongValue() { 1000L, ByteString.copyFrom(Longs.toByteArray(1L))) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); RowMutation rowMutation = changeStreamMutation.toRowMutation(TABLE_ID); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordTest.java index 3f09d9b443..14697f430e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.time.Instant; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -37,7 +38,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ChangeStreamRecordTest { @@ -129,7 +129,7 @@ public void heartbeatTest() { .build(); Heartbeat actualHeartbeat = Heartbeat.fromProto(heartbeatProto); - assertThat(actualHeartbeat.getEstimatedLowWatermark()) + assertThat(actualHeartbeat.getEstimatedLowWatermarkInstant()) .isEqualTo(Instant.ofEpochSecond(lowWatermark.getSeconds(), lowWatermark.getNanos())); assertThat(actualHeartbeat.getChangeStreamContinuationToken().getPartition()) .isEqualTo(ByteStringRange.create(rowRange.getStartKeyClosed(), rowRange.getEndKeyOpen())); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java index 22270bc269..56701a8e6f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java @@ -25,6 +25,7 @@ import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; import com.google.rpc.Status; +import java.time.Instant; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -32,7 +33,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class DefaultChangeStreamRecordAdapterTest { @@ -59,7 +59,7 @@ public void isHeartbeatTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); Assert.assertTrue(adapter.isHeartbeat(heartbeatRecord)); Assert.assertFalse(adapter.isHeartbeat(closeStreamRecord)); @@ -99,7 +99,7 @@ public void isChangeStreamMutationTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); Assert.assertFalse(adapter.isChangeStreamMutation(heartbeatRecord)); Assert.assertFalse(adapter.isChangeStreamMutation(closeStreamRecord)); @@ -112,7 +112,7 @@ public void getTokenFromChangeStreamMutationTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("change-stream-mutation-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); Assert.assertEquals( adapter.getTokenFromChangeStreamMutation(changeStreamMutationRecord), @@ -161,14 +161,14 @@ public void closeStreamTest() { @Test(expected = IllegalStateException.class) public void createHeartbeatWithExistingMutationShouldFailTest() { - changeStreamRecordBuilder.startGcMutation( + changeStreamRecordBuilder.startGcMutationInstant( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.onHeartbeat(ReadChangeStreamResponse.Heartbeat.getDefaultInstance()); } @Test(expected = IllegalStateException.class) public void createCloseStreamWithExistingMutationShouldFailTest() { - changeStreamRecordBuilder.startGcMutation( + changeStreamRecordBuilder.startGcMutationInstant( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.onCloseStream( ReadChangeStreamResponse.CloseStream.getDefaultInstance()); @@ -186,19 +186,21 @@ public void singleDeleteFamilyTest() { ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily(deleteFromFamily.getFamilyName()); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -225,11 +227,11 @@ public void singleDeleteCellTest() { ByteString.copyFromUtf8("fake-qualifier"), Range.TimestampRange.create(1000L, 2000L)) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteCells( deleteFromColumn.getFamilyName(), @@ -238,11 +240,13 @@ public void singleDeleteCellTest() { deleteFromColumn.getTimeRange().getStartTimestampMicros(), deleteFromColumn.getTimeRange().getEndTimestampMicros())); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -258,23 +262,25 @@ public void singleNonChunkedCellTest() { 100L, ByteString.copyFromUtf8("fake-value")) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. // Suppose the SetCell is not chunked and the state machine calls `cellValue()` once. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("fake-value")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -290,13 +296,13 @@ public void singleChunkedCellTest() { 100L, ByteString.copyFromUtf8("fake-value1-value2")) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. // Suppose the SetCell is chunked into two pieces and the state machine calls `cellValue()` // twice. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); @@ -304,11 +310,13 @@ public void singleChunkedCellTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value2")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -327,10 +335,10 @@ public void multipleChunkedCellsTest() { } expectedChangeStreamMutationBuilder .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK); + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); for (int i = 0; i < 10; ++i) { changeStreamRecordBuilder.startCell( @@ -342,11 +350,13 @@ public void multipleChunkedCellsTest() { } // Check that they're the same. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); } @@ -369,10 +379,10 @@ public void multipleDifferentModsTest() { 100L, ByteString.copyFromUtf8("chunked-value")) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK); + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily("fake-family"); // Add non-chunked cell. @@ -387,7 +397,8 @@ public void multipleDifferentModsTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); } @@ -418,13 +429,14 @@ public void resetTest() { ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily(deleteFromFamily.getDeleteFromFamily().getFamilyName()); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Reset a build a cell. @@ -438,10 +450,10 @@ public void resetTest() { 100L, ByteString.copyFromUtf8("fake-value1-value2")) .setToken("fake-token") - .setEstimatedLowWatermark(FAKE_LOW_WATERMARK) + .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) .build(); - changeStreamRecordBuilder.startUserMutation( + changeStreamRecordBuilder.startUserMutationInstant( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); @@ -449,7 +461,8 @@ public void resetTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value2")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutationInstant( + "fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java index 699f60a8d1..a7d6347488 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.time.Instant; import java.util.Collections; import org.junit.Before; import org.junit.Rule; @@ -41,7 +42,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ReadChangeStreamQueryTest { @@ -121,7 +121,8 @@ public void streamPartitionTest() { @Test public void startTimeTest() { - ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).startTime(FAKE_START_TIME); + ReadChangeStreamQuery query = + ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(FAKE_START_TIME); Builder expectedProto = expectedProtoBuilder() @@ -136,7 +137,8 @@ public void startTimeTest() { @Test public void endTimeTest() { - ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).endTime(FAKE_END_TIME); + ReadChangeStreamQuery query = + ReadChangeStreamQuery.create(TABLE_ID).endTimeInstant(FAKE_END_TIME); Builder expectedProto = expectedProtoBuilder() @@ -153,7 +155,7 @@ public void endTimeTest() { public void heartbeatDurationTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)); + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); Builder expectedProto = expectedProtoBuilder().setHeartbeatDuration(Duration.newBuilder().setSeconds(5).build()); @@ -206,7 +208,7 @@ public void createWithStartTimeAndContinuationTokensTest() { ChangeStreamContinuationToken token = ChangeStreamContinuationToken.fromProto(tokenProto); ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID) - .startTime(FAKE_START_TIME) + .startTimeInstant(FAKE_START_TIME) .continuationTokens(Collections.singletonList(token)); expect.expect(IllegalArgumentException.class); expect.expectMessage("startTime and continuationTokens can't be specified together"); @@ -231,8 +233,8 @@ public void serializationTest() throws IOException, ClassNotFoundException { ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") .continuationTokens(Collections.singletonList(token)) - .endTime(FAKE_END_TIME) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)); + .endTimeInstant(FAKE_END_TIME) + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); @@ -300,9 +302,9 @@ public void testEquality() { ReadChangeStreamQuery request = ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") - .startTime(FAKE_START_TIME) - .endTime(FAKE_END_TIME) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)); + .startTimeInstant(FAKE_START_TIME) + .endTimeInstant(FAKE_END_TIME) + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); // ReadChangeStreamQuery#toProto should not change the ReadChangeStreamQuery instance state request.toProto(requestContext); @@ -310,24 +312,26 @@ public void testEquality() { .isEqualTo( ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") - .startTime(FAKE_START_TIME) - .endTime(FAKE_END_TIME) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5))); + .startTimeInstant(FAKE_START_TIME) + .endTimeInstant(FAKE_END_TIME) + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5))); assertThat(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-1", "end-1")) .isNotEqualTo(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-2", "end-1")); - assertThat(ReadChangeStreamQuery.create(TABLE_ID).startTime(FAKE_START_TIME)) + assertThat(ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(FAKE_START_TIME)) .isNotEqualTo( - ReadChangeStreamQuery.create(TABLE_ID).startTime(Instant.ofEpochSecond(1L, 1001L))); - assertThat(ReadChangeStreamQuery.create(TABLE_ID).endTime(FAKE_END_TIME)) + ReadChangeStreamQuery.create(TABLE_ID) + .startTimeInstant(Instant.ofEpochSecond(1L, 1001L))); + assertThat(ReadChangeStreamQuery.create(TABLE_ID).endTimeInstant(FAKE_END_TIME)) .isNotEqualTo( - ReadChangeStreamQuery.create(TABLE_ID).endTime(Instant.ofEpochSecond(1L, 1001L))); + ReadChangeStreamQuery.create(TABLE_ID) + .endTimeInstant(Instant.ofEpochSecond(1L, 1001L))); assertThat( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5))) + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5))) .isNotEqualTo( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(6))); + .heartbeatDurationDuration(java.time.Duration.ofSeconds(6))); } @Test @@ -349,8 +353,8 @@ public void testClone() { ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("begin", "end") .continuationTokens(Collections.singletonList(token)) - .endTime(FAKE_END_TIME) - .heartbeatDuration(org.threeten.bp.Duration.ofSeconds(5)); + .endTimeInstant(FAKE_END_TIME) + .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); ReadChangeStreamRequest request = ReadChangeStreamRequest.newBuilder() .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java index cb19a7fde9..e2fecffdca 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java @@ -41,12 +41,12 @@ import com.google.cloud.Date; import com.google.cloud.bigtable.data.v2.internal.RequestContext; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class StatementTest { @@ -218,7 +218,7 @@ public void statementWithTimestampParam() { Statement s = Statement.newBuilder( "SELECT * FROM table WHERE PARSE_TIMESTAMP(\"%Y/%m/%dT%H:%M:%S\", CAST(cf[\"ts\"] AS STRING)) < @timeParam") - .setTimestampParam("timeParam", Instant.ofEpochSecond(1000, 100)) + .setTimestampParamInstant("timeParam", Instant.ofEpochSecond(1000, 100)) .build(); assertThat(s.toProto(REQUEST_CONTEXT)) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBatchingCallSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBatchingCallSettingsTest.java index dcdef068a5..cf42f07ff8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBatchingCallSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBatchingCallSettingsTest.java @@ -25,11 +25,11 @@ import com.google.api.gax.rpc.StatusCode; import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor; import com.google.common.collect.ImmutableSet; +import java.time.Duration; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BigtableBatchingCallSettingsTest { @@ -38,7 +38,7 @@ public class BigtableBatchingCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(Duration.ofMillis(5)) + .setDelayThresholdDuration(Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) @@ -111,7 +111,7 @@ public void testBuilderFromSettings() { BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBulkReadRowsCallSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBulkReadRowsCallSettingsTest.java index a343bf4667..63a6d95858 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBulkReadRowsCallSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableBulkReadRowsCallSettingsTest.java @@ -24,11 +24,11 @@ import com.google.api.gax.rpc.StatusCode; import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor; import com.google.common.collect.ImmutableSet; +import java.time.Duration; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BigtableBulkReadRowsCallSettingsTest { @@ -37,7 +37,7 @@ public class BigtableBulkReadRowsCallSettingsTest { BatchingSettings.newBuilder() .setElementCountThreshold(10L) .setRequestByteThreshold(20L) - .setDelayThreshold(Duration.ofMillis(5)) + .setDelayThresholdDuration(Duration.ofMillis(5)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100L) @@ -78,7 +78,7 @@ public void testBuilderFromSettings() { BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor()); RetrySettings retrySettings = - RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build(); + RetrySettings.newBuilder().setTotalTimeoutDuration(Duration.ofMinutes(1)).build(); builder .setBatchingSettings(BATCHING_SETTINGS) .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java index 95a807bf76..5f69a3c6cd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/CookiesHolderTest.java @@ -62,6 +62,7 @@ import io.grpc.StatusRuntimeException; import io.grpc.stub.StreamObserver; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -74,7 +75,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 CookiesHolderTest { @@ -145,8 +145,8 @@ public void sendHeaders(Metadata responseHeaders) { .checkAndMutateRowSettings() .setRetrySettings( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(10)) - .setMaxRetryDelay(Duration.ofMinutes(1)) + .setInitialRetryDelayDuration(Duration.ofMillis(10)) + .setMaxRetryDelayDuration(Duration.ofMinutes(1)) .setMaxAttempts(2) .build()) .setRetryableCodes(StatusCode.Code.UNAVAILABLE); @@ -156,8 +156,8 @@ public void sendHeaders(Metadata responseHeaders) { .readModifyWriteRowSettings() .setRetrySettings( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(10)) - .setMaxRetryDelay(Duration.ofMinutes(1)) + .setInitialRetryDelayDuration(Duration.ofMillis(10)) + .setMaxRetryDelayDuration(Duration.ofMinutes(1)) .setMaxAttempts(2) .build()) .setRetryableCodes(StatusCode.Code.UNAVAILABLE); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java index fdc6b5717e..d50175f525 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java @@ -42,6 +42,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.URI; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -51,7 +52,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class EnhancedBigtableStubSettingsTest { @@ -92,7 +92,7 @@ public void settingsAreNotLostTest() { .setEndpoint(endpoint) .setCredentialsProvider(credentialsProvider) .setStreamWatchdogProvider(watchdogProvider) - .setStreamWatchdogCheckInterval(watchdogInterval) + .setStreamWatchdogCheckIntervalDuration(watchdogInterval) .setEnableRoutingCookie(enableRoutingCookie) .setEnableRetryInfo(enableRetryInfo) .setMetricsEndpoint(metricsEndpoint); @@ -158,7 +158,7 @@ private void verifyBuilder( assertThat(builder.getEndpoint()).isEqualTo(endpoint); assertThat(builder.getCredentialsProvider()).isEqualTo(credentialsProvider); assertThat(builder.getStreamWatchdogProvider()).isSameInstanceAs(watchdogProvider); - assertThat(builder.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(builder.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(builder.getEnableRoutingCookie()).isEqualTo(enableRoutingCookie); assertThat(builder.getEnableRetryInfo()).isEqualTo(enableRetryInfo); assertThat(builder.getMetricsEndpoint()).isEqualTo(metricsEndpoint); @@ -222,16 +222,16 @@ public void readRowsIsNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); builder .readRowsSettings() - .setIdleTimeout(Duration.ofMinutes(5)) + .setIdleTimeoutDuration(Duration.ofMinutes(5)) .setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED) .setRetrySettings(retrySettings) .build(); @@ -240,18 +240,19 @@ public void readRowsIsNotLostTest() { builder.readRowSettings().setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED); builder.bulkReadRowsSettings().setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED); - assertThat(builder.readRowsSettings().getIdleTimeout()).isEqualTo(Duration.ofMinutes(5)); + assertThat(builder.readRowsSettings().getIdleTimeoutDuration()) + .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.readRowsSettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.readRowsSettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().readRowsSettings().getIdleTimeout()) + assertThat(builder.build().readRowsSettings().getIdleTimeoutDuration()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().readRowsSettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.build().readRowsSettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().toBuilder().readRowsSettings().getIdleTimeout()) + assertThat(builder.build().toBuilder().readRowsSettings().getIdleTimeoutDuration()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().toBuilder().readRowsSettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); @@ -281,10 +282,10 @@ public void readRowIsNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); @@ -369,10 +370,10 @@ public void sampleRowKeysSettingsAreNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); @@ -417,10 +418,10 @@ public void mutateRowSettingsAreNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); @@ -467,10 +468,10 @@ public void bulkMutateRowsSettingsAreNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); @@ -579,10 +580,10 @@ public void bulkReadRowsSettingsAreNotLostTest() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); @@ -626,7 +627,7 @@ public void mutateRowsHasSaneDefaultsTest() { verifyRetrySettingAreSane(builder.getRetryableCodes(), builder.getRetrySettings()); - assertThat(builder.getBatchingSettings().getDelayThreshold()) + assertThat(builder.getBatchingSettings().getDelayThresholdDuration()) .isIn(Range.open(Duration.ZERO, Duration.ofMinutes(1))); assertThat(builder.getBatchingSettings().getElementCountThreshold()) .isIn(Range.open(0L, 1_000L)); @@ -768,7 +769,8 @@ public void pingAndWarmRetriesAreDisabled() { EnhancedBigtableStubSettings.newBuilder().pingAndWarmSettings(); assertThat(builder.getRetrySettings().getMaxAttempts()).isAtMost(1); - assertThat(builder.getRetrySettings().getInitialRpcTimeout()).isAtMost(Duration.ofSeconds(30)); + assertThat(builder.getRetrySettings().getInitialRpcTimeoutDuration()) + .isAtMost(Duration.ofSeconds(30)); } @Test @@ -789,34 +791,35 @@ public void executeQuerySettingsAreNotLost() { RetrySettings retrySettings = RetrySettings.newBuilder() .setMaxAttempts(10) - .setTotalTimeout(Duration.ofHours(1)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setTotalTimeoutDuration(Duration.ofHours(1)) + .setInitialRpcTimeoutDuration(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) - .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setMaxRpcTimeoutDuration(Duration.ofSeconds(10)) .setJittered(true) .build(); builder .executeQuerySettings() - .setIdleTimeout(Duration.ofMinutes(5)) + .setIdleTimeoutDuration(Duration.ofMinutes(5)) .setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED) .setRetrySettings(retrySettings) .build(); builder.executeQuerySettings().setRetryableCodes(Code.ABORTED, Code.DEADLINE_EXCEEDED); - assertThat(builder.executeQuerySettings().getIdleTimeout()).isEqualTo(Duration.ofMinutes(5)); + assertThat(builder.executeQuerySettings().getIdleTimeoutDuration()) + .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.executeQuerySettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.executeQuerySettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().executeQuerySettings().getIdleTimeout()) + assertThat(builder.build().executeQuerySettings().getIdleTimeoutDuration()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().executeQuerySettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); assertThat(builder.build().executeQuerySettings().getRetrySettings()).isEqualTo(retrySettings); - assertThat(builder.build().toBuilder().executeQuerySettings().getIdleTimeout()) + assertThat(builder.build().toBuilder().executeQuerySettings().getIdleTimeoutDuration()) .isEqualTo(Duration.ofMinutes(5)); assertThat(builder.build().toBuilder().executeQuerySettings().getRetryableCodes()) .containsAtLeast(Code.ABORTED, Code.DEADLINE_EXCEEDED); @@ -832,8 +835,10 @@ public void executeQueryHasSaneDefaults() { // Retries aren't supported right now // call verifyRetrySettingAreSane when we do assertThat(builder.getRetryableCodes()).containsExactlyElementsIn(Collections.emptySet()); - assertThat(builder.getRetrySettings().getInitialRpcTimeout()).isEqualTo(Duration.ofSeconds(30)); - assertThat(builder.getRetrySettings().getMaxRpcTimeout()).isEqualTo(Duration.ofSeconds(30)); + assertThat(builder.getRetrySettings().getInitialRpcTimeoutDuration()) + .isEqualTo(Duration.ofSeconds(30)); + assertThat(builder.getRetrySettings().getMaxRpcTimeoutDuration()) + .isEqualTo(Duration.ofSeconds(30)); assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1); } @@ -843,21 +848,22 @@ public void executeQueryRetriesAreDisabled() { EnhancedBigtableStubSettings.newBuilder().executeQuerySettings(); assertThat(builder.getRetrySettings().getMaxAttempts()).isAtMost(1); - assertThat(builder.getRetrySettings().getInitialRpcTimeout()).isAtMost(Duration.ofSeconds(30)); + assertThat(builder.getRetrySettings().getInitialRpcTimeoutDuration()) + .isAtMost(Duration.ofSeconds(30)); } private void verifyRetrySettingAreSane(Set retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).containsAtLeast(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); - assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getTotalTimeoutDuration()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getInitialRetryDelayDuration()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); - assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); + assertThat(retrySettings.getMaxRetryDelayDuration()).isGreaterThan(Duration.ZERO); - assertThat(retrySettings.getInitialRpcTimeout()).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); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java index 495250fe13..1adf37b6da 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java @@ -118,6 +118,7 @@ import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; +import java.time.Duration; import java.util.Base64; import java.util.Collection; import java.util.Iterator; @@ -132,7 +133,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class EnhancedBigtableStubTest { @@ -599,7 +599,7 @@ public void testCallContextPropagatedInMutationBatcher() // Override the timeout GrpcCallContext clientCtx = - GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10)); + GrpcCallContext.createDefault().withTimeoutDuration(Duration.ofMinutes(10)); // Send a batch try (Batcher batcher = @@ -630,7 +630,7 @@ public void testCallContextPropagatedInReadBatcher() // Override the timeout GrpcCallContext clientCtx = - GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10)); + GrpcCallContext.createDefault().withTimeoutDuration(Duration.ofMinutes(10)); // Send a batch try (Batcher batcher = @@ -692,9 +692,9 @@ public void testBulkMutationFlowControlFeatureFlagIsNotSet() throws Exception { public void testWaitTimeoutIsSet() throws Exception { EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder(); // Set a shorter wait timeout and make watchdog checks more frequently - settings.readRowsSettings().setWaitTimeout(WATCHDOG_CHECK_DURATION.dividedBy(2)); + settings.readRowsSettings().setWaitTimeoutDuration(WATCHDOG_CHECK_DURATION.dividedBy(2)); settings.setStreamWatchdogProvider( - InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION)); + InstantiatingWatchdogProvider.create().withCheckIntervalDuration(WATCHDOG_CHECK_DURATION)); try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) { ServerStream results = stub.readRowsCallable().call(Query.create(WAIT_TIME_TABLE_ID)); @@ -709,9 +709,11 @@ public void testWaitTimeoutIsSet() throws Exception { public void testReadChangeStreamWaitTimeoutIsSet() throws Exception { EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder(); // Set a shorter wait timeout and make watchdog checks more frequently - settings.readChangeStreamSettings().setWaitTimeout(WATCHDOG_CHECK_DURATION.dividedBy(2)); + settings + .readChangeStreamSettings() + .setWaitTimeoutDuration(WATCHDOG_CHECK_DURATION.dividedBy(2)); settings.setStreamWatchdogProvider( - InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION)); + InstantiatingWatchdogProvider.create().withCheckIntervalDuration(WATCHDOG_CHECK_DURATION)); try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) { ServerStream results = @@ -805,9 +807,9 @@ public void testCreateExecuteQueryCallable() throws InterruptedException { public void testExecuteQueryWaitTimeoutIsSet() throws IOException { EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder(); // Set a shorter wait timeout and make watchdog checks more frequently - settings.executeQuerySettings().setWaitTimeout(WATCHDOG_CHECK_DURATION.dividedBy(2)); + settings.executeQuerySettings().setWaitTimeoutDuration(WATCHDOG_CHECK_DURATION.dividedBy(2)); settings.setStreamWatchdogProvider( - InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION)); + InstantiatingWatchdogProvider.create().withCheckIntervalDuration(WATCHDOG_CHECK_DURATION)); EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build()); Iterator iterator = @@ -821,9 +823,9 @@ public void testExecuteQueryWaitTimeoutWorksWithMetadataFuture() throws IOException, InterruptedException { EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder(); // Set a shorter wait timeout and make watchdog checks more frequently - settings.executeQuerySettings().setWaitTimeout(WATCHDOG_CHECK_DURATION.dividedBy(2)); + settings.executeQuerySettings().setWaitTimeoutDuration(WATCHDOG_CHECK_DURATION.dividedBy(2)); settings.setStreamWatchdogProvider( - InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION)); + InstantiatingWatchdogProvider.create().withCheckIntervalDuration(WATCHDOG_CHECK_DURATION)); EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build()); ApiFuture future = diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingCallableTest.java index f2fe77725d..652049b266 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingCallableTest.java @@ -36,12 +36,12 @@ import com.google.protobuf.Duration; import com.google.rpc.Code; import com.google.rpc.Status; +import java.time.Instant; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class RateLimitingCallableTest { @@ -72,7 +72,7 @@ public void testUpdateRate() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant earlier = Instant.now().minus(org.threeten.bp.Duration.ofHours(1)); + Instant earlier = Instant.now().minus(java.time.Duration.ofHours(1)); // Make sure rate will be updated. callableToTest.getNextRateUpdateTime().set(earlier); @@ -105,7 +105,7 @@ public void testNoRateLimitInfoDoesNotUpdateRate() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant earlier = Instant.now().minus(org.threeten.bp.Duration.ofHours(1)); + Instant earlier = Instant.now().minus(java.time.Duration.ofHours(1)); // Make sure rate will be updated. callableToTest.getNextRateUpdateTime().set(earlier); @@ -131,7 +131,7 @@ public void testInvalidRateLimitInfoDoesNotUpdateRate() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant earlier = Instant.now().minus(org.threeten.bp.Duration.ofHours(1)); + Instant earlier = Instant.now().minus(java.time.Duration.ofHours(1)); // make sure QPS will be updated callableToTest.getNextRateUpdateTime().set(earlier); @@ -166,7 +166,7 @@ public void testMissingRateLimitInfoFactorDoesNotUpdateRate() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant earlier = Instant.now().minus(org.threeten.bp.Duration.ofHours(1)); + Instant earlier = Instant.now().minus(java.time.Duration.ofHours(1)); // Make sure rate can be updated. callableToTest.getNextRateUpdateTime().set(earlier); @@ -199,7 +199,7 @@ public void testNoUpdateBeforeAllowedTime() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant later = Instant.now().plus(org.threeten.bp.Duration.ofHours(1)); + Instant later = Instant.now().plus(java.time.Duration.ofHours(1)); // Make sure rate will not be updated. callableToTest.getNextRateUpdateTime().set(later); double oldQps = callableToTest.getCurrentRate(); @@ -232,7 +232,7 @@ public void testDoesNotDisableBeforeAllowedTime() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setLimiterEnabled(true); - Instant later = Instant.now().plus(org.threeten.bp.Duration.ofHours(1)); + Instant later = Instant.now().plus(java.time.Duration.ofHours(1)); // Make sure limiter will not be disabled. callableToTest.getNextRateUpdateTime().set(later); double oldQps = callableToTest.getCurrentRate(); @@ -257,7 +257,7 @@ public void testEnableWithinPeriodDoesNotUpdateRate() throws Exception { callableToTest.call(request, responseObserver, context); callableToTest.setRate(1.5); - Instant later = Instant.now().plus(org.threeten.bp.Duration.ofHours(1)); + Instant later = Instant.now().plus(java.time.Duration.ofHours(1)); // Even though the rate update time is far in the future, enable is always allowed. callableToTest.getNextRateUpdateTime().set(later); double oldQps = callableToTest.getCurrentRate(); @@ -289,7 +289,7 @@ public void testEnableWithinPeriodDoesNotUpdateRate() throws Exception { public void testErrorInfoLowerQPS() throws Exception { callableToTest.call(request, responseObserver, context); - Instant earlier = Instant.now().minus(org.threeten.bp.Duration.ofHours(1)); + Instant earlier = Instant.now().minus(java.time.Duration.ofHours(1)); // make sure QPS will be updated callableToTest.getNextRateUpdateTime().set(earlier); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamRecordMergingCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamRecordMergingCallableTest.java index f0939fb0cf..c34173edea 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamRecordMergingCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamRecordMergingCallableTest.java @@ -33,13 +33,13 @@ import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; import com.google.rpc.Status; +import java.time.Instant; import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; /** * Additional tests in addition to {@link ReadChangeStreamMergingAcceptanceTest}. @@ -80,7 +80,7 @@ public void heartbeatTest() { .isEqualTo(ByteStringRange.create(rowRange.getStartKeyClosed(), rowRange.getEndKeyOpen())); assertThat(heartbeat.getChangeStreamContinuationToken().getToken()) .isEqualTo(heartbeatProto.getContinuationToken().getToken()); - assertThat(heartbeat.getEstimatedLowWatermark()) + assertThat(heartbeat.getEstimatedLowWatermarkInstant()) .isEqualTo( Instant.ofEpochSecond( heartbeatProto.getEstimatedLowWatermark().getSeconds(), diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java index 48a62bfee8..cb6d4a9432 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java @@ -51,6 +51,7 @@ import io.grpc.stub.StreamObserver; import io.grpc.testing.GrpcServerRule; import java.io.IOException; +import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.Queue; @@ -62,7 +63,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ReadChangeStreamRetryTest { @@ -392,7 +392,7 @@ public void retryRstStreamExceptionTest() { private List getResults() { ReadChangeStreamQuery query = - ReadChangeStreamQuery.create(TABLE_ID).startTime(REQUEST_START_TIME); + ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(REQUEST_START_TIME); // Always give it this partition. We don't care. ServerStream actualRecords = client.readChangeStream(query.streamPartition(START_KEY_CLOSED, END_KEY_OPEN)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java index 84f9765ea6..5eb154ca86 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java @@ -21,11 +21,11 @@ import com.google.cloud.bigtable.data.v2.models.ReadChangeStreamQuery; import com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable; import com.google.common.truth.Truth; +import java.time.Duration; +import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; -import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class ReadChangeStreamUserCallableTest { @@ -41,9 +41,9 @@ public void testRequestIsConverted() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create("fake-table") .streamPartition("begin", "end") - .startTime(Instant.ofEpochSecond(0L, 1000L)) - .endTime(Instant.ofEpochSecond(0L, 2000L)) - .heartbeatDuration(Duration.ofSeconds(1)); + .startTimeInstant(Instant.ofEpochSecond(0L, 1000L)) + .endTimeInstant(Instant.ofEpochSecond(0L, 2000L)) + .heartbeatDurationDuration(Duration.ofSeconds(1)); callable.call(query); Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.toProto(REQUEST_CONTEXT)); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracerTest.java index cb0916ad28..2bd4f8fd0e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracerTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracerTest.java @@ -29,6 +29,7 @@ import io.grpc.Status; import io.grpc.StatusRuntimeException; import java.lang.reflect.Method; +import java.time.Duration; import java.util.Arrays; import org.junit.Assert; import org.junit.Before; @@ -39,7 +40,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CompositeTracerTest { @@ -149,11 +149,11 @@ public void testAttemptCancelled() { public void testAttemptFailed() { RuntimeException error = new RuntimeException(); Duration delay = Duration.ofMillis(10); - compositeTracer.attemptFailed(error, delay); - verify(child1, times(1)).attemptFailed(error, delay); - verify(child2, times(1)).attemptFailed(error, delay); - verify(child3, times(1)).attemptFailed(error, delay); - verify(child4, times(1)).attemptFailed(error, delay); + compositeTracer.attemptFailedDuration(error, delay); + verify(child1, times(1)).attemptFailedDuration(error, delay); + verify(child2, times(1)).attemptFailedDuration(error, delay); + verify(child3, times(1)).attemptFailedDuration(error, delay); + verify(child4, times(1)).attemptFailedDuration(error, delay); } @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java index 6dd1ff9bd0..60ec5193e4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsAttemptCallableTest.java @@ -41,6 +41,7 @@ import com.google.common.collect.Lists; import com.google.protobuf.ByteString; import com.google.rpc.Status; +import java.time.Duration; import java.util.List; import java.util.Set; import java.util.concurrent.Callable; @@ -49,7 +50,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mockito; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class MutateRowsAttemptCallableTest { @@ -140,7 +140,7 @@ public void missingEntry() throws Exception { @Test public void testNoRpcTimeout() { parentFuture.timedAttemptSettings = - parentFuture.timedAttemptSettings.toBuilder().setRpcTimeout(Duration.ZERO).build(); + parentFuture.timedAttemptSettings.toBuilder().setRpcTimeoutDuration(Duration.ZERO).build(); MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build(); @@ -405,12 +405,13 @@ static class MockRetryingFuture extends AbstractApiFuture 0) { - settings.setInitialRpcTimeout(newTimeout).setMaxRpcTimeout(newTimeout); + settings.setInitialRpcTimeout(newTimeout).setMaxRpcTimeoutDuration(newTimeout); } - settings.setTotalTimeout(newTimeout); + settings.setTotalTimeoutDuration(newTimeout); } /** Helper method to get a client object by its id. */ @@ -180,7 +179,7 @@ public synchronized void createClient( .setAppProfileId(request.getAppProfileId()); if (request.hasPerOperationTimeout()) { - Duration newTimeout = Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); + java.time.Duration newTimeout = java.time.Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); settingsBuilder = overrideTimeoutSetting(newTimeout, settingsBuilder); logger.info( String.format( diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java index c138c82a6b..e2ec0307c0 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java @@ -35,7 +35,6 @@ import com.google.protobuf.ByteString; import java.util.List; import java.util.concurrent.ExecutionException; -import org.threeten.bp.Instant; public class ResultSetSerializer { public static ExecuteQueryResult toExecuteQueryResult(ResultSet resultSet) diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java index ae3b50aa7f..9fddbf05c0 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.threeten.bp.Instant; public class StatementDeserializer { From 62dd45f574c6cf151b1678060188c84826f5a461 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 14 Nov 2024 16:51:49 +0000 Subject: [PATCH 02/30] fix tests i --- .../cloud/bigtable/admin/v2/models/Backup.java | 4 +++- .../bigtable/admin/v2/models/CopyBackupRequest.java | 9 +++++++-- .../v2/models/DefaultChangeStreamRecordAdapter.java | 12 ++++++++++++ .../admin/v2/BigtableTableAdminClientTests.java | 6 +++++- .../v2/stub/EnhancedBigtableStubSettingsTest.java | 2 +- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java index b0f093c7de..5c0763eb97 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java @@ -176,7 +176,9 @@ public org.threeten.bp.Instant getExpireTime() { /** Get the expire time of this backup. */ public java.time.Instant getExpireTimeInstant() { - return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); + // return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); + return java.time.Instant.ofEpochSecond( + proto.getExpireTime().getSeconds(), proto.getExpireTime().getNanos()); } /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java index c42ec5ffa7..5f4d71c96a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java @@ -22,7 +22,7 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.google.protobuf.util.Timestamps; +import com.google.protobuf.Timestamp; import javax.annotation.Nonnull; /** Build CopyBackupRequest for {@link com.google.bigtable.admin.v2.CopyBackupRequest}. */ @@ -85,7 +85,12 @@ public CopyBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { public CopyBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); - requestBuilder.setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); + Timestamp value = + Timestamp.newBuilder() + .setSeconds(expireTime.getEpochSecond()) + .setNanos(expireTime.getNano()) + .build(); + requestBuilder.setExpireTime(value); return this; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index b8ef0a3b11..884ae606ca 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -99,6 +99,18 @@ public ChangeStreamRecord onCloseStream(ReadChangeStreamResponse.CloseStream clo return CloseStream.fromProto(closeStream); } + /** {@inheritDoc} */ + @Override + public void startUserMutationInstant( + @Nonnull ByteString rowKey, + @Nonnull String sourceClusterId, + java.time.Instant commitTimestamp, + int tieBreaker) { + this.changeStreamMutationBuilder = + ChangeStreamMutation.createUserMutation( + rowKey, sourceClusterId, commitTimestamp, tieBreaker); + } + /** {@inheritDoc} */ @Override public void startUserMutation( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index a242227647..0e9946dfb1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -1003,7 +1003,11 @@ public void testCopyBackup() { .setSourceBackup(srcBackupName) .setStartTime(startTime) .setEndTime(endTime) - .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())) + .setExpireTime( + Timestamp.newBuilder() + .setSeconds(expireTime.getEpochSecond()) + .setNanos(expireTime.getNano()) + .build()) .setSizeBytes(sizeBytes) .build(), CopyBackupMetadata.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java index d50175f525..51790a73d8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettingsTest.java @@ -184,7 +184,7 @@ private void verifySettings( assertThat(settings.getEndpoint()).isEqualTo(endpoint); assertThat(settings.getCredentialsProvider()).isEqualTo(credentialsProvider); assertThat(settings.getStreamWatchdogProvider()).isSameInstanceAs(watchdogProvider); - assertThat(settings.getStreamWatchdogCheckInterval()).isEqualTo(watchdogInterval); + assertThat(settings.getStreamWatchdogCheckIntervalDuration()).isEqualTo(watchdogInterval); assertThat(settings.getEnableRoutingCookie()).isEqualTo(enableRoutingCookie); assertThat(settings.getEnableRetryInfo()).isEqualTo(enableRetryInfo); assertThat(settings.getMetricsEndpoint()).isEqualTo(metricsEndpoint); From 959a469f8a21d94a536266b6d2c56aa8afb18602 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Thu, 14 Nov 2024 16:55:35 +0000 Subject: [PATCH 03/30] chore: generate libraries at Thu Nov 14 16:52:48 UTC 2024 --- .../java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java index f4c263a9a5..ad074feda9 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java @@ -179,7 +179,8 @@ public synchronized void createClient( .setAppProfileId(request.getAppProfileId()); if (request.hasPerOperationTimeout()) { - java.time.Duration newTimeout = java.time.Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); + java.time.Duration newTimeout = + java.time.Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); settingsBuilder = overrideTimeoutSetting(newTimeout, settingsBuilder); logger.info( String.format( From ca275dcf8ba16b11d9449b4c6301bd47f16fde25 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 14 Nov 2024 22:07:41 +0000 Subject: [PATCH 04/30] fix tests --- .../admin/v2/models/CreateBackupRequest.java | 6 +++++- .../bigtable/admin/v2/it/BigtableBackupIT.java | 16 +++++++++------- .../admin/v2/models/CopyBackupRequestTest.java | 13 +++++++++---- .../bigtable/data/v2/it/ExecuteQueryIT.java | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index d4c6f315ec..04bea94413 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -62,7 +62,11 @@ public CreateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() - .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); + .setExpireTime( + com.google.protobuf.Timestamp.newBuilder() + .setSeconds(expireTime.getEpochSecond()) + .setNanos(expireTime.getNano()) + .build()); return this; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 9a328185ac..98d3b60c4e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -159,7 +159,7 @@ public void createAndGetBackupTest() { .that(response.getSourceTableId()) .isEqualTo(testTable.getId()); assertWithMessage("Got wrong expire time in CreateBackup") - .that(response.getExpireTime()) + .that(response.getExpireTimeInstant()) .isEqualTo(expireTime); Backup result = tableAdmin.getBackup(targetCluster, backupId); @@ -170,7 +170,7 @@ public void createAndGetBackupTest() { .that(result.getSourceTableId()) .isEqualTo(testTable.getId()); assertWithMessage("Got wrong expire time in GetBackup API") - .that(result.getExpireTime()) + .that(result.getExpireTimeInstant()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in GetBackup API") .that(result.getStartTime()) @@ -208,13 +208,13 @@ public void createAndGetHotBackupTest() { .that(response.getSourceTableId()) .isEqualTo(testTableHot.getId()); assertWithMessage("Got wrong expire time in CreateBackup") - .that(response.getExpireTime()) + .that(response.getExpireTimeInstant()) .isEqualTo(expireTime); assertWithMessage("Got wrong backup type in CreateBackup") .that(response.getBackupType()) .isEqualTo(Backup.BackupType.HOT); assertWithMessage("Got wrong hot to standard time in CreateBackup") - .that(response.getHotToStandardTime()) + .that(response.getHotToStandardTimeInstant()) .isEqualTo(hotToStandardTime); Backup result = tableAdminHot.getBackup(targetClusterHot, backupId); @@ -285,7 +285,9 @@ public void updateBackupTest() { .clearHotToStandardTime(); try { Backup backup = tableAdminHot.updateBackup(req); - assertWithMessage("Incorrect expire time").that(backup.getExpireTime()).isEqualTo(expireTime); + assertWithMessage("Incorrect expire time") + .that(backup.getExpireTimeInstant()) + .isEqualTo(expireTime); assertWithMessage("Incorrect hot to standard time") .that(backup.getHotToStandardTime()) .isNull(); @@ -422,10 +424,10 @@ public void copyBackupTest() .that(result.getSourceBackupId()) .isEqualTo(backupId); assertWithMessage("Got wrong expire time in CopyBackup API") - .that(result.getExpireTime()) + .that(result.getExpireTimeInstant()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in CopyBackup API") - .that(result.getStartTime()) + .that(result.getStartTimeInstant()) .isNotNull(); assertWithMessage("Got wrong state in CopyBackup API") .that(result.getState()) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java index 27300b1a24..1245ce35bd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.protobuf.util.Timestamps; +import com.google.protobuf.Timestamp; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -37,6 +37,11 @@ public class CopyBackupRequestTest { private static final String SOURCE_INSTANCE_ID = "source-instance-id"; private static final String SOURCE_PROJECT_ID = "source-project-id"; private static final Instant EXPIRE_TIME = Instant.now().plus(Duration.ofDays(15)); + private static final Timestamp EXPIRE_TIME_PROTOBUF = + Timestamp.newBuilder() + .setSeconds(EXPIRE_TIME.getEpochSecond()) + .setNanos(EXPIRE_TIME.getNano()) + .build(); @Test public void testToProto() { @@ -51,7 +56,7 @@ public void testToProto() { .setSourceBackup( NameUtil.formatBackupName( PROJECT_ID, INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) + .setExpireTime(EXPIRE_TIME_PROTOBUF) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); @@ -71,7 +76,7 @@ public void testToProtoCrossInstance() { .setSourceBackup( NameUtil.formatBackupName( PROJECT_ID, SOURCE_INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) + .setExpireTime(EXPIRE_TIME_PROTOBUF) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); @@ -91,7 +96,7 @@ public void testToProtoCrossProject() { .setSourceBackup( NameUtil.formatBackupName( SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) + .setExpireTime(EXPIRE_TIME_PROTOBUF) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java index b105270472..9d063fa1db 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java @@ -272,8 +272,8 @@ public void allQueryParamsTypes() { assertThat(rs.getFloat(4)).isEqualTo(1.4f); assertThat(rs.getBoolean("boolCol")).isTrue(); assertThat(rs.getBoolean(5)).isTrue(); - assertThat(rs.getTimestamp("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); - assertThat(rs.getTimestamp(6)).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestampInstant("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestampInstant(6)).isEqualTo(Instant.ofEpochMilli(1000)); assertThat(rs.getDate("dateCol")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getList("byteArrayCol", SqlType.arrayOf(SqlType.bytes()))) From a7746ad4e7371a0dd000208eb4a3892992b03faf Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 14 Nov 2024 22:15:40 +0000 Subject: [PATCH 05/30] make protobuf timestamp conversion fully precise (epoch seconds + nanos) --- .../admin/v2/models/CreateBackupRequest.java | 8 +++++-- .../admin/v2/models/UpdateBackupRequest.java | 14 ++++++++--- .../v2/models/CreateBackupRequestTest.java | 13 +++++++--- .../v2/models/UpdateBackupRequestTest.java | 13 +++++++--- .../bigtable/data/v2/it/BuiltinMetricsIT.java | 24 +++++++++++++++---- 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index 04bea94413..ac421d6a7e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -22,7 +22,7 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.google.protobuf.util.Timestamps; +import com.google.protobuf.Timestamp; import javax.annotation.Nonnull; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateBackupRequest} */ @@ -91,7 +91,11 @@ public CreateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToSt Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() - .setHotToStandardTime(Timestamps.fromMillis(hotToStandardTime.toEpochMilli())); + .setHotToStandardTime( + Timestamp.newBuilder() + .setSeconds(hotToStandardTime.getEpochSecond()) + .setNanos(hotToStandardTime.getNano()) + .build()); return this; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java index 565dbac61c..38d113d1cc 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java @@ -24,8 +24,8 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; import com.google.protobuf.util.FieldMaskUtil; -import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.UpdateBackupRequest} */ @@ -62,7 +62,11 @@ public UpdateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() - .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); + .setExpireTime( + Timestamp.newBuilder() + .setSeconds(expireTime.getEpochSecond()) + .setNanos(expireTime.getNano()) + .build()); updateFieldMask(Backup.EXPIRE_TIME_FIELD_NUMBER); return this; } @@ -81,7 +85,11 @@ public UpdateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToSt Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() - .setHotToStandardTime(Timestamps.fromMillis(hotToStandardTime.toEpochMilli())); + .setHotToStandardTime( + Timestamp.newBuilder() + .setSeconds(hotToStandardTime.getEpochSecond()) + .setNanos(hotToStandardTime.getNano()) + .build()); updateFieldMask(Backup.HOT_TO_STANDARD_TIME_FIELD_NUMBER); return this; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java index 8f8b0747cf..e852ccd5d8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java @@ -20,7 +20,7 @@ import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.admin.v2.models.Backup.BackupType; -import com.google.protobuf.util.Timestamps; +import com.google.protobuf.Timestamp; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -53,10 +53,17 @@ public void testToProto() { .setBackup( Backup.newBuilder() .setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) - .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) + .setExpireTime( + Timestamp.newBuilder() + .setSeconds(EXPIRE_TIME.getEpochSecond()) + .setNanos(EXPIRE_TIME.getNano()) + .build()) .setBackupType(Backup.BackupType.HOT) .setHotToStandardTime( - Timestamps.fromMillis(HOT_TO_STANDARD_TIME.toEpochMilli())) + Timestamp.newBuilder() + .setSeconds(HOT_TO_STANDARD_TIME.getEpochSecond()) + .setNanos(HOT_TO_STANDARD_TIME.getNano()) + .build()) .build()) .setParent(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)) .build(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java index 54f3b53142..125a7913dc 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java @@ -20,7 +20,7 @@ import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; -import com.google.protobuf.util.Timestamps; +import com.google.protobuf.Timestamp; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -52,9 +52,16 @@ public void testToProto() { Backup.newBuilder() .setName( NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) - .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) + .setExpireTime( + Timestamp.newBuilder() + .setSeconds(EXPIRE_TIME.getEpochSecond()) + .setNanos(EXPIRE_TIME.getNano()) + .build()) .setHotToStandardTime( - Timestamps.fromMillis(HOT_TO_STANDARD_TIME.toEpochMilli())) + Timestamp.newBuilder() + .setSeconds(HOT_TO_STANDARD_TIME.getEpochSecond()) + .setNanos(HOT_TO_STANDARD_TIME.getNano()) + .build()) .build()) .setUpdateMask( FieldMask.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java index 41d4b6c0d3..d76d188136 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java @@ -220,8 +220,16 @@ public void testBuiltinMetricsWithDefaultOTEL() throws Exception { Instant end = Instant.now().plus(Duration.ofMinutes(3)); TimeInterval interval = TimeInterval.newBuilder() - .setStartTime(Timestamps.fromMillis(start.toEpochMilli())) - .setEndTime(Timestamps.fromMillis(end.toEpochMilli())) + .setStartTime( + Timestamp.newBuilder() + .setSeconds(start.getEpochSecond()) + .setNanos(start.getNano()) + .build()) + .setEndTime( + Timestamp.newBuilder() + .setSeconds(end.getEpochSecond()) + .setNanos(end.getNano()) + .build()) .build(); for (String view : VIEWS) { @@ -282,8 +290,16 @@ public void testBuiltinMetricsWithCustomOTEL() throws Exception { Instant end = start.plus(Duration.ofMinutes(3)); TimeInterval interval = TimeInterval.newBuilder() - .setStartTime(Timestamps.fromMillis(start.toEpochMilli())) - .setEndTime(Timestamps.fromMillis(end.toEpochMilli())) + .setStartTime( + Timestamp.newBuilder() + .setSeconds(start.getEpochSecond()) + .setNanos(start.getNano()) + .build()) + .setEndTime( + Timestamp.newBuilder() + .setSeconds(end.getEpochSecond()) + .setNanos(end.getNano()) + .build()) .build(); for (String view : VIEWS) { From d25d6ef7a791f687e0e3e391842246e09aa09d34 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 18 Nov 2024 18:28:27 +0000 Subject: [PATCH 06/30] resolve to microsecond level --- .../com/google/cloud/bigtable/admin/v2/models/Backup.java | 1 - .../cloud/bigtable/admin/v2/it/BigtableBackupIT.java | 1 + .../bigtable/admin/v2/it/BigtableTableAdminClientIT.java | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java index 5c0763eb97..b2cec2b735 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java @@ -176,7 +176,6 @@ public org.threeten.bp.Instant getExpireTime() { /** Get the expire time of this backup. */ public java.time.Instant getExpireTimeInstant() { - // return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); return java.time.Instant.ofEpochSecond( proto.getExpireTime().getSeconds(), proto.getExpireTime().getNanos()); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 98d3b60c4e..82e99dc8b7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.time.temporal.TemporalUnit; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 82965e5ba9..07dcc52ce9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -103,7 +103,7 @@ public void createTable() { assertFalse(columnFamilyById.get("cf1").hasGCRule()); assertTrue(columnFamilyById.get("cf2").hasGCRule()); assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions()); - assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetention()); + assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetentionDuration()); // Disable change stream so the table can be deleted. UpdateTableRequest updateTableRequest = @@ -124,18 +124,18 @@ public void updateTable() { .addChangeStreamRetentionDuration(Duration.ofDays(2)); Table tableResponse = tableAdmin.createTable(createTableReq); assertEquals(tableId, tableResponse.getId()); - assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetention()); + assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetentionDuration()); UpdateTableRequest updateTableRequest = UpdateTableRequest.of(tableId).addChangeStreamRetentionDuration(Duration.ofDays(4)); tableResponse = tableAdmin.updateTable(updateTableRequest); assertEquals(tableId, tableResponse.getId()); - assertEquals(Duration.ofDays(4), tableResponse.getChangeStreamRetention()); + assertEquals(Duration.ofDays(4), tableResponse.getChangeStreamRetentionDuration()); updateTableRequest = UpdateTableRequest.of(tableId).disableChangeStreamRetention(); tableResponse = tableAdmin.updateTable(updateTableRequest); assertEquals(tableId, tableResponse.getId()); - assertNull(tableResponse.getChangeStreamRetention()); + assertNull(tableResponse.getChangeStreamRetentionDuration()); } @Test From 796aa4b9e0199622636864a6b8e54102caf50f59 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 18 Nov 2024 18:30:42 +0000 Subject: [PATCH 07/30] Revert "make protobuf timestamp conversion fully precise (epoch seconds + nanos)" This reverts commit a7746ad4e7371a0dd000208eb4a3892992b03faf. --- .../admin/v2/models/CreateBackupRequest.java | 8 ++----- .../admin/v2/models/UpdateBackupRequest.java | 14 +++-------- .../v2/models/CreateBackupRequestTest.java | 13 +++------- .../v2/models/UpdateBackupRequestTest.java | 13 +++------- .../bigtable/data/v2/it/BuiltinMetricsIT.java | 24 ++++--------------- 5 files changed, 15 insertions(+), 57 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index ac421d6a7e..04bea94413 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -22,7 +22,7 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateBackupRequest} */ @@ -91,11 +91,7 @@ public CreateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToSt Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() - .setHotToStandardTime( - Timestamp.newBuilder() - .setSeconds(hotToStandardTime.getEpochSecond()) - .setNanos(hotToStandardTime.getNano()) - .build()); + .setHotToStandardTime(Timestamps.fromMillis(hotToStandardTime.toEpochMilli())); return this; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java index 38d113d1cc..565dbac61c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java @@ -24,8 +24,8 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.FieldMask; -import com.google.protobuf.Timestamp; import com.google.protobuf.util.FieldMaskUtil; +import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.UpdateBackupRequest} */ @@ -62,11 +62,7 @@ public UpdateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() - .setExpireTime( - Timestamp.newBuilder() - .setSeconds(expireTime.getEpochSecond()) - .setNanos(expireTime.getNano()) - .build()); + .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); updateFieldMask(Backup.EXPIRE_TIME_FIELD_NUMBER); return this; } @@ -85,11 +81,7 @@ public UpdateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToSt Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() - .setHotToStandardTime( - Timestamp.newBuilder() - .setSeconds(hotToStandardTime.getEpochSecond()) - .setNanos(hotToStandardTime.getNano()) - .build()); + .setHotToStandardTime(Timestamps.fromMillis(hotToStandardTime.toEpochMilli())); updateFieldMask(Backup.HOT_TO_STANDARD_TIME_FIELD_NUMBER); return this; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java index e852ccd5d8..8f8b0747cf 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java @@ -20,7 +20,7 @@ import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.admin.v2.models.Backup.BackupType; -import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -53,17 +53,10 @@ public void testToProto() { .setBackup( Backup.newBuilder() .setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) - .setExpireTime( - Timestamp.newBuilder() - .setSeconds(EXPIRE_TIME.getEpochSecond()) - .setNanos(EXPIRE_TIME.getNano()) - .build()) + .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) .setBackupType(Backup.BackupType.HOT) .setHotToStandardTime( - Timestamp.newBuilder() - .setSeconds(HOT_TO_STANDARD_TIME.getEpochSecond()) - .setNanos(HOT_TO_STANDARD_TIME.getNano()) - .build()) + Timestamps.fromMillis(HOT_TO_STANDARD_TIME.toEpochMilli())) .build()) .setParent(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)) .build(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java index 125a7913dc..54f3b53142 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java @@ -20,7 +20,7 @@ import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; -import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -52,16 +52,9 @@ public void testToProto() { Backup.newBuilder() .setName( NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)) - .setExpireTime( - Timestamp.newBuilder() - .setSeconds(EXPIRE_TIME.getEpochSecond()) - .setNanos(EXPIRE_TIME.getNano()) - .build()) + .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) .setHotToStandardTime( - Timestamp.newBuilder() - .setSeconds(HOT_TO_STANDARD_TIME.getEpochSecond()) - .setNanos(HOT_TO_STANDARD_TIME.getNano()) - .build()) + Timestamps.fromMillis(HOT_TO_STANDARD_TIME.toEpochMilli())) .build()) .setUpdateMask( FieldMask.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java index d76d188136..41d4b6c0d3 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java @@ -220,16 +220,8 @@ public void testBuiltinMetricsWithDefaultOTEL() throws Exception { Instant end = Instant.now().plus(Duration.ofMinutes(3)); TimeInterval interval = TimeInterval.newBuilder() - .setStartTime( - Timestamp.newBuilder() - .setSeconds(start.getEpochSecond()) - .setNanos(start.getNano()) - .build()) - .setEndTime( - Timestamp.newBuilder() - .setSeconds(end.getEpochSecond()) - .setNanos(end.getNano()) - .build()) + .setStartTime(Timestamps.fromMillis(start.toEpochMilli())) + .setEndTime(Timestamps.fromMillis(end.toEpochMilli())) .build(); for (String view : VIEWS) { @@ -290,16 +282,8 @@ public void testBuiltinMetricsWithCustomOTEL() throws Exception { Instant end = start.plus(Duration.ofMinutes(3)); TimeInterval interval = TimeInterval.newBuilder() - .setStartTime( - Timestamp.newBuilder() - .setSeconds(start.getEpochSecond()) - .setNanos(start.getNano()) - .build()) - .setEndTime( - Timestamp.newBuilder() - .setSeconds(end.getEpochSecond()) - .setNanos(end.getNano()) - .build()) + .setStartTime(Timestamps.fromMillis(start.toEpochMilli())) + .setEndTime(Timestamps.fromMillis(end.toEpochMilli())) .build(); for (String view : VIEWS) { From a7e6167438f1881c1be80f16d5ac4f34d3a6169e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 18 Nov 2024 19:46:06 +0000 Subject: [PATCH 08/30] restore ms precision --- .../admin/v2/models/CopyBackupRequest.java | 7 ++----- .../admin/v2/models/CreateBackupRequest.java | 6 +----- .../admin/v2/BigtableTableAdminClientTests.java | 14 ++++++++------ .../bigtable/admin/v2/it/BigtableBackupIT.java | 1 - .../admin/v2/models/CopyBackupRequestTest.java | 6 ++---- .../bigtable/testproxy/ResultSetSerializer.java | 5 +---- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java index 5f4d71c96a..4c6571040e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java @@ -23,6 +23,7 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; /** Build CopyBackupRequest for {@link com.google.bigtable.admin.v2.CopyBackupRequest}. */ @@ -85,11 +86,7 @@ public CopyBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { public CopyBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); - Timestamp value = - Timestamp.newBuilder() - .setSeconds(expireTime.getEpochSecond()) - .setNanos(expireTime.getNano()) - .build(); + Timestamp value = Timestamps.fromMillis(expireTime.toEpochMilli()); requestBuilder.setExpireTime(value); return this; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index 04bea94413..d4c6f315ec 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -62,11 +62,7 @@ public CreateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() - .setExpireTime( - com.google.protobuf.Timestamp.newBuilder() - .setSeconds(expireTime.getEpochSecond()) - .setNanos(expireTime.getNano()) - .build()); + .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); return this; } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 0e9946dfb1..c2d680c7ff 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -90,6 +90,7 @@ import com.google.protobuf.util.Timestamps; import io.grpc.Status; import io.grpc.Status.Code; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -980,7 +981,12 @@ public void testCopyBackup() { String srcTableId = "src-table"; String srcClusterId = "src-cluster"; String srcBackupId = "src-backup"; - java.time.Instant expireTime = java.time.Instant.now().plus(java.time.Duration.ofDays(15)); + + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + java.time.Instant expireTime = + java.time.Instant.now().plus(java.time.Duration.ofDays(15)).truncatedTo(ChronoUnit.MILLIS); long sizeBytes = 123456789; String dstBackupName = @@ -1003,11 +1009,7 @@ public void testCopyBackup() { .setSourceBackup(srcBackupName) .setStartTime(startTime) .setEndTime(endTime) - .setExpireTime( - Timestamp.newBuilder() - .setSeconds(expireTime.getEpochSecond()) - .setNanos(expireTime.getNano()) - .build()) + .setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())) .setSizeBytes(sizeBytes) .build(), CopyBackupMetadata.newBuilder() diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 82e99dc8b7..98d3b60c4e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -47,7 +47,6 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; -import java.time.temporal.TemporalUnit; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java index 1245ce35bd..cf8df6fd40 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java @@ -19,6 +19,7 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.Timestamp; +import com.google.protobuf.util.Timestamps; import java.time.Duration; import java.time.Instant; import org.junit.Test; @@ -38,10 +39,7 @@ public class CopyBackupRequestTest { private static final String SOURCE_PROJECT_ID = "source-project-id"; private static final Instant EXPIRE_TIME = Instant.now().plus(Duration.ofDays(15)); private static final Timestamp EXPIRE_TIME_PROTOBUF = - Timestamp.newBuilder() - .setSeconds(EXPIRE_TIME.getEpochSecond()) - .setNanos(EXPIRE_TIME.getNano()) - .build(); + Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli()); @Test public void testToProto() { diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java index e2ec0307c0..3caee99f32 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java @@ -88,10 +88,7 @@ private static Value toProtoValue(Object value, SqlType type) { case TIMESTAMP: Instant ts = (Instant) value; valueBuilder.setTimestampValue( - com.google.protobuf.Timestamp.newBuilder() - .setSeconds(ts.getEpochSecond()) - .setNanos(ts.getNano()) - .build()); + com.google.protobuf.Timestamp.newBuilder().setSeconds(ts.getEpochSeconds()).setNanos(ts.getNano()).build()) break; case DATE: Date date = (Date) value; From 00721919df6210da7f1f5acca184cc2261253b84 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 19 Nov 2024 17:55:02 +0000 Subject: [PATCH 09/30] fix precision in tests --- .../admin/v2/it/BigtableBackupIT.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 98d3b60c4e..dc5dc283ad 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -144,7 +145,10 @@ private void deleteBackupIgnoreErrors(String clusterId, String backupId) { @Test public void createAndGetBackupTest() { String backupId = prefixGenerator.newPrefix(); - Instant expireTime = Instant.now().plus(Duration.ofHours(6)); + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + Instant expireTime = Instant.now().plus(Duration.ofHours(6)).truncatedTo(ChronoUnit.MILLIS); CreateBackupRequest request = CreateBackupRequest.of(targetCluster, backupId) @@ -190,8 +194,12 @@ public void createAndGetBackupTest() { @Test public void createAndGetHotBackupTest() { String backupId = prefixGenerator.newPrefix(); - Instant expireTime = Instant.now().plus(Duration.ofHours(24)); - Instant hotToStandardTime = Instant.now().plus(Duration.ofHours(24)); + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + Instant expireTime = Instant.now().plus(Duration.ofHours(24)).truncatedTo(ChronoUnit.MILLIS); + Instant hotToStandardTime = + Instant.now().plus(Duration.ofHours(24)).truncatedTo(ChronoUnit.MILLIS); CreateBackupRequest request = CreateBackupRequest.of(targetClusterHot, backupId) @@ -278,7 +286,10 @@ public void updateBackupTest() { .setBackupType(Backup.BackupType.HOT) .setHotToStandardTimeInstant(Instant.now().plus(Duration.ofDays(10)))); - Instant expireTime = Instant.now().plus(Duration.ofDays(20)); + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + Instant expireTime = Instant.now().plus(Duration.ofDays(20)).truncatedTo(ChronoUnit.MILLIS); UpdateBackupRequest req = UpdateBackupRequest.of(targetClusterHot, backupId) .setExpireTimeInstant(expireTime) @@ -403,7 +414,10 @@ public void copyBackupTest() throws InterruptedException, IOException, ExecutionException, TimeoutException { String backupId = prefixGenerator.newPrefix(); String copiedBackupId = prefixGenerator.newPrefix(); - Instant expireTime = Instant.now().plus(Duration.ofHours(36)); + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + Instant expireTime = Instant.now().plus(Duration.ofHours(36)).truncatedTo(ChronoUnit.MILLIS); // Create the backup tableAdmin.createBackup( @@ -444,7 +458,10 @@ public void crossInstanceCopyBackupTest() throws InterruptedException, IOException, ExecutionException, TimeoutException { String backupId = prefixGenerator.newPrefix(); String copiedBackupId = prefixGenerator.newPrefix(); - Instant expireTime = Instant.now().plus(Duration.ofHours(36)); + // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches + // bigtable's millisecond precision api. + // see https://bugs.openjdk.org/browse/JDK-8242504 + Instant expireTime = Instant.now().plus(Duration.ofDays(36)).truncatedTo(ChronoUnit.MILLIS); // Create the backup tableAdmin.createBackup( From 99600a6387f5e1c83b74d4b8719dd846adb3546e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 19 Nov 2024 20:17:48 +0000 Subject: [PATCH 10/30] fix tests --- .../google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index dc5dc283ad..6e8d989375 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -233,13 +233,13 @@ public void createAndGetHotBackupTest() { .that(result.getSourceTableId()) .isEqualTo(testTableHot.getId()); assertWithMessage("Got wrong expire time in GetBackup API") - .that(result.getExpireTime()) + .that(result.getExpireTimeInstant()) .isEqualTo(expireTime); assertWithMessage("Got wrong hot to standard time in GetBackup API") - .that(result.getHotToStandardTime()) + .that(result.getHotToStandardTimeInstant()) .isEqualTo(hotToStandardTime); assertWithMessage("Got empty start time in GetBackup API") - .that(result.getStartTime()) + .that(result.getStartTimeInstant()) .isNotNull(); assertWithMessage("Got wrong size bytes in GetBackup API") .that(result.getSizeBytes()) From 3765977830d75d4014794a2f8a961d637695db90 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 19 Nov 2024 22:37:40 +0000 Subject: [PATCH 11/30] fix tests, clirr --- .../clirr-ignored-differences.xml | 6 ++++ .../data/v2/models/ChangeStreamMutation.java | 32 +++++++++---------- .../bigtable/data/v2/models/Heartbeat.java | 12 ++++--- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/google-cloud-bigtable/clirr-ignored-differences.xml b/google-cloud-bigtable/clirr-ignored-differences.xml index a3dc564c44..bbc32d1c0e 100644 --- a/google-cloud-bigtable/clirr-ignored-differences.xml +++ b/google-cloud-bigtable/clirr-ignored-differences.xml @@ -275,4 +275,10 @@ com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProvider * + + + 7012 + com/google/cloud/bigtable/data/v2/models/sql/StructReader + java.time.Instant getTimestampInstant(*) + diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java index 1afa8a2358..f0279f69c4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java @@ -115,12 +115,12 @@ static Builder createGcMutation( /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ @ObsoleteApi("Use getCommitTimestampInstant() instead") - public org.threeten.bp.Instant getCommitTimestamp() { - return toThreetenInstant(getCommitTimestampInstant()); - } + public abstract org.threeten.bp.Instant getCommitTimestamp(); /** Get the commit timestamp of the current mutation. */ - public abstract java.time.Instant getCommitTimestampInstant(); + public java.time.Instant getCommitTimestampInstant() { + return toJavaTimeInstant(getCommitTimestamp()); + } /** * Get the tie breaker of the current mutation. This is used to resolve conflicts when multiple @@ -134,12 +134,12 @@ public org.threeten.bp.Instant getCommitTimestamp() { /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ @ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") - public org.threeten.bp.Instant getEstimatedLowWatermark() { - return toThreetenInstant(getEstimatedLowWatermarkInstant()); - } + public abstract org.threeten.bp.Instant getEstimatedLowWatermark(); /** Get the low watermark of the current mutation. */ - public abstract java.time.Instant getEstimatedLowWatermarkInstant(); + public java.time.Instant getEstimatedLowWatermarkInstant() { + return toJavaTimeInstant(getEstimatedLowWatermark()); + } /** Get the list of mods of the current mutation. */ @Nonnull @@ -160,15 +160,15 @@ abstract static class Builder { abstract Builder setSourceClusterId(@Nonnull String sourceClusterId); - abstract Builder setCommitTimestampInstant(java.time.Instant commitTimestamp); + Builder setCommitTimestampInstant(java.time.Instant commitTimestamp) { + return setCommitTimestamp(toThreetenInstant(commitTimestamp)); + } /** * This method is obsolete. Use {@link #setCommitTimestampInstant(java.time.Instant)} instead. */ @ObsoleteApi("Use setCommitTimestampInstant(java.time.Instant) instead") - Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp) { - return setCommitTimestampInstant(toJavaTimeInstant(commitTimestamp)); - } + abstract Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp); abstract Builder setTieBreaker(int tieBreaker); @@ -176,16 +176,16 @@ Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp) { abstract Builder setToken(@Nonnull String token); - abstract Builder setEstimatedLowWatermarkInstant(java.time.Instant estimatedLowWatermark); + Builder setEstimatedLowWatermarkInstant(java.time.Instant estimatedLowWatermark) { + return setEstimatedLowWatermark(toThreetenInstant(estimatedLowWatermark)); + } /** * This method is obsolete. Use {@link #setEstimatedLowWatermarkInstant(java.time.Instant)} * instead. */ @ObsoleteApi("Use setEstimatedLowWatermarkInstant(java.time.Instant) instead") - Builder setEstimatedLowWatermark(org.threeten.bp.Instant estimatedLowWatermark) { - return setEstimatedLowWatermarkInstant(toJavaTimeInstant(estimatedLowWatermark)); - } + abstract Builder setEstimatedLowWatermark(org.threeten.bp.Instant estimatedLowWatermark); Builder setCell( @Nonnull String familyName, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java index 66888cce20..0cf792ee1b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Heartbeat.java @@ -15,6 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.models; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.InternalApi; @@ -33,7 +34,8 @@ public abstract class Heartbeat implements ChangeStreamRecord, Serializable { private static Heartbeat create( ChangeStreamContinuationToken changeStreamContinuationToken, java.time.Instant estimatedLowWatermark) { - return new AutoValue_Heartbeat(changeStreamContinuationToken, estimatedLowWatermark); + return new AutoValue_Heartbeat( + changeStreamContinuationToken, toThreetenInstant(estimatedLowWatermark)); } /** Wraps the protobuf {@link ReadChangeStreamResponse.Heartbeat}. */ @@ -50,10 +52,10 @@ static Heartbeat fromProto(@Nonnull ReadChangeStreamResponse.Heartbeat heartbeat /** This method is obsolete. Use {@link #getEstimatedLowWatermarkInstant()} instead. */ @ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") - public org.threeten.bp.Instant getEstimatedLowWatermark() { - return toThreetenInstant(getEstimatedLowWatermarkInstant()); - } + public abstract org.threeten.bp.Instant getEstimatedLowWatermark(); @InternalApi("Intended for use by the BigtableIO in apache/beam only.") - public abstract java.time.Instant getEstimatedLowWatermarkInstant(); + public java.time.Instant getEstimatedLowWatermarkInstant() { + return toJavaTimeInstant(getEstimatedLowWatermark()); + } } From 38b13e9750b593d3ec7aa0cb91c47866c966f564 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 20 Nov 2024 03:02:17 +0000 Subject: [PATCH 12/30] fix test proxy --- .../cloud/bigtable/data/v2/models/sql/Statement.java | 7 +++++++ test-proxy/README.md | 2 +- .../google/cloud/bigtable/testproxy/CbtTestProxy.java | 4 ++-- .../cloud/bigtable/testproxy/ResultSetSerializer.java | 3 ++- .../cloud/bigtable/testproxy/StatementDeserializer.java | 9 +++++---- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java index 117ae1ae09..bb5aa99364 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java @@ -19,6 +19,7 @@ import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ArrayValue; import com.google.bigtable.v2.ExecuteQueryRequest; import com.google.bigtable.v2.Type; @@ -29,6 +30,7 @@ import com.google.common.collect.ImmutableMap; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -164,6 +166,11 @@ public Builder setBooleanParam(String paramName, @Nullable Boolean value) { return this; } + /** + * This method is obsolete. Use {@link #setTimestampParamInstant(String, java.time.Instant)} + * instead. + */ + @ObsoleteApi("Use setTimestampParamInstant(String, java.time.Instant) instead") public Builder setTimestampParam(String paramName, @Nullable org.threeten.bp.Instant value) { return setTimestampParamInstant(paramName, toJavaTimeInstant(value)); } diff --git a/test-proxy/README.md b/test-proxy/README.md index 18778ba8c3..f87a3374ca 100644 --- a/test-proxy/README.md +++ b/test-proxy/README.md @@ -1,6 +1,6 @@ # CBT Java Test Proxy -The CBT test proxy is intended for running confromance tests for Cloug Bigtable Java Client. +The CBT test proxy is intended for running conformance tests for Cloud Bigtable Java Client. ## Set up diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java index ad074feda9..28e191c730 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java @@ -107,7 +107,7 @@ public static CbtTestProxy create() { * @param settingsBuilder The Builder object of BigtableDataSettings. * @param newTimeout The value that is used to set the timeout. */ - private static BigtableDataSettings.Builder overrideTimeoutSettingDuration( + private static BigtableDataSettings.Builder overrideTimeoutSetting( java.time.Duration newTimeout, BigtableDataSettings.Builder settingsBuilder) { updateTimeout( @@ -133,7 +133,7 @@ private static void updateTimeout(RetrySettings.Builder settings, java.time.Dura // TODO: this should happen in gax // Clamp the rpcTimeout to the overall timeout if (rpcTimeout != null && rpcTimeout.compareTo(newTimeout) > 0) { - settings.setInitialRpcTimeout(newTimeout).setMaxRpcTimeoutDuration(newTimeout); + settings.setInitialRpcTimeoutDuration(newTimeout).setMaxRpcTimeoutDuration(newTimeout); } settings.setTotalTimeoutDuration(newTimeout); diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java index 3caee99f32..e6803577b2 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java @@ -33,6 +33,7 @@ import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.cloud.bigtable.data.v2.models.sql.StructReader; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.List; import java.util.concurrent.ExecutionException; @@ -88,7 +89,7 @@ private static Value toProtoValue(Object value, SqlType type) { case TIMESTAMP: Instant ts = (Instant) value; valueBuilder.setTimestampValue( - com.google.protobuf.Timestamp.newBuilder().setSeconds(ts.getEpochSeconds()).setNanos(ts.getNano()).build()) + com.google.protobuf.Timestamp.newBuilder().setSeconds(ts.getEpochSecond()).setNanos(ts.getNano()).build()); break; case DATE: Date date = (Date) value; diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java index 9fddbf05c0..deb58682d2 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java @@ -21,6 +21,7 @@ import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.cloud.bigtable.data.v2.models.sql.Statement; import com.google.protobuf.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -89,10 +90,10 @@ static Statement toStatement(ExecuteQueryRequest request) { break; case TIMESTAMP_TYPE: if (value.getKindCase().equals(KindCase.KIND_NOT_SET)) { - statementBuilder.setTimestampParam(name, null); + statementBuilder.setTimestampParamInstant(name, null); } else if (value.getKindCase().equals(KindCase.TIMESTAMP_VALUE)) { Timestamp ts = value.getTimestampValue(); - statementBuilder.setTimestampParam(name, toInstant(ts)); + statementBuilder.setTimestampParamInstant(name, toInstant(ts)); } else { throw new IllegalArgumentException("Malformed timestamp value: " + value); } @@ -156,8 +157,8 @@ static Object decodeArrayElement(Value value, SqlType elemType) { } } - private static Instant toInstant(Timestamp timestamp) { - return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); + private static java.time.Instant toInstant(Timestamp timestamp) { + return java.time.Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); } private static Date fromProto(com.google.type.Date proto) { From f6efe6bc77cf909424061ca6fe9cce214c119f5c Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 20 Nov 2024 03:02:45 +0000 Subject: [PATCH 13/30] format --- .../google/cloud/bigtable/testproxy/ResultSetSerializer.java | 5 ++++- .../cloud/bigtable/testproxy/StatementDeserializer.java | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java index e6803577b2..7400986b6e 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/ResultSetSerializer.java @@ -89,7 +89,10 @@ private static Value toProtoValue(Object value, SqlType type) { case TIMESTAMP: Instant ts = (Instant) value; valueBuilder.setTimestampValue( - com.google.protobuf.Timestamp.newBuilder().setSeconds(ts.getEpochSecond()).setNanos(ts.getNano()).build()); + com.google.protobuf.Timestamp.newBuilder() + .setSeconds(ts.getEpochSecond()) + .setNanos(ts.getNano()) + .build()); break; case DATE: Date date = (Date) value; diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java index deb58682d2..b887f75043 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java @@ -21,7 +21,6 @@ import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.cloud.bigtable.data.v2.models.sql.Statement; import com.google.protobuf.Timestamp; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; From 41bc6eabd2ce924e1773f8b03bda222aa5b6941a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 20 Nov 2024 19:43:46 +0000 Subject: [PATCH 14/30] format ii --- .../com/google/cloud/bigtable/data/v2/models/sql/Statement.java | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java index bb5aa99364..78986c5c6a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java @@ -30,7 +30,6 @@ import com.google.common.collect.ImmutableMap; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; -import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; From e06a104bcc673abc312a977cdbf0525717a18f82 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 21 Nov 2024 20:55:57 -0500 Subject: [PATCH 15/30] fix ITs --- .../cloud/bigtable/admin/v2/it/BigtableBackupIT.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 6e8d989375..76aa7ba438 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -461,7 +461,7 @@ public void crossInstanceCopyBackupTest() // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches // bigtable's millisecond precision api. // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofDays(36)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofHours(36)).truncatedTo(ChronoUnit.MILLIS); // Create the backup tableAdmin.createBackup( @@ -496,15 +496,16 @@ public void crossInstanceCopyBackupTest() .that(result.getSourceBackupId()) .isEqualTo(backupId); assertWithMessage("Got wrong expire time in CopyBackup API") - .that(result.getExpireTime()) + .that(result.getExpireTimeInstant()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in CopyBackup API") - .that(result.getStartTime()) + .that(result.getStartTimeInstant()) .isNotNull(); assertWithMessage("Got wrong state in CopyBackup API") - .that(result.getState()) + .that(result.getState(t sta)) .isAnyOf(Backup.State.CREATING, Backup.State.READY); - + } catch (Exception ex) { + System.out.println(ex); } finally { deleteBackupIgnoreErrors(destTableAdmin, destCluster, copiedBackupId); deleteBackupIgnoreErrors(targetCluster, backupId); From fc920b0be7aa9fa1cc4415b500348500c1af13ac Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 21 Nov 2024 21:12:18 -0500 Subject: [PATCH 16/30] fix it, timestamp precision --- .../com/google/cloud/bigtable/admin/v2/models/Backup.java | 5 ++--- .../google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java index b2cec2b735..e308175d83 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java @@ -174,10 +174,9 @@ public org.threeten.bp.Instant getExpireTime() { return toThreetenInstant(getExpireTimeInstant()); } - /** Get the expire time of this backup. */ + /** Gets the expiry time of this backup. */ public java.time.Instant getExpireTimeInstant() { - return java.time.Instant.ofEpochSecond( - proto.getExpireTime().getSeconds(), proto.getExpireTime().getNanos()); + return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); } /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 76aa7ba438..7f47bef58a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -502,7 +502,7 @@ public void crossInstanceCopyBackupTest() .that(result.getStartTimeInstant()) .isNotNull(); assertWithMessage("Got wrong state in CopyBackup API") - .that(result.getState(t sta)) + .that(result.getState()) .isAnyOf(Backup.State.CREATING, Backup.State.READY); } catch (Exception ex) { System.out.println(ex); From de505d25f2c9fa478a1c6bf528fe6edeeae90488 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Mon, 25 Nov 2024 15:00:17 -0500 Subject: [PATCH 17/30] solve review comments --- .../v2/internal/AbstractProtoStructReader.java | 2 ++ .../bigtable/data/v2/internal/ResultSetImpl.java | 2 ++ .../models/DefaultChangeStreamRecordAdapter.java | 4 ++++ .../data/v2/models/ReadChangeStreamQuery.java | 8 ++++---- .../gaxx/retrying/RetryInfoRetryAlgorithm.java | 2 +- .../data/v2/models/ReadChangeStreamQueryTest.java | 14 +++++++------- .../ReadChangeStreamUserCallableTest.java | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java index f6e611c878..e7bdcd52eb 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java @@ -167,6 +167,7 @@ public boolean getBoolean(String columnName) { return value.getBoolValue(); } + /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead */ @Override @ObsoleteApi("Use getTimestampInstant(int) instead") public org.threeten.bp.Instant getTimestamp(int columnIndex) { @@ -180,6 +181,7 @@ public java.time.Instant getTimestampInstant(int columnIndex) { return toInstant(value.getTimestampValue()); } + /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead */ @Override @ObsoleteApi("Use getTimestampInstant(String) instead") public org.threeten.bp.Instant getTimestamp(String columnName) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java index 5dd242d64b..12db850abf 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java @@ -168,6 +168,7 @@ public boolean getBoolean(String columnName) { return getCurrentRow().getBoolean(columnName); } + /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead. */ @Override @ObsoleteApi("Use getTimestampInstant(int) instead") public org.threeten.bp.Instant getTimestamp(int columnIndex) { @@ -179,6 +180,7 @@ public java.time.Instant getTimestampInstant(int columnIndex) { return getCurrentRow().getTimestampInstant(columnIndex); } + /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead. */ @Override @ObsoleteApi("Use getTimestampInstant(String) instead") public org.threeten.bp.Instant getTimestamp(String columnName) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index 884ae606ca..a800a53ec7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -18,6 +18,7 @@ import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.common.base.Preconditions; @@ -113,6 +114,7 @@ public void startUserMutationInstant( /** {@inheritDoc} */ @Override + @ObsoleteApi("Use startUserMutationInstant(ByteString, String, java.time.Instant, int) instead") public void startUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, @@ -124,6 +126,7 @@ public void startUserMutation( /** {@inheritDoc} */ @Override + @ObsoleteApi("Use startUserMutationInstant(ByteString, java.time.Instant, int) instead") public void startGcMutation( @Nonnull ByteString rowKey, org.threeten.bp.Instant commitTimestamp, int tieBreaker) { startGcMutationInstant(rowKey, toJavaTimeInstant(commitTimestamp), tieBreaker); @@ -194,6 +197,7 @@ public void finishCell() { /** {@inheritDoc} */ @Override + @ObsoleteApi("Use finishChangeStreamMutationInstant(String, java.time.Instant) instead") public ChangeStreamRecord finishChangeStreamMutation( @Nonnull String token, org.threeten.bp.Instant estimatedLowWatermark) { return finishChangeStreamMutationInstant(token, toJavaTimeInstant(estimatedLowWatermark)); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java index e6ae9e526f..7dd76236d2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java @@ -197,15 +197,15 @@ public ReadChangeStreamQuery continuationTokens( } /** - * This method is obsolete. Use {@link #heartbeatDurationDuration(java.time.Duration)} instead. + * This method is obsolete. Use {@link #heartbeatDurationJavaTime(java.time.Duration)} instead. */ - @ObsoleteApi("Use heartbeatDurationDuration(java.time.Duration) instead") + @ObsoleteApi("Use heartbeatDurationJavaTime(java.time.Duration) instead") public ReadChangeStreamQuery heartbeatDuration(org.threeten.bp.Duration duration) { - return heartbeatDurationDuration(toJavaTimeDuration(duration)); + return heartbeatDurationJavaTime(toJavaTimeDuration(duration)); } /** Sets the heartbeat duration for the change stream. */ - public ReadChangeStreamQuery heartbeatDurationDuration(java.time.Duration duration) { + public ReadChangeStreamQuery heartbeatDurationJavaTime(java.time.Duration duration) { builder.setHeartbeatDuration( Duration.newBuilder() .setSeconds(duration.getSeconds()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java index dd131f2498..98e549cee1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/retrying/RetryInfoRetryAlgorithm.java @@ -22,7 +22,7 @@ import com.google.api.gax.rpc.ApiException; import com.google.protobuf.util.Durations; import com.google.rpc.RetryInfo; -import org.checkerframework.checker.nullness.qual.Nullable; +import javax.annotation.Nullable; // TODO move this algorithm to gax /** diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java index a7d6347488..a214d887e8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java @@ -155,7 +155,7 @@ public void endTimeTest() { public void heartbeatDurationTest() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); Builder expectedProto = expectedProtoBuilder().setHeartbeatDuration(Duration.newBuilder().setSeconds(5).build()); @@ -234,7 +234,7 @@ public void serializationTest() throws IOException, ClassNotFoundException { .streamPartition("simple-begin", "simple-end") .continuationTokens(Collections.singletonList(token)) .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); @@ -304,7 +304,7 @@ public void testEquality() { .streamPartition("simple-begin", "simple-end") .startTimeInstant(FAKE_START_TIME) .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); // ReadChangeStreamQuery#toProto should not change the ReadChangeStreamQuery instance state request.toProto(requestContext); @@ -314,7 +314,7 @@ public void testEquality() { .streamPartition("simple-begin", "simple-end") .startTimeInstant(FAKE_START_TIME) .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5))); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5))); assertThat(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-1", "end-1")) .isNotEqualTo(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-2", "end-1")); @@ -328,10 +328,10 @@ public void testEquality() { .endTimeInstant(Instant.ofEpochSecond(1L, 1001L))); assertThat( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5))) + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5))) .isNotEqualTo( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(6))); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(6))); } @Test @@ -354,7 +354,7 @@ public void testClone() { .streamPartition("begin", "end") .continuationTokens(Collections.singletonList(token)) .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationDuration(java.time.Duration.ofSeconds(5)); + .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); ReadChangeStreamRequest request = ReadChangeStreamRequest.newBuilder() .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java index 5eb154ca86..a27e948e5c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java @@ -43,7 +43,7 @@ public void testRequestIsConverted() { .streamPartition("begin", "end") .startTimeInstant(Instant.ofEpochSecond(0L, 1000L)) .endTimeInstant(Instant.ofEpochSecond(0L, 2000L)) - .heartbeatDurationDuration(Duration.ofSeconds(1)); + .heartbeatDurationJavaTime(Duration.ofSeconds(1)); callable.call(query); Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.toProto(REQUEST_CONTEXT)); } From dc19a8616d2c1339f0ba9f47b0f0cea52a09115d Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 14:44:03 -0500 Subject: [PATCH 18/30] treat tracer classes as internal --- .../v2/stub/metrics/BuiltinMetricsTracer.java | 15 ++------------- .../data/v2/stub/metrics/CompositeTracer.java | 12 ------------ .../data/v2/stub/metrics/MetricsTracer.java | 12 ------------ 3 files changed, 2 insertions(+), 37 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java index 2993622505..d2cd501de0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java @@ -16,7 +16,6 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.api.gax.tracing.ApiTracerFactory.OperationType; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METHOD_KEY; @@ -25,7 +24,6 @@ import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.TABLE_ID_KEY; import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ZONE_ID_KEY; -import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.SpanName; import com.google.cloud.bigtable.Version; @@ -35,6 +33,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.LongCounter; +import java.time.Duration; import java.util.concurrent.CancellationException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -201,18 +200,8 @@ public void attemptCancelled() { recordAttemptCompletion(new CancellationException()); } - /** - * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") @Override - public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailedDuration(error, toJavaTimeDuration(delay)); - } - - @Override - public void attemptFailedDuration(Throwable error, java.time.Duration delay) { + public void attemptFailedDuration(Throwable error, Duration delay) { recordAttemptCompletion(error); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java index cb846f19b7..bb37235abe 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java @@ -15,9 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import com.google.api.core.ObsoleteApi; import com.google.api.gax.tracing.ApiTracer; import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -126,16 +124,6 @@ public void attemptCancelled() { } } - /** - * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") - @Override - public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { - attemptFailedDuration(error, toJavaTimeDuration(delay)); - } - @Override public void attemptFailedDuration(Throwable error, java.time.Duration delay) { for (ApiTracer child : children) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java index dda7707af7..d24976969a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java @@ -15,9 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; import com.google.api.gax.tracing.SpanName; @@ -154,16 +152,6 @@ public void attemptCancelled() { recordAttemptCompletion(new CancellationException()); } - /** - * This method is obsolete. Use {@link #attemptFailedDuration(Throwable, java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead") - @Override - public void attemptFailed(Throwable throwable, org.threeten.bp.Duration duration) { - attemptFailedDuration(throwable, toJavaTimeDuration(duration)); - } - @Override public void attemptFailedDuration(Throwable throwable, java.time.Duration duration) { recordAttemptCompletion(throwable); From 5b6d8af1b0ffd1779935d9fc0de2479711966e50 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 14:50:24 -0500 Subject: [PATCH 19/30] reset admin changes no changes in admin, everything is reset to the latest of main --- .../bigtable/admin/v2/models/Backup.java | 47 ++++--------------- .../admin/v2/models/CopyBackupRequest.java | 16 ++----- .../admin/v2/models/CreateBackupRequest.java | 22 ++------- .../admin/v2/models/CreateTableRequest.java | 18 ++----- .../bigtable/admin/v2/models/GCRules.java | 32 ++++--------- .../cloud/bigtable/admin/v2/models/Table.java | 20 +++----- .../admin/v2/models/UpdateBackupRequest.java | 21 ++------- .../admin/v2/models/UpdateTableRequest.java | 17 ++----- 8 files changed, 39 insertions(+), 154 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java index e308175d83..1c340910a0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Backup.java @@ -16,10 +16,7 @@ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.BackupName; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; @@ -27,6 +24,7 @@ import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.threeten.bp.Instant; /** * A backup lets you save a copy of a table's schema and data and restore the backup to a new table @@ -168,41 +166,23 @@ public String getInstanceId() { return instanceId; } - /** This method is obsolete. Use {@link #getExpireTimeInstant()} instead. */ - @ObsoleteApi("Use getExpireTimeInstant() instead") - public org.threeten.bp.Instant getExpireTime() { - return toThreetenInstant(getExpireTimeInstant()); - } - - /** Gets the expiry time of this backup. */ - public java.time.Instant getExpireTimeInstant() { - return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); - } - - /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ - @ObsoleteApi("Use getStartTimeInstant() instead") - public @Nullable org.threeten.bp.Instant getStartTime() { - return toThreetenInstant(getStartTimeInstant()); + /** Get the expire time of this backup. */ + public Instant getExpireTime() { + return Instant.ofEpochMilli(Timestamps.toMillis(proto.getExpireTime())); } /** Get the start time when this backup is taken. */ - public @Nullable java.time.Instant getStartTimeInstant() { + public @Nullable Instant getStartTime() { if (proto.hasStartTime()) { - return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime())); + return Instant.ofEpochMilli(Timestamps.toMillis(proto.getStartTime())); } return null; } - /** This method is obsolete. Use {@link #getStartTimeInstant()} instead. */ - @ObsoleteApi("Use getStartTimeInstant() instead") - public @Nullable org.threeten.bp.Instant getEndTime() { - return toThreetenInstant(getEndTimeInstant()); - } - /** Get the end time when the creation of this backup has completed. */ - public @Nullable java.time.Instant getEndTimeInstant() { + public @Nullable Instant getEndTime() { if (proto.hasEndTime()) { - return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime())); + return Instant.ofEpochMilli(Timestamps.toMillis(proto.getEndTime())); } return null; } @@ -222,18 +202,11 @@ public BackupType getBackupType() { return BackupType.fromProto(proto.getBackupType()); } - /** This method is obsolete. Use {@link #getHotToStandardTimeInstant()} instead. */ - @ObsoleteApi("Use getHotToStandardTimeInstant() instead.") - @Nullable - public org.threeten.bp.Instant getHotToStandardTime() { - return toThreetenInstant(getHotToStandardTimeInstant()); - } - /** Get the time at which this backup will be converted from a hot backup to a standard backup. */ @Nullable - public java.time.Instant getHotToStandardTimeInstant() { + public Instant getHotToStandardTime() { if (proto.hasHotToStandardTime()) { - return java.time.Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime())); + return Instant.ofEpochMilli(Timestamps.toMillis(proto.getHotToStandardTime())); } return null; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java index 4c6571040e..88b50376be 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequest.java @@ -15,16 +15,13 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.google.protobuf.Timestamp; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; +import org.threeten.bp.Instant; /** Build CopyBackupRequest for {@link com.google.bigtable.admin.v2.CopyBackupRequest}. */ public final class CopyBackupRequest { @@ -78,16 +75,9 @@ public CopyBackupRequest setDestination(String clusterId, String backupId) { return this; } - /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ - @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") - public CopyBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { - return setExpireTimeInstant(toJavaTimeInstant(expireTime)); - } - - public CopyBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { + public CopyBackupRequest setExpireTime(Instant expireTime) { Preconditions.checkNotNull(expireTime); - Timestamp value = Timestamps.fromMillis(expireTime.toEpochMilli()); - requestBuilder.setExpireTime(value); + requestBuilder.setExpireTime(Timestamps.fromMillis(expireTime.toEpochMilli())); return this; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java index d4c6f315ec..542ba8da20 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequest.java @@ -15,15 +15,13 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; +import org.threeten.bp.Instant; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateBackupRequest} */ public final class CreateBackupRequest { @@ -52,13 +50,7 @@ public CreateBackupRequest setSourceTableId(String sourceTableId) { return this; } - /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ - @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") - public CreateBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { - return setExpireTimeInstant(toJavaTimeInstant(expireTime)); - } - - public CreateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { + public CreateBackupRequest setExpireTime(Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() @@ -72,18 +64,10 @@ public CreateBackupRequest setBackupType(Backup.BackupType backupType) { return this; } - /** - * This method is obsolete. Use {@link #setHotToStandardTimeInstant(java.time.Instant)} instead. - */ - @ObsoleteApi("Use setHotToStandardTimeInstant(java.time.Instant) instead.") - public CreateBackupRequest setHotToStandardTime(org.threeten.bp.Instant hotToStandardTime) { - return setHotToStandardTimeInstant(toJavaTimeInstant(hotToStandardTime)); - } - // The time at which this backup will be converted from a hot backup to a standard backup. Only // applicable for hot backups. If not set, the backup will remain as a hot backup until it is // deleted. - public CreateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToStandardTime) { + public CreateBackupRequest setHotToStandardTime(Instant hotToStandardTime) { Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java index 0cad0a9974..c7a0580fde 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequest.java @@ -15,10 +15,7 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.ChangeStreamConfig; import com.google.bigtable.admin.v2.ColumnFamily; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; @@ -26,8 +23,8 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; -import com.google.protobuf.Duration; import javax.annotation.Nonnull; +import org.threeten.bp.Duration; /** * Fluent wrapper for {@link com.google.bigtable.admin.v2.CreateTableRequest} @@ -110,24 +107,15 @@ public CreateTableRequest addSplit(ByteString key) { return this; } - /** - * This method is obsolete. Use {@link #addChangeStreamRetentionDuration(java.time.Duration)} - * instead. - */ - @ObsoleteApi("Use addChangeStreamRetentionDuration(java.time.Duration) instead.") - public CreateTableRequest addChangeStreamRetention(org.threeten.bp.Duration retention) { - return addChangeStreamRetentionDuration(toJavaTimeDuration(retention)); - } - /** Add change stream retention period between 1 day and 7 days */ - public CreateTableRequest addChangeStreamRetentionDuration(java.time.Duration retention) { + public CreateTableRequest addChangeStreamRetention(Duration retention) { Preconditions.checkNotNull(retention); requestBuilder .getTableBuilder() .setChangeStreamConfig( ChangeStreamConfig.newBuilder() .setRetentionPeriod( - Duration.newBuilder() + com.google.protobuf.Duration.newBuilder() .setSeconds(retention.getSeconds()) .setNanos(retention.getNano()) .build()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java index 6971967f0a..35f48c5260 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/GCRules.java @@ -15,12 +15,8 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.GcRule; import com.google.bigtable.admin.v2.GcRule.Intersection; import com.google.bigtable.admin.v2.GcRule.Union; @@ -30,6 +26,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; +import org.threeten.bp.Duration; // TODO(igorbernstein2): the distinction between GcRule & GCRule is too subtle, use fully qualified // names for the protos. @@ -73,21 +70,15 @@ public VersionRule maxVersions(int maxVersion) { * @param timeUnit - timeunit for the age */ public DurationRule maxAge(long maxAge, TimeUnit timeUnit) { - return maxAgeDuration( - java.time.Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit))); + return maxAge(Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit))); } - /** This method is obsolete. Use {@link #maxAgeDuration(java.time.Duration)} instead. */ - @ObsoleteApi("Use maxAgeDuration(java.time.Duration) instead.") - public DurationRule maxAge(org.threeten.bp.Duration duration) { - return maxAgeDuration(toJavaTimeDuration(duration)); - } /** * Creates a new instance of the DurationRule * * @param duration - age expressed as duration */ - public DurationRule maxAgeDuration(java.time.Duration duration) { + public DurationRule maxAge(Duration duration) { return new DurationRule(duration); } @@ -100,9 +91,8 @@ public DefaultRule defaultRule() { public GCRule fromProto(GcRule source) { switch (source.getRuleCase()) { case MAX_AGE: - return GCRULES.maxAgeDuration( - java.time.Duration.ofSeconds( - source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); + return GCRULES.maxAge( + Duration.ofSeconds(source.getMaxAge().getSeconds(), source.getMaxAge().getNanos())); case MAX_NUM_VERSIONS: return GCRULES.maxVersions(source.getMaxNumVersions()); @@ -297,22 +287,16 @@ public GcRule toProto() { public static final class DurationRule implements GCRule { private final com.google.protobuf.Duration.Builder builder; - private DurationRule(java.time.Duration duration) { + private DurationRule(Duration duration) { this.builder = com.google.protobuf.Duration.newBuilder() .setSeconds(duration.getSeconds()) .setNanos(duration.getNano()); } - /** This method is obsolete. Use {@link #getMaxAgeDuration()} instead. */ - @ObsoleteApi("Use getMaxAgeDuration() instead.") - public org.threeten.bp.Duration getMaxAge() { - return toThreetenDuration(getMaxAgeDuration()); - } - /** Gets the configured maximum age */ - public java.time.Duration getMaxAgeDuration() { - return java.time.Duration.ofSeconds(builder.getSeconds(), builder.getNanos()); + public Duration getMaxAge() { + return Duration.ofSeconds(builder.getSeconds(), builder.getNanos()); } @Override diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java index 3fc8b9ebc6..979e01cb8c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java @@ -15,10 +15,7 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.TableName; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -28,6 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import javax.annotation.Nonnull; +import org.threeten.bp.Duration; /** Wrapper for {@link Table} protocol buffer object */ public final class Table { @@ -106,7 +104,7 @@ public com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState toProto( private final Map replicationStatesByClusterId; private final List columnFamilies; - private final java.time.Duration changeStreamRetention; + private final Duration changeStreamRetention; private final boolean deletionProtection; @InternalApi @@ -126,10 +124,10 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto) columnFamilies.add(ColumnFamily.fromProto(entry.getKey(), entry.getValue())); } - java.time.Duration changeStreamConfig = null; + Duration changeStreamConfig = null; if (proto.hasChangeStreamConfig()) { changeStreamConfig = - java.time.Duration.ofSeconds( + Duration.ofSeconds( proto.getChangeStreamConfig().getRetentionPeriod().getSeconds(), proto.getChangeStreamConfig().getRetentionPeriod().getNanos()); } @@ -146,7 +144,7 @@ private Table( TableName tableName, Map replicationStatesByClusterId, List columnFamilies, - java.time.Duration changeStreamRetention, + Duration changeStreamRetention, boolean deletionProtection) { this.instanceId = tableName.getInstance(); this.id = tableName.getTable(); @@ -174,13 +172,7 @@ public List getColumnFamilies() { return columnFamilies; } - /** This method is obsolete. Use {@link #getChangeStreamRetentionDuration()} instead. */ - @ObsoleteApi("Use getChangeStreamRetention() instead.") - public org.threeten.bp.Duration getChangeStreamRetention() { - return toThreetenDuration(getChangeStreamRetentionDuration()); - } - - public java.time.Duration getChangeStreamRetentionDuration() { + public Duration getChangeStreamRetention() { return changeStreamRetention; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java index 565dbac61c..9bf9076b0c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequest.java @@ -15,10 +15,7 @@ */ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.Backup; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Objects; @@ -27,6 +24,7 @@ import com.google.protobuf.util.FieldMaskUtil; import com.google.protobuf.util.Timestamps; import javax.annotation.Nonnull; +import org.threeten.bp.Instant; /** Fluent wrapper for {@link com.google.bigtable.admin.v2.UpdateBackupRequest} */ public final class UpdateBackupRequest { @@ -52,13 +50,7 @@ private void updateFieldMask(int fieldNumber) { requestBuilder.setUpdateMask(FieldMaskUtil.union(requestBuilder.getUpdateMask(), newMask)); } - /** This method is obsolete. Use {@link #setExpireTimeInstant(java.time.Instant)} instead. */ - @ObsoleteApi("Use setExpireTimeInstant(java.time.Instant) instead.") - public UpdateBackupRequest setExpireTime(org.threeten.bp.Instant expireTime) { - return setExpireTimeInstant(toJavaTimeInstant(expireTime)); - } - - public UpdateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { + public UpdateBackupRequest setExpireTime(Instant expireTime) { Preconditions.checkNotNull(expireTime); requestBuilder .getBackupBuilder() @@ -66,18 +58,11 @@ public UpdateBackupRequest setExpireTimeInstant(java.time.Instant expireTime) { updateFieldMask(Backup.EXPIRE_TIME_FIELD_NUMBER); return this; } - /** - * This method is obsolete. Use {@link #setHotToStandardTimeInstant(java.time.Instant)} instead. - */ - @ObsoleteApi("Use setHotToStandardTimeInstant(java.time.Instant) instead.") - public UpdateBackupRequest setHotToStandardTime(org.threeten.bp.Instant hotToStandardTime) { - return setHotToStandardTimeInstant(toJavaTimeInstant(hotToStandardTime)); - } // The time at which this backup will be converted from a hot backup to a standard backup. Only // applicable for hot backups. If not set, the backup will remain as a hot backup until it is // deleted. - public UpdateBackupRequest setHotToStandardTimeInstant(java.time.Instant hotToStandardTime) { + public UpdateBackupRequest setHotToStandardTime(Instant hotToStandardTime) { Preconditions.checkNotNull(hotToStandardTime); requestBuilder .getBackupBuilder() diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java index fc696a1828..4e78051864 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequest.java @@ -16,14 +16,12 @@ package com.google.cloud.bigtable.admin.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.admin.v2.ChangeStreamConfig; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.common.base.Preconditions; import java.util.Objects; +import org.threeten.bp.Duration; /** * Wrapper for {@link com.google.bigtable.admin.v2.UpdateTableRequest} @@ -49,17 +47,8 @@ private UpdateTableRequest(String tableId) { this.tableId = tableId; } - /** - * This method is obsolete. Use {@link #addChangeStreamRetentionDuration(java.time.Duration - * retention)} instead. - */ - @ObsoleteApi("Use addChangeStreamRetentionDuration(java.time.Duration) instead.") - public UpdateTableRequest addChangeStreamRetention(org.threeten.bp.Duration retention) { - return addChangeStreamRetentionDuration(toJavaTimeDuration(retention)); - } - /** Update change stream retention period between 1 day and 7 days. */ - public UpdateTableRequest addChangeStreamRetentionDuration(java.time.Duration retention) { + public UpdateTableRequest addChangeStreamRetention(Duration retention) { Preconditions.checkNotNull(retention); if (!retention.isZero()) { requestBuilder @@ -82,7 +71,7 @@ public UpdateTableRequest addChangeStreamRetentionDuration(java.time.Duration re /** Disable change stream for table */ public UpdateTableRequest disableChangeStreamRetention() { - return addChangeStreamRetentionDuration(java.time.Duration.ZERO); + return addChangeStreamRetention(Duration.ZERO); } /** Changes the deletion protection of an existing table. */ From efe806b20d7b736d0178f2606705b228cc2fe487 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 15:02:14 -0500 Subject: [PATCH 20/30] update sql files (internal) --- .../internal/AbstractProtoStructReader.java | 25 ++++--------------- .../data/v2/internal/ResultSetImpl.java | 25 ++++--------------- .../bigtable/data/v2/models/sql/SqlType.java | 3 ++- .../data/v2/models/sql/Statement.java | 19 ++++---------- .../data/v2/models/sql/StructReader.java | 24 ++++-------------- 5 files changed, 22 insertions(+), 74 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java index e7bdcd52eb..a8992ee85d 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java @@ -15,10 +15,8 @@ */ package com.google.cloud.bigtable.data.v2.internal; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.Value; import com.google.bigtable.v2.Value.KindCase; import com.google.cloud.Date; @@ -28,6 +26,7 @@ import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -167,29 +166,15 @@ public boolean getBoolean(String columnName) { return value.getBoolValue(); } - /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead */ @Override - @ObsoleteApi("Use getTimestampInstant(int) instead") - public org.threeten.bp.Instant getTimestamp(int columnIndex) { - return toThreetenInstant(getTimestampInstant(columnIndex)); - } - - @Override - public java.time.Instant getTimestampInstant(int columnIndex) { + public Instant getTimestamp(int columnIndex) { checkNonNullOfType(columnIndex, SqlType.timestamp(), columnIndex); Value value = values().get(columnIndex); return toInstant(value.getTimestampValue()); } - /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead */ - @Override - @ObsoleteApi("Use getTimestampInstant(String) instead") - public org.threeten.bp.Instant getTimestamp(String columnName) { - return toThreetenInstant(getTimestampInstant(columnName)); - } - @Override - public java.time.Instant getTimestampInstant(String columnName) { + public Instant getTimestamp(String columnName) { int columnIndex = getColumnIndex(columnName); checkNonNullOfType(columnIndex, SqlType.timestamp(), columnName); Value value = values().get(columnIndex); @@ -345,8 +330,8 @@ private void checkNonNullOfType( } } - private java.time.Instant toInstant(Timestamp timestamp) { - return java.time.Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); + private Instant toInstant(Timestamp timestamp) { + return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); } private Date fromProto(com.google.type.Date proto) { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java index 12db850abf..d9a97110c6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java @@ -15,11 +15,9 @@ */ package com.google.cloud.bigtable.data.v2.internal; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.api.gax.rpc.ApiExceptions; import com.google.api.gax.rpc.ServerStream; import com.google.cloud.Date; @@ -31,6 +29,7 @@ import com.google.cloud.bigtable.data.v2.stub.sql.SqlServerStream; import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -168,28 +167,14 @@ public boolean getBoolean(String columnName) { return getCurrentRow().getBoolean(columnName); } - /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead. */ @Override - @ObsoleteApi("Use getTimestampInstant(int) instead") - public org.threeten.bp.Instant getTimestamp(int columnIndex) { - return toThreetenInstant(getTimestampInstant(columnIndex)); + public Instant getTimestamp(int columnIndex) { + return getCurrentRow().getTimestamp(columnIndex); } @Override - public java.time.Instant getTimestampInstant(int columnIndex) { - return getCurrentRow().getTimestampInstant(columnIndex); - } - - /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead. */ - @Override - @ObsoleteApi("Use getTimestampInstant(String) instead") - public org.threeten.bp.Instant getTimestamp(String columnName) { - return toThreetenInstant(getTimestampInstant(columnName)); - } - - @Override - public java.time.Instant getTimestampInstant(String columnName) { - return getCurrentRow().getTimestampInstant(columnName); + public Instant getTimestamp(String columnName) { + return getCurrentRow().getTimestamp(columnName); } @Override diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java index 697bfd1f04..d4d3261dcf 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/SqlType.java @@ -23,6 +23,7 @@ import com.google.cloud.bigtable.common.Type.StructWithSchema; import com.google.protobuf.ByteString; import java.io.Serializable; +import java.time.Instant; import java.util.List; /** @@ -149,7 +150,7 @@ static SqlType bool() { } /** returns a {@link SqlType} for the {@code TIMESTAMP} type. */ - static SqlType timestamp() { + static SqlType timestamp() { return Type.Timestamp.create(); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java index 78986c5c6a..4bc835c81e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java @@ -15,11 +15,9 @@ */ package com.google.cloud.bigtable.data.v2.models.sql; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ArrayValue; import com.google.bigtable.v2.ExecuteQueryRequest; import com.google.bigtable.v2.Type; @@ -30,6 +28,7 @@ import com.google.common.collect.ImmutableMap; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -165,19 +164,11 @@ public Builder setBooleanParam(String paramName, @Nullable Boolean value) { return this; } - /** - * This method is obsolete. Use {@link #setTimestampParamInstant(String, java.time.Instant)} - * instead. - */ - @ObsoleteApi("Use setTimestampParamInstant(String, java.time.Instant) instead") - public Builder setTimestampParam(String paramName, @Nullable org.threeten.bp.Instant value) { - return setTimestampParamInstant(paramName, toJavaTimeInstant(value)); - } /** * Sets a query parameter with the name {@code paramName} and the TIMESTAMP typed value {@code * value} */ - public Builder setTimestampParamInstant(String paramName, @Nullable java.time.Instant value) { + public Builder setTimestampParam(String paramName, @Nullable Instant value) { params.put(paramName, timestampParamOf(value)); return this; } @@ -249,7 +240,7 @@ private static Value booleanParamOf(@Nullable Boolean value) { return builder.build(); } - private static Value timestampParamOf(@Nullable java.time.Instant value) { + private static Value timestampParamOf(@Nullable Instant value) { Value.Builder builder = nullValueWithType(TIMESTAMP_TYPE); if (value != null) { builder.setTimestampValue(toTimestamp(value)); @@ -335,7 +326,7 @@ private static ArrayValue arrayValueOf(List value, SqlType.Array arrayType valueBuilder.addValues(Value.newBuilder().setBoolValue(boolElem).build()); break; case TIMESTAMP: - java.time.Instant timestampElem = (java.time.Instant) element; + Instant timestampElem = (Instant) element; valueBuilder.addValues( Value.newBuilder().setTimestampValue(toTimestamp(timestampElem)).build()); break; @@ -351,7 +342,7 @@ private static ArrayValue arrayValueOf(List value, SqlType.Array arrayType return valueBuilder.build(); } - private static Timestamp toTimestamp(java.time.Instant instant) { + private static Timestamp toTimestamp(Instant instant) { return Timestamp.newBuilder() .setSeconds(instant.getEpochSecond()) .setNanos(instant.getNano()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java index fc3e286cf4..f127b6b54c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/StructReader.java @@ -15,12 +15,10 @@ */ package com.google.cloud.bigtable.data.v2.models.sql; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; - import com.google.api.core.BetaApi; -import com.google.api.core.ObsoleteApi; import com.google.cloud.Date; import com.google.protobuf.ByteString; +import java.time.Instant; import java.util.List; import java.util.Map; @@ -133,29 +131,17 @@ public interface StructReader { */ boolean getBoolean(String columnName); - /** This method is obsolete. Use {@link #getTimestampInstant(int)} instead. */ - @ObsoleteApi("Use getTimestampInstant(int) instead") - org.threeten.bp.Instant getTimestamp(int columnIndex); - /** * @param columnIndex index of the column - * @return {@link java.time.Instant} type value of a non-{@code NULL} column + * @return {@link Instant} type value of a non-{@code NULL} column */ - default java.time.Instant getTimestampInstant(int columnIndex) { - return toJavaTimeInstant(getTimestamp(columnIndex)); - } - - /** This method is obsolete. Use {@link #getTimestampInstant(String)} instead. */ - @ObsoleteApi("Use getTimestampInstant(String) instead") - org.threeten.bp.Instant getTimestamp(String columnName); + Instant getTimestamp(int columnIndex); /** * @param columnName name of the column - * @return {@link java.time.Instant} type value of a non-{@code NULL} column + * @return {@link Instant} type value of a non-{@code NULL} column */ - default java.time.Instant getTimestampInstant(String columnName) { - return toJavaTimeInstant(getTimestamp(columnName)); - } + Instant getTimestamp(String columnName); /** * @param columnIndex index of the column From 812c5a5e27764079432b1f80483ac6ae64aa2fff Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 15:03:59 -0500 Subject: [PATCH 21/30] format tracer files --- .../cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java | 1 - .../cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java | 1 - 2 files changed, 2 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java index bb37235abe..f355fc9047 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CompositeTracer.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; - import com.google.api.gax.tracing.ApiTracer; import com.google.common.collect.ImmutableList; import java.util.ArrayList; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java index d24976969a..59ec1c8594 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.stub.metrics; - import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; import com.google.api.gax.tracing.SpanName; From 7deadf3442ef63701b74e6f3f0442a778f48dcbc Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 15:29:21 -0500 Subject: [PATCH 22/30] adapt admin tests --- .../v2/BigtableTableAdminClientTests.java | 80 ++++++++--------- .../admin/v2/it/BigtableBackupIT.java | 86 +++++++------------ .../bigtable/admin/v2/it/BigtableCmekIT.java | 6 +- .../v2/it/BigtableTableAdminClientIT.java | 25 +++--- .../bigtable/admin/v2/models/BackupTest.java | 11 ++- .../v2/models/CopyBackupRequestTest.java | 55 ++++++------ .../v2/models/CreateBackupRequestTest.java | 40 ++++----- .../v2/models/CreateTableRequestTest.java | 6 +- .../bigtable/admin/v2/models/GCRulesTest.java | 38 ++++---- .../v2/models/UpdateBackupRequestTest.java | 36 ++++---- .../v2/models/UpdateTableRequestTest.java | 6 +- 11 files changed, 179 insertions(+), 210 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index c69c4eb09d..bda240f288 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -90,7 +90,6 @@ import com.google.protobuf.util.Timestamps; import io.grpc.Status; import io.grpc.Status.Code; -import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -106,6 +105,7 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) /** @@ -344,7 +344,7 @@ public void testUpdateTable() { com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest request = com.google.cloud.bigtable.admin.v2.models.UpdateTableRequest.of(TABLE_ID) - .addChangeStreamRetentionDuration(java.time.Duration.ofHours(24)); + .addChangeStreamRetention(org.threeten.bp.Duration.ofHours(24)); com.google.bigtable.admin.v2.Table expectedResponse = com.google.bigtable.admin.v2.Table.newBuilder() @@ -366,9 +366,8 @@ public void testUpdateTable() { // Verify assertThat(actualResult.getId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getChangeStreamRetentionDuration()) - .isEqualTo(java.time.Duration.ofHours(24)); - assertThat(actualResult.getChangeStreamRetentionDuration().toMillis()) + assertThat(actualResult.getChangeStreamRetention()).isEqualTo(java.time.Duration.ofHours(24)); + assertThat(actualResult.getChangeStreamRetention().toMillis()) .isEqualTo(actualResult.getChangeStreamRetention().toMillis()); } @@ -683,7 +682,7 @@ public void testCreateBackup() { CreateBackupRequest req = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .setExpireTime(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); mockOperationResult( mockCreateBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -707,12 +706,12 @@ public void testCreateBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getStartTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getStartTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -731,10 +730,9 @@ public void testCreateHotBackup() { CreateBackupRequest req = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))) + .setExpireTime(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTimeInstant( - java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + .setHotToStandardTime(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); mockOperationResult( mockCreateBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -760,15 +758,15 @@ public void testCreateHotBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getStartTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTimeInstant()) + assertThat(actualResult.getStartTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTime()) .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.HOT); - assertThat(actualResult.getHotToStandardTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + assertThat(actualResult.getHotToStandardTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -807,12 +805,12 @@ public void testGetBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getExpireTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(actualResult.getStartTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getStartTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); assertThat(actualResult.getState()).isEqualTo(Backup.State.fromProto(state)); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.STANDARD); @@ -845,10 +843,10 @@ public void testUpdateBackup() { // Verify assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getExpireTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(actualResult.getHotToStandardTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + assertThat(actualResult.getExpireTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + assertThat(actualResult.getHotToStandardTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -1019,11 +1017,7 @@ public void testCopyBackup() { String srcClusterId = "src-cluster"; String srcBackupId = "src-backup"; - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - java.time.Instant expireTime = - java.time.Instant.now().plus(java.time.Duration.ofDays(15)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(org.threeten.bp.Duration.ofDays(15)); long sizeBytes = 123456789; String dstBackupName = @@ -1036,7 +1030,7 @@ public void testCopyBackup() { CopyBackupRequest.of(srcClusterId, srcBackupId) .setSourceInstance(srcProjectId, srcInstanceId) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(expireTime); + .setExpireTime(expireTime); mockOperationResult( mockCopyBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), @@ -1067,11 +1061,11 @@ public void testCopyBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(srcTableId); assertThat(actualResult.getSourceBackupId()).isEqualTo(srcBackupId); - assertThat(actualResult.getStartTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(actualResult.getEndTimeInstant()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(actualResult.getExpireTimeInstant()).isEqualTo(expireTime); + assertThat(actualResult.getStartTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + assertThat(actualResult.getEndTime()) + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(actualResult.getExpireTime()).isEqualTo(expireTime); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 7f47bef58a..465bf2d467 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -45,9 +45,6 @@ import com.google.common.base.Stopwatch; import com.google.protobuf.ByteString; import java.io.IOException; -import java.time.Duration; -import java.time.Instant; -import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -62,6 +59,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class BigtableBackupIT { @@ -145,15 +144,12 @@ private void deleteBackupIgnoreErrors(String clusterId, String backupId) { @Test public void createAndGetBackupTest() { String backupId = prefixGenerator.newPrefix(); - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofHours(6)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofHours(6)); CreateBackupRequest request = CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTimeInstant(expireTime); + .setExpireTime(expireTime); try { Backup response = tableAdmin.createBackup(request); assertWithMessage("Got wrong backup Id in CreateBackup") @@ -163,7 +159,7 @@ public void createAndGetBackupTest() { .that(response.getSourceTableId()) .isEqualTo(testTable.getId()); assertWithMessage("Got wrong expire time in CreateBackup") - .that(response.getExpireTimeInstant()) + .that(response.getExpireTime()) .isEqualTo(expireTime); Backup result = tableAdmin.getBackup(targetCluster, backupId); @@ -174,7 +170,7 @@ public void createAndGetBackupTest() { .that(result.getSourceTableId()) .isEqualTo(testTable.getId()); assertWithMessage("Got wrong expire time in GetBackup API") - .that(result.getExpireTimeInstant()) + .that(result.getExpireTime()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in GetBackup API") .that(result.getStartTime()) @@ -194,19 +190,15 @@ public void createAndGetBackupTest() { @Test public void createAndGetHotBackupTest() { String backupId = prefixGenerator.newPrefix(); - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofHours(24)).truncatedTo(ChronoUnit.MILLIS); - Instant hotToStandardTime = - Instant.now().plus(Duration.ofHours(24)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofHours(24)); + Instant hotToStandardTime = Instant.now().plus(Duration.ofHours(24)); CreateBackupRequest request = CreateBackupRequest.of(targetClusterHot, backupId) .setSourceTableId(testTableHot.getId()) - .setExpireTimeInstant(expireTime) + .setExpireTime(expireTime) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTimeInstant(hotToStandardTime); + .setHotToStandardTime(hotToStandardTime); try { Backup response = tableAdminHot.createBackup(request); assertWithMessage("Got wrong backup Id in CreateBackup") @@ -216,13 +208,13 @@ public void createAndGetHotBackupTest() { .that(response.getSourceTableId()) .isEqualTo(testTableHot.getId()); assertWithMessage("Got wrong expire time in CreateBackup") - .that(response.getExpireTimeInstant()) + .that(response.getExpireTime()) .isEqualTo(expireTime); assertWithMessage("Got wrong backup type in CreateBackup") .that(response.getBackupType()) .isEqualTo(Backup.BackupType.HOT); assertWithMessage("Got wrong hot to standard time in CreateBackup") - .that(response.getHotToStandardTimeInstant()) + .that(response.getHotToStandardTime()) .isEqualTo(hotToStandardTime); Backup result = tableAdminHot.getBackup(targetClusterHot, backupId); @@ -233,13 +225,13 @@ public void createAndGetHotBackupTest() { .that(result.getSourceTableId()) .isEqualTo(testTableHot.getId()); assertWithMessage("Got wrong expire time in GetBackup API") - .that(result.getExpireTimeInstant()) + .that(result.getExpireTime()) .isEqualTo(expireTime); assertWithMessage("Got wrong hot to standard time in GetBackup API") - .that(result.getHotToStandardTimeInstant()) + .that(result.getHotToStandardTime()) .isEqualTo(hotToStandardTime); assertWithMessage("Got empty start time in GetBackup API") - .that(result.getStartTimeInstant()) + .that(result.getStartTime()) .isNotNull(); assertWithMessage("Got wrong size bytes in GetBackup API") .that(result.getSizeBytes()) @@ -282,23 +274,18 @@ public void updateBackupTest() { tableAdminHot.createBackup( CreateBackupRequest.of(targetClusterHot, backupId) .setSourceTableId(testTableHot.getId()) - .setExpireTimeInstant(Instant.now().plus(Duration.ofDays(15))) + .setExpireTime(Instant.now().plus(Duration.ofDays(15))) .setBackupType(Backup.BackupType.HOT) - .setHotToStandardTimeInstant(Instant.now().plus(Duration.ofDays(10)))); + .setHotToStandardTime(Instant.now().plus(Duration.ofDays(10)))); - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofDays(20)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofDays(20)); UpdateBackupRequest req = UpdateBackupRequest.of(targetClusterHot, backupId) - .setExpireTimeInstant(expireTime) + .setExpireTime(expireTime) .clearHotToStandardTime(); try { Backup backup = tableAdminHot.updateBackup(req); - assertWithMessage("Incorrect expire time") - .that(backup.getExpireTimeInstant()) - .isEqualTo(expireTime); + assertWithMessage("Incorrect expire time").that(backup.getExpireTime()).isEqualTo(expireTime); assertWithMessage("Incorrect hot to standard time") .that(backup.getHotToStandardTime()) .isNull(); @@ -360,7 +347,7 @@ public void crossInstanceRestoreTest() tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTimeInstant(Instant.now().plus(Duration.ofHours(6)))); + .setExpireTime(Instant.now().plus(Duration.ofHours(6)))); Stopwatch stopwatch = Stopwatch.createStarted(); @@ -414,22 +401,19 @@ public void copyBackupTest() throws InterruptedException, IOException, ExecutionException, TimeoutException { String backupId = prefixGenerator.newPrefix(); String copiedBackupId = prefixGenerator.newPrefix(); - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofHours(36)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofHours(36)); // Create the backup tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTimeInstant(expireTime)); + .setExpireTime(expireTime)); try { CopyBackupRequest req = CopyBackupRequest.of(targetCluster, backupId) .setDestination(targetCluster, copiedBackupId) - .setExpireTimeInstant(expireTime); + .setExpireTime(expireTime); Backup result = tableAdmin.copyBackup(req); assertWithMessage("Got wrong copied backup id in CopyBackup API") .that(result.getId()) @@ -438,10 +422,10 @@ public void copyBackupTest() .that(result.getSourceBackupId()) .isEqualTo(backupId); assertWithMessage("Got wrong expire time in CopyBackup API") - .that(result.getExpireTimeInstant()) + .that(result.getExpireTime()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in CopyBackup API") - .that(result.getStartTimeInstant()) + .that(result.getStartTime()) .isNotNull(); assertWithMessage("Got wrong state in CopyBackup API") .that(result.getState()) @@ -458,16 +442,13 @@ public void crossInstanceCopyBackupTest() throws InterruptedException, IOException, ExecutionException, TimeoutException { String backupId = prefixGenerator.newPrefix(); String copiedBackupId = prefixGenerator.newPrefix(); - // From java 15, now() provides nanosecond precision. We trim micros and nanos, so it matches - // bigtable's millisecond precision api. - // see https://bugs.openjdk.org/browse/JDK-8242504 - Instant expireTime = Instant.now().plus(Duration.ofHours(36)).truncatedTo(ChronoUnit.MILLIS); + Instant expireTime = Instant.now().plus(Duration.ofHours(36)); // Create the backup tableAdmin.createBackup( CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTimeInstant(expireTime)); + .setExpireTime(expireTime)); // Set up a new instance to test cross-instance copy. The backup will be copied here String destInstance = prefixGenerator.newPrefix(); @@ -487,7 +468,7 @@ public void crossInstanceCopyBackupTest() CopyBackupRequest.of(targetCluster, backupId) .setSourceInstance(testEnvRule.env().getInstanceId()) .setDestination(destCluster, copiedBackupId) - .setExpireTimeInstant(expireTime); + .setExpireTime(expireTime); Backup result = destTableAdmin.copyBackup(req); assertWithMessage("Got wrong copied backup id in CopyBackup API") .that(result.getId()) @@ -496,16 +477,15 @@ public void crossInstanceCopyBackupTest() .that(result.getSourceBackupId()) .isEqualTo(backupId); assertWithMessage("Got wrong expire time in CopyBackup API") - .that(result.getExpireTimeInstant()) + .that(result.getExpireTime()) .isEqualTo(expireTime); assertWithMessage("Got empty start time in CopyBackup API") - .that(result.getStartTimeInstant()) + .that(result.getStartTime()) .isNotNull(); assertWithMessage("Got wrong state in CopyBackup API") .that(result.getState()) .isAnyOf(Backup.State.CREATING, Backup.State.READY); - } catch (Exception ex) { - System.out.println(ex); + } finally { deleteBackupIgnoreErrors(destTableAdmin, destCluster, copiedBackupId); deleteBackupIgnoreErrors(targetCluster, backupId); @@ -549,7 +529,7 @@ public void backupIamTest() { private CreateBackupRequest createBackupRequest(String backupId) { return CreateBackupRequest.of(targetCluster, backupId) .setSourceTableId(testTable.getId()) - .setExpireTimeInstant(Instant.now().plus(Duration.ofDays(15))); + .setExpireTime(Instant.now().plus(Duration.ofDays(15))); } private static Table createAndPopulateTestTable( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java index 7f4c179280..11f4a99b1c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java @@ -39,8 +39,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import java.io.IOException; -import java.time.Instant; -import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -52,6 +50,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Instant; +import org.threeten.bp.temporal.ChronoUnit; /** * Tests our CMEK offering. It can take up to 5 mins after a CMEK-protected table is created for the @@ -210,7 +210,7 @@ public void backupTest() { // taken tableAdmin.createBackup( CreateBackupRequest.of(clusterId1, BACKUP_ID) - .setExpireTimeInstant(Instant.now().plus(6, ChronoUnit.HOURS)) + .setExpireTime(Instant.now().plus(6, ChronoUnit.HOURS)) .setSourceTableId(TEST_TABLE_ID)); Backup backup = tableAdmin.getBackup(clusterId1, BACKUP_ID); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 07dcc52ce9..cfcc8d0b42 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -42,7 +42,6 @@ import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; import com.google.common.collect.Maps; import com.google.protobuf.ByteString; -import java.time.Duration; import java.util.List; import java.util.Map; import org.junit.After; @@ -53,6 +52,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class BigtableTableAdminClientIT { @@ -90,7 +90,7 @@ public void createTable() { .addFamily("cf2", GCRULES.maxVersions(10)) .addSplit(ByteString.copyFromUtf8("b")) .addSplit(ByteString.copyFromUtf8("q")) - .addChangeStreamRetentionDuration(Duration.ofDays(2)); + .addChangeStreamRetention(Duration.ofDays(2)); Table tableResponse = tableAdmin.createTable(createTableReq); assertEquals(tableId, tableResponse.getId()); @@ -103,7 +103,7 @@ public void createTable() { assertFalse(columnFamilyById.get("cf1").hasGCRule()); assertTrue(columnFamilyById.get("cf2").hasGCRule()); assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions()); - assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetentionDuration()); + assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetention()); // Disable change stream so the table can be deleted. UpdateTableRequest updateTableRequest = @@ -121,21 +121,21 @@ public void updateTable() { CreateTableRequest createTableReq = CreateTableRequest.of(tableId) .addFamily("cf1") - .addChangeStreamRetentionDuration(Duration.ofDays(2)); + .addChangeStreamRetention(Duration.ofDays(2)); Table tableResponse = tableAdmin.createTable(createTableReq); assertEquals(tableId, tableResponse.getId()); - assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetentionDuration()); + assertEquals(Duration.ofDays(2), tableResponse.getChangeStreamRetention()); UpdateTableRequest updateTableRequest = - UpdateTableRequest.of(tableId).addChangeStreamRetentionDuration(Duration.ofDays(4)); + UpdateTableRequest.of(tableId).addChangeStreamRetention(Duration.ofDays(4)); tableResponse = tableAdmin.updateTable(updateTableRequest); assertEquals(tableId, tableResponse.getId()); - assertEquals(Duration.ofDays(4), tableResponse.getChangeStreamRetentionDuration()); + assertEquals(Duration.ofDays(4), tableResponse.getChangeStreamRetention()); updateTableRequest = UpdateTableRequest.of(tableId).disableChangeStreamRetention(); tableResponse = tableAdmin.updateTable(updateTableRequest); assertEquals(tableId, tableResponse.getId()); - assertNull(tableResponse.getChangeStreamRetentionDuration()); + assertNull(tableResponse.getChangeStreamRetention()); } @Test @@ -145,21 +145,20 @@ public void modifyFamilies() { ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId) .addFamily("mf1") - .addFamily("mf2", GCRULES.maxAgeDuration(Duration.ofSeconds(1000, 20000))) + .addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))) .updateFamily( "mf1", GCRULES .union() - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(100))) + .rule(GCRULES.maxAge(Duration.ofSeconds(100))) .rule(GCRULES.maxVersions(1))) .addFamily( "mf3", GCRULES .intersection() - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(2000))) + .rule(GCRULES.maxAge(Duration.ofSeconds(2000))) .rule(GCRULES.maxVersions(10))) - .addFamily( - "mf4", GCRULES.intersection().rule(GCRULES.maxAgeDuration(Duration.ofSeconds(360)))) + .addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))) .addFamily("mf5") .addFamily("mf6") .dropFamily("mf5") diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java index ab87d3bff8..2fc9ad2390 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/BackupTest.java @@ -23,11 +23,11 @@ import com.google.protobuf.Timestamp; import com.google.protobuf.util.Timestamps; import com.google.rpc.Code; -import java.time.Instant; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class BackupTest { @@ -91,13 +91,12 @@ public void testFromProto() { assertThat(result.getId()).isEqualTo("backup1"); assertThat(result.getSourceTableId()).isEqualTo("table1"); assertThat(result.getSourceBackupId()).isEqualTo("backup2"); - assertThat(result.getExpireTimeInstant()) + assertThat(result.getExpireTime()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); - assertThat(result.getStartTimeInstant()) + assertThat(result.getStartTime()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); - assertThat(result.getEndTimeInstant()) - .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); - assertThat(result.getHotToStandardTimeInstant()) + assertThat(result.getEndTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + assertThat(result.getHotToStandardTime()) .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(result.getSizeBytes()).isEqualTo(123456); assertThat(result.getState()).isEqualTo(Backup.State.READY); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java index cf8df6fd40..df8830da8e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CopyBackupRequestTest.java @@ -18,13 +18,12 @@ import static com.google.common.truth.Truth.assertThat; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.protobuf.Timestamp; import com.google.protobuf.util.Timestamps; -import java.time.Duration; -import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class CopyBackupRequestTest { @@ -38,15 +37,13 @@ public class CopyBackupRequestTest { private static final String SOURCE_INSTANCE_ID = "source-instance-id"; private static final String SOURCE_PROJECT_ID = "source-project-id"; private static final Instant EXPIRE_TIME = Instant.now().plus(Duration.ofDays(15)); - private static final Timestamp EXPIRE_TIME_PROTOBUF = - Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli()); @Test public void testToProto() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -54,7 +51,7 @@ public void testToProto() { .setSourceBackup( NameUtil.formatBackupName( PROJECT_ID, INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(EXPIRE_TIME_PROTOBUF) + .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); @@ -66,7 +63,7 @@ public void testToProtoCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -74,7 +71,7 @@ public void testToProtoCrossInstance() { .setSourceBackup( NameUtil.formatBackupName( PROJECT_ID, SOURCE_INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(EXPIRE_TIME_PROTOBUF) + .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); @@ -86,7 +83,7 @@ public void testToProtoCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); com.google.bigtable.admin.v2.CopyBackupRequest requestProto = com.google.bigtable.admin.v2.CopyBackupRequest.newBuilder() @@ -94,7 +91,7 @@ public void testToProtoCrossProject() { .setSourceBackup( NameUtil.formatBackupName( SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID, SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID)) - .setExpireTime(EXPIRE_TIME_PROTOBUF) + .setExpireTime(Timestamps.fromMillis(EXPIRE_TIME.toEpochMilli())) .setBackupId(BACKUP_ID) .build(); assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto); @@ -105,18 +102,18 @@ public void testEquality() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); } @Test @@ -125,20 +122,20 @@ public void testEqualityCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); } @Test @@ -147,20 +144,20 @@ public void testEqualityCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); assertThat(request) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME)); + .setExpireTime(EXPIRE_TIME)); } @Test @@ -168,19 +165,19 @@ public void testHashCode() { CopyBackupRequest request = CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); } @@ -190,21 +187,21 @@ public void testHashCodeCrossInstance() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); } @@ -214,21 +211,21 @@ public void testHashCodeCrossProject() { CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME); + .setExpireTime(EXPIRE_TIME); assertThat(request.hashCode()) .isEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CopyBackupRequest.of(SOURCE_CLUSTER_ID, SOURCE_BACKUP_ID) .setSourceInstance(SOURCE_PROJECT_ID, SOURCE_INSTANCE_ID) .setDestination(CLUSTER_ID, "another-backup") - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .hashCode()); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java index 8f8b0747cf..821919264e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateBackupRequestTest.java @@ -21,11 +21,11 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.cloud.bigtable.admin.v2.models.Backup.BackupType; import com.google.protobuf.util.Timestamps; -import java.time.Duration; -import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class CreateBackupRequestTest { @@ -43,9 +43,9 @@ public void testToProto() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setHotToStandardTime(HOT_TO_STANDARD_TIME); com.google.bigtable.admin.v2.CreateBackupRequest requestProto = com.google.bigtable.admin.v2.CreateBackupRequest.newBuilder() @@ -68,33 +68,33 @@ public void testEquality() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setHotToStandardTime(HOT_TO_STANDARD_TIME); assertThat(request) .isEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); + .setHotToStandardTime(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId("another-table") - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); + .setHotToStandardTime(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.STANDARD) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); + .setHotToStandardTime(HOT_TO_STANDARD_TIME)); } @Test @@ -102,35 +102,35 @@ public void testHashCode() { CreateBackupRequest request = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setHotToStandardTime(HOT_TO_STANDARD_TIME); assertThat(request.hashCode()) .isEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId("another-table") - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.HOT) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID) .setSourceTableId(TABLE_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .setBackupType(BackupType.BACKUP_TYPE_UNSPECIFIED) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME) .hashCode()); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java index 1e52f4b1a9..35dae7aeeb 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateTableRequestTest.java @@ -24,11 +24,11 @@ import com.google.bigtable.admin.v2.Table; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.ByteString; -import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class CreateTableRequestTest { @@ -48,7 +48,7 @@ public void testToProto() { .addFamily("another-family", GCRULES.maxAge(100, TimeUnit.HOURS)) .addSplit(splitKey) .addSplit(secondSplitKey) - .addChangeStreamRetentionDuration(Duration.ofHours(24)) + .addChangeStreamRetention(Duration.ofHours(24)) .setDeletionProtection(true); com.google.bigtable.admin.v2.CreateTableRequest requestProto = @@ -142,7 +142,7 @@ public void testEquality() { .isEqualTo( CreateTableRequest.of(TABLE_ID) .addFamily("family-id") - .addFamily("another-family", GCRULES.maxAgeDuration(Duration.ofHours(100))) + .addFamily("another-family", GCRULES.maxAge(Duration.ofHours(100))) .addSplit(splitKey)); assertThat(request) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java index b9994fa24b..61a1527a34 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java @@ -27,18 +27,18 @@ import com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule; import com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule; -import java.time.Duration; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class GCRulesTest { @Test public void duration() { - DurationRule actual = GCRULES.maxAgeDuration(Duration.ofSeconds(61, 9)); + DurationRule actual = GCRULES.maxAge(Duration.ofSeconds(61, 9)); GcRule expected = buildAgeRule(61, 9); assertNotNull(actual.getMaxAge()); assertThat(actual.toProto()).isEqualTo(expected); @@ -46,14 +46,14 @@ public void duration() { @Test public void durationSeconds() { - GcRule actual = GCRULES.maxAgeDuration(Duration.ofSeconds(1)).toProto(); + GcRule actual = GCRULES.maxAge(Duration.ofSeconds(1)).toProto(); GcRule expected = buildAgeRule(1, 0); assertThat(actual).isEqualTo(expected); } @Test public void durationNanos() { - GcRule actual = GCRULES.maxAgeDuration(Duration.ofNanos(11)).toProto(); + GcRule actual = GCRULES.maxAge(Duration.ofNanos(11)).toProto(); GcRule expected = buildAgeRule(0, 11); assertThat(actual).isEqualTo(expected); } @@ -114,7 +114,7 @@ public void unionTwo() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1))) .toProto(); GcRule expected = @@ -132,8 +132,8 @@ public void unionThree() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) - .rule(GCRULES.maxAgeDuration(Duration.ofNanos(1))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1))) + .rule(GCRULES.maxAge(Duration.ofNanos(1))) .toProto(); GcRule expected = @@ -168,7 +168,7 @@ public void intersectionTwo() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1))) .toProto(); GcRule expected = @@ -188,8 +188,8 @@ public void intersectionThree() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1))) - .rule(GCRULES.maxAgeDuration(Duration.ofNanos(1))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1))) + .rule(GCRULES.maxAge(Duration.ofNanos(1))) .toProto(); GcRule expected = @@ -213,12 +213,12 @@ public void unionOfIntersections() { GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1)))) .rule( GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))); + .rule(GCRULES.maxAge(Duration.ofSeconds(1)))); GcRule expected = GcRule.newBuilder() @@ -251,12 +251,12 @@ public void intersectionOfUnions() { GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))) + .rule(GCRULES.maxAge(Duration.ofSeconds(1)))) .rule( GCRULES .union() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1)))); + .rule(GCRULES.maxAge(Duration.ofSeconds(1)))); GcRule expected = GcRule.newBuilder() @@ -294,9 +294,9 @@ public void unionOfRules() { GCRules.GCRule modelGCRule = GCRULES .union() - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(10))) + .rule(GCRULES.maxAge(Duration.ofSeconds(10))) .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(20, 2))); + .rule(GCRULES.maxAge(Duration.ofSeconds(20, 2))); assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); } @@ -314,7 +314,7 @@ public void intersectionWithFromProto() { GCRules.GCRule modelGCRule = GCRules.GCRULES .intersection() - .rule(GCRULES.maxAgeDuration(java.time.Duration.ofSeconds(10, 5))) + .rule(GCRULES.maxAge(org.threeten.bp.Duration.ofSeconds(10, 5))) .rule(GCRULES.maxVersions(1)) .rule(GCRULES.maxVersions(2)); assertThat(GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); @@ -351,12 +351,12 @@ public void unionOfIntersectionFromProto() { GCRULES .intersection() .rule(GCRULES.maxVersions(10)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(2, 4)))) + .rule(GCRULES.maxAge(Duration.ofSeconds(2, 4)))) .rule( GCRULES .intersection() .rule(GCRULES.maxVersions(1)) - .rule(GCRULES.maxAgeDuration(Duration.ofSeconds(1, 1)))); + .rule(GCRULES.maxAge(Duration.ofSeconds(1, 1)))); assertThat(GCRules.GCRULES.fromProto(protoGCRule)).isEqualTo(modelGCRule); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java index 54f3b53142..9551fd70c4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateBackupRequestTest.java @@ -21,11 +21,11 @@ import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; import com.google.protobuf.util.Timestamps; -import java.time.Duration; -import java.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; +import org.threeten.bp.Instant; @RunWith(JUnit4.class) public class UpdateBackupRequestTest { @@ -43,8 +43,8 @@ public class UpdateBackupRequestTest { public void testToProto() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setExpireTime(EXPIRE_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME); com.google.bigtable.admin.v2.UpdateBackupRequest requestProto = com.google.bigtable.admin.v2.UpdateBackupRequest.newBuilder() @@ -69,22 +69,22 @@ public void testToProto() { public void testEquality() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setExpireTime(EXPIRE_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME); assertThat(request) .isEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); + .setExpireTime(EXPIRE_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME_2) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME)); + .setExpireTime(EXPIRE_TIME_2) + .setHotToStandardTime(HOT_TO_STANDARD_TIME)); assertThat(request) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .clearHotToStandardTime()); } @@ -92,24 +92,24 @@ public void testEquality() { public void testHashCode() { UpdateBackupRequest request = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME); + .setExpireTime(EXPIRE_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME); assertThat(request.hashCode()) .isEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) + .setExpireTime(EXPIRE_TIME) + .setHotToStandardTime(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME_2) - .setHotToStandardTimeInstant(HOT_TO_STANDARD_TIME) + .setExpireTime(EXPIRE_TIME_2) + .setHotToStandardTime(HOT_TO_STANDARD_TIME) .hashCode()); assertThat(request.hashCode()) .isNotEqualTo( UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID) - .setExpireTimeInstant(EXPIRE_TIME) + .setExpireTime(EXPIRE_TIME) .clearHotToStandardTime() .hashCode()); } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java index 1d55f757e3..24fe80187c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateTableRequestTest.java @@ -22,10 +22,10 @@ import com.google.bigtable.admin.v2.Table; import com.google.cloud.bigtable.admin.v2.internal.NameUtil; import com.google.protobuf.FieldMask; -import java.time.Duration; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class UpdateTableRequestTest { @@ -36,7 +36,7 @@ public class UpdateTableRequestTest { @Test public void testEnableChangeStreamToProto() { UpdateTableRequest request = - UpdateTableRequest.of(TABLE_ID).addChangeStreamRetentionDuration(Duration.ofHours(24)); + UpdateTableRequest.of(TABLE_ID).addChangeStreamRetention(Duration.ofHours(24)); com.google.bigtable.admin.v2.UpdateTableRequest requestProto = com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() @@ -57,7 +57,7 @@ public void testEnableChangeStreamToProto() { @Test public void testDisableChangeStreamToProto() { UpdateTableRequest request = - UpdateTableRequest.of(TABLE_ID).addChangeStreamRetentionDuration(Duration.ofHours(0)); + UpdateTableRequest.of(TABLE_ID).addChangeStreamRetention(Duration.ofHours(0)); com.google.bigtable.admin.v2.UpdateTableRequest requestProto = com.google.bigtable.admin.v2.UpdateTableRequest.newBuilder() From e2b16214eb280e65b8f44b40c2a288ba43028f5d Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 15:29:29 -0500 Subject: [PATCH 23/30] adapt sql tests --- .../v2/internal/AbstractProtoStructReader.java | 1 - .../bigtable/data/v2/internal/ResultSetImpl.java | 1 - .../bigtable/data/v2/models/sql/Statement.java | 1 - .../admin/v2/BigtableTableAdminClientTests.java | 5 +++-- .../v2/internal/AbstractProtoStructReaderTest.java | 8 ++++---- .../bigtable/data/v2/internal/ProtoStructTest.java | 5 ++--- .../data/v2/internal/ResultSetImplTest.java | 4 ++-- .../cloud/bigtable/data/v2/it/ExecuteQueryIT.java | 14 +++++++------- .../bigtable/data/v2/models/sql/StatementTest.java | 2 +- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java index a8992ee85d..2a74fccd22 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReader.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.internal; - import com.google.api.core.InternalApi; import com.google.bigtable.v2.Value; import com.google.bigtable.v2.Value.KindCase; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java index d9a97110c6..53044c3b37 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImpl.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.internal; - import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; import com.google.api.gax.rpc.ApiExceptions; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java index 4bc835c81e..c1831219a6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/sql/Statement.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.models.sql; - import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; import com.google.bigtable.v2.ArrayValue; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index bda240f288..77c668a1f1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -366,7 +366,8 @@ public void testUpdateTable() { // Verify assertThat(actualResult.getId()).isEqualTo(TABLE_ID); - assertThat(actualResult.getChangeStreamRetention()).isEqualTo(java.time.Duration.ofHours(24)); + assertThat(actualResult.getChangeStreamRetention()) + .isEqualTo(org.threeten.bp.Duration.ofHours(24)); assertThat(actualResult.getChangeStreamRetention().toMillis()) .isEqualTo(actualResult.getChangeStreamRetention().toMillis()); } @@ -763,7 +764,7 @@ public void testCreateHotBackup() { assertThat(actualResult.getEndTime()) .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getExpireTime()) - .isEqualTo(java.time.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.HOT); assertThat(actualResult.getHotToStandardTime()) .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java index 9a848e38d4..8770880983 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java @@ -311,8 +311,8 @@ public static List parameters() { Collections.singletonList(timestampValue(1000000, 100)), 0, "testField", - (BiFunction) TestProtoStruct::getTimestampInstant, - (BiFunction) TestProtoStruct::getTimestampInstant, + (BiFunction) TestProtoStruct::getTimestamp, + (BiFunction) TestProtoStruct::getTimestamp, Instant.ofEpochSecond(1000000, 100) }, // MAX long timestamp - bigtable allows users to set timestamp micros to any long @@ -323,8 +323,8 @@ public static List parameters() { Collections.singletonList(timestampValue(MAX_TS_SECONDS, 0)), 0, "testField", - (BiFunction) TestProtoStruct::getTimestampInstant, - (BiFunction) TestProtoStruct::getTimestampInstant, + (BiFunction) TestProtoStruct::getTimestamp, + (BiFunction) TestProtoStruct::getTimestamp, Instant.ofEpochSecond(MAX_TS_SECONDS) }, // Date diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java index a4b364cf9d..66808bb98a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java @@ -101,7 +101,7 @@ public void getByIndex_supportsAllTypes() { assertThat(struct.getDouble(3)).isEqualTo(1.23d); assertThat(struct.getFloat(4)).isEqualTo(1.23f); assertThat(struct.getBoolean(5)).isTrue(); - assertThat(struct.getTimestampInstant(6)).isEqualTo(Instant.ofEpochSecond(100000, 100)); + assertThat(struct.getTimestamp(6)).isEqualTo(Instant.ofEpochSecond(100000, 100)); assertThat(struct.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(struct.getStruct(8)) .isEqualTo( @@ -129,8 +129,7 @@ public void getByNameSupportsAllTypes() { assertThat(struct.getDouble("doubleField")).isEqualTo(1.23d); assertThat(struct.getFloat("floatField")).isEqualTo(1.23f); assertThat(struct.getBoolean("booleanField")).isTrue(); - assertThat(struct.getTimestampInstant("timestampField")) - .isEqualTo(Instant.ofEpochSecond(100000, 100)); + assertThat(struct.getTimestamp("timestampField")).isEqualTo(Instant.ofEpochSecond(100000, 100)); assertThat(struct.getDate("dateField")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(struct.getStruct("structField")) .isEqualTo( diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java index 115cf1f279..a8c5776a87 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java @@ -126,8 +126,8 @@ public void testSingleRow() throws ExecutionException, InterruptedException { assertThat(resultSet.getFloat("float")).isEqualTo(1.23f); assertThat(resultSet.getBoolean(5)).isTrue(); assertThat(resultSet.getBoolean("boolean")).isTrue(); - assertThat(resultSet.getTimestampInstant(6)).isEqualTo(Instant.ofEpochSecond(10000000, 100)); - assertThat(resultSet.getTimestampInstant("timestamp")) + assertThat(resultSet.getTimestamp(6)).isEqualTo(Instant.ofEpochSecond(10000000, 100)); + assertThat(resultSet.getTimestamp("timestamp")) .isEqualTo(Instant.ofEpochSecond(10000000, 100)); assertThat(resultSet.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 5)); assertThat(resultSet.getDate("date")).isEqualTo(Date.fromYearMonthDay(2024, 6, 5)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java index 9d063fa1db..34d0952401 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java @@ -124,10 +124,10 @@ public void withHistoryQuery() { Struct rowAQual_0 = rowAQual.get(0); assertThat(rowAQual_0.getBytes("value")).isEqualTo(ByteString.copyFromUtf8("val")); // timestamp in micros above so we divide by 1000 - assertThat(rowAQual_0.getTimestampInstant("timestamp")).isEqualTo(Instant.ofEpochMilli(10)); + assertThat(rowAQual_0.getTimestamp("timestamp")).isEqualTo(Instant.ofEpochMilli(10)); Struct rowAQual_1 = rowAQual.get(1); assertThat(rowAQual_1.getBytes("value")).isEqualTo(ByteString.copyFromUtf8("old")); - assertThat(rowAQual_1.getTimestampInstant("timestamp")).isEqualTo(Instant.ofEpochMilli(1)); + assertThat(rowAQual_1.getTimestamp("timestamp")).isEqualTo(Instant.ofEpochMilli(1)); assertThat(rs.next()).isTrue(); assertThat(rs.getBytes("_key")).isEqualTo(ByteString.copyFromUtf8(uniquePrefix + "b")); @@ -169,8 +169,8 @@ public void allTypes() { assertThat(rs.getDouble(4)).isEqualTo(1.3d); assertThat(rs.getBoolean("boolCol")).isTrue(); assertThat(rs.getBoolean(5)).isTrue(); - assertThat(rs.getTimestampInstant("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); - assertThat(rs.getTimestampInstant(6)).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestamp("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestamp(6)).isEqualTo(Instant.ofEpochMilli(1000)); assertThat(rs.getDate("dateCol")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getStruct("structCol").getLong("a")).isEqualTo(1); @@ -222,7 +222,7 @@ public void allQueryParamsTypes() { .setDoubleParam("doubleParam", 1.3d) .setFloatParam("floatParam", 1.4f) .setBooleanParam("boolParam", true) - .setTimestampParamInstant("tsParam", Instant.ofEpochMilli(1000)) + .setTimestampParam("tsParam", Instant.ofEpochMilli(1000)) .setDateParam("dateParam", Date.fromYearMonthDay(2024, 6, 1)) .setListParam( "byteArrayParam", @@ -272,8 +272,8 @@ public void allQueryParamsTypes() { assertThat(rs.getFloat(4)).isEqualTo(1.4f); assertThat(rs.getBoolean("boolCol")).isTrue(); assertThat(rs.getBoolean(5)).isTrue(); - assertThat(rs.getTimestampInstant("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); - assertThat(rs.getTimestampInstant(6)).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestamp("tsCol")).isEqualTo(Instant.ofEpochMilli(1000)); + assertThat(rs.getTimestamp(6)).isEqualTo(Instant.ofEpochMilli(1000)); assertThat(rs.getDate("dateCol")).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getDate(7)).isEqualTo(Date.fromYearMonthDay(2024, 6, 1)); assertThat(rs.getList("byteArrayCol", SqlType.arrayOf(SqlType.bytes()))) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java index e2fecffdca..6d4765230e 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/sql/StatementTest.java @@ -218,7 +218,7 @@ public void statementWithTimestampParam() { Statement s = Statement.newBuilder( "SELECT * FROM table WHERE PARSE_TIMESTAMP(\"%Y/%m/%dT%H:%M:%S\", CAST(cf[\"ts\"] AS STRING)) < @timeParam") - .setTimestampParamInstant("timeParam", Instant.ofEpochSecond(1000, 100)) + .setTimestampParam("timeParam", Instant.ofEpochSecond(1000, 100)) .build(); assertThat(s.toProto(REQUEST_CONTEXT)) From dde93267639cde8fd94dbaf4f736e990b6c1128a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Thu, 5 Dec 2024 17:59:21 -0500 Subject: [PATCH 24/30] changes in change stream --- .../data/v2/models/ChangeStreamMutation.java | 31 +++---- .../v2/models/ChangeStreamRecordAdapter.java | 48 ++--------- .../DefaultChangeStreamRecordAdapter.java | 37 +-------- .../data/v2/models/ReadChangeStreamQuery.java | 26 +++--- .../ChangeStreamStateMachine.java | 6 +- .../v2/models/ChangeStreamMutationTest.java | 24 +++--- .../DefaultChangeStreamRecordAdapterTest.java | 81 ++++++++----------- .../v2/models/ReadChangeStreamQueryTest.java | 45 +++++------ .../ReadChangeStreamRetryTest.java | 2 +- .../ReadChangeStreamUserCallableTest.java | 6 +- 10 files changed, 107 insertions(+), 199 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java index f0279f69c4..1defc67c5e 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutation.java @@ -82,7 +82,7 @@ static Builder createUserMutation( .setRowKey(rowKey) .setType(MutationType.USER) .setSourceClusterId(sourceClusterId) - .setCommitTimestampInstant(commitTimestamp) + .setCommitTime(commitTimestamp) .setTieBreaker(tieBreaker); } @@ -97,7 +97,7 @@ static Builder createGcMutation( .setRowKey(rowKey) .setType(MutationType.GARBAGE_COLLECTION) .setSourceClusterId("") - .setCommitTimestampInstant(commitTimestamp) + .setCommitTime(commitTimestamp) .setTieBreaker(tieBreaker); } @@ -113,12 +113,12 @@ static Builder createGcMutation( @Nonnull public abstract String getSourceClusterId(); - /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ - @ObsoleteApi("Use getCommitTimestampInstant() instead") + /** This method is obsolete. Use {@link #getCommitTime()} instead. */ + @ObsoleteApi("Use getCommitTime() instead") public abstract org.threeten.bp.Instant getCommitTimestamp(); /** Get the commit timestamp of the current mutation. */ - public java.time.Instant getCommitTimestampInstant() { + public java.time.Instant getCommitTime() { return toJavaTimeInstant(getCommitTimestamp()); } @@ -132,12 +132,12 @@ public java.time.Instant getCommitTimestampInstant() { @Nonnull public abstract String getToken(); - /** This method is obsolete. Use {@link #getCommitTimestampInstant()} instead. */ - @ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead") + /** This method is obsolete. Use {@link #getEstimatedLowWatermarkTime()} instead. */ + @ObsoleteApi("Use getEstimatedLowWatermarkTime() instead") public abstract org.threeten.bp.Instant getEstimatedLowWatermark(); /** Get the low watermark of the current mutation. */ - public java.time.Instant getEstimatedLowWatermarkInstant() { + public java.time.Instant getEstimatedLowWatermarkTime() { return toJavaTimeInstant(getEstimatedLowWatermark()); } @@ -160,14 +160,12 @@ abstract static class Builder { abstract Builder setSourceClusterId(@Nonnull String sourceClusterId); - Builder setCommitTimestampInstant(java.time.Instant commitTimestamp) { + Builder setCommitTime(java.time.Instant commitTimestamp) { return setCommitTimestamp(toThreetenInstant(commitTimestamp)); } - /** - * This method is obsolete. Use {@link #setCommitTimestampInstant(java.time.Instant)} instead. - */ - @ObsoleteApi("Use setCommitTimestampInstant(java.time.Instant) instead") + /** This method is obsolete. Use {@link #setCommitTime(java.time.Instant)} instead. */ + @ObsoleteApi("Use setCommitTime(java.time.Instant) instead") abstract Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp); abstract Builder setTieBreaker(int tieBreaker); @@ -176,14 +174,11 @@ Builder setCommitTimestampInstant(java.time.Instant commitTimestamp) { abstract Builder setToken(@Nonnull String token); - Builder setEstimatedLowWatermarkInstant(java.time.Instant estimatedLowWatermark) { + Builder setLowWatermarkTime(java.time.Instant estimatedLowWatermark) { return setEstimatedLowWatermark(toThreetenInstant(estimatedLowWatermark)); } - /** - * This method is obsolete. Use {@link #setEstimatedLowWatermarkInstant(java.time.Instant)} - * instead. - */ + /** This method is obsolete. Use {@link #setLowWatermarkTime(java.time.Instant)} instead. */ @ObsoleteApi("Use setEstimatedLowWatermarkInstant(java.time.Instant) instead") abstract Builder setEstimatedLowWatermark(org.threeten.bp.Instant estimatedLowWatermark); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java index e7ec59d070..ba8e57cde8 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java @@ -15,10 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant; - import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.protobuf.ByteString; @@ -110,47 +107,24 @@ interface ChangeStreamRecordBuilder { */ ChangeStreamRecordT onCloseStream(ReadChangeStreamResponse.CloseStream closeStream); - /** - * This method is obsolete. Use {@link #startUserMutationInstant(ByteString, String, - * java.time.Instant, int)} instead. - */ - @ObsoleteApi("Use startUserMutationInstant(ByteString, String, java.time.Instant, int) instead") - void startUserMutation( - @Nonnull ByteString rowKey, - @Nonnull String sourceClusterId, - org.threeten.bp.Instant commitTimestamp, - int tieBreaker); - /** * Called to start a new user initiated ChangeStreamMutation. This will be called at most once. * If called, the current change stream record must not include any close stream message or * heartbeat. */ - default void startUserMutationInstant( + void startUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, java.time.Instant commitTimestamp, - int tieBreaker) { - startUserMutation(rowKey, sourceClusterId, toThreetenInstant(commitTimestamp), tieBreaker); - } - - /** - * This method is obsolete. Use {@link #startGcMutationInstant(ByteString, java.time.Instant, - * int)} instead. - */ - @ObsoleteApi("Use startGcMutationInstant(ByteString, java.time.Instant, int) instead") - void startGcMutation( - @Nonnull ByteString rowKey, org.threeten.bp.Instant commitTimestamp, int tieBreaker); + int tieBreaker); /** * Called to start a new Garbage Collection ChangeStreamMutation. This will be called at most * once. If called, the current change stream record must not include any close stream message * or heartbeat. */ - default void startGcMutationInstant( - @Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { - startGcMutation(rowKey, toThreetenInstant(commitTimestamp), tieBreaker); - } + void startGcMutation( + @Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker); /** Called to add a DeleteFamily mod. */ void deleteFamily(@Nonnull String familyName); @@ -201,19 +175,9 @@ void mergeToCell( /** Called once per cell to signal the end of the value (unless reset). */ void finishCell(); - /** - * This method is obsolete. Use {@link #finishChangeStreamMutationInstant(String, - * java.time.Instant)} instead. - */ - @ObsoleteApi("Use finishChangeStreamMutationInstant(String, java.time.Instant) instead") - ChangeStreamRecordT finishChangeStreamMutation( - @Nonnull String token, org.threeten.bp.Instant estimatedLowWatermark); - /** Called once per stream record to signal that all mods have been processed (unless reset). */ - default ChangeStreamRecordT finishChangeStreamMutationInstant( - @Nonnull String token, java.time.Instant estimatedLowWatermark) { - return finishChangeStreamMutation(token, toThreetenInstant(estimatedLowWatermark)); - } + ChangeStreamRecordT finishChangeStreamMutation( + @Nonnull String token, java.time.Instant estimatedLowWatermark); /** Called when the current in progress change stream record should be dropped */ void reset(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index a800a53ec7..b025bd96aa 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -15,14 +15,13 @@ */ package com.google.cloud.bigtable.data.v2.models; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant; import com.google.api.core.InternalApi; -import com.google.api.core.ObsoleteApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; +import java.time.Instant; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -102,10 +101,10 @@ public ChangeStreamRecord onCloseStream(ReadChangeStreamResponse.CloseStream clo /** {@inheritDoc} */ @Override - public void startUserMutationInstant( + public void startUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, - java.time.Instant commitTimestamp, + Instant commitTimestamp, int tieBreaker) { this.changeStreamMutationBuilder = ChangeStreamMutation.createUserMutation( @@ -114,27 +113,7 @@ public void startUserMutationInstant( /** {@inheritDoc} */ @Override - @ObsoleteApi("Use startUserMutationInstant(ByteString, String, java.time.Instant, int) instead") - public void startUserMutation( - @Nonnull ByteString rowKey, - @Nonnull String sourceClusterId, - org.threeten.bp.Instant commitTimestamp, - int tieBreaker) { - startUserMutationInstant( - rowKey, sourceClusterId, toJavaTimeInstant(commitTimestamp), tieBreaker); - } - - /** {@inheritDoc} */ - @Override - @ObsoleteApi("Use startUserMutationInstant(ByteString, java.time.Instant, int) instead") public void startGcMutation( - @Nonnull ByteString rowKey, org.threeten.bp.Instant commitTimestamp, int tieBreaker) { - startGcMutationInstant(rowKey, toJavaTimeInstant(commitTimestamp), tieBreaker); - } - - /** {@inheritDoc} */ - @Override - public void startGcMutationInstant( ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { this.changeStreamMutationBuilder = ChangeStreamMutation.createGcMutation(rowKey, commitTimestamp, tieBreaker); @@ -197,18 +176,10 @@ public void finishCell() { /** {@inheritDoc} */ @Override - @ObsoleteApi("Use finishChangeStreamMutationInstant(String, java.time.Instant) instead") public ChangeStreamRecord finishChangeStreamMutation( - @Nonnull String token, org.threeten.bp.Instant estimatedLowWatermark) { - return finishChangeStreamMutationInstant(token, toJavaTimeInstant(estimatedLowWatermark)); - } - - /** {@inheritDoc} */ - @Override - public ChangeStreamRecord finishChangeStreamMutationInstant( String token, java.time.Instant estimatedLowWatermark) { this.changeStreamMutationBuilder.setToken(token); - this.changeStreamMutationBuilder.setEstimatedLowWatermarkInstant(estimatedLowWatermark); + this.changeStreamMutationBuilder.setLowWatermarkTime(estimatedLowWatermark); return this.changeStreamMutationBuilder.build(); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java index 7dd76236d2..2c9cf54354 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQuery.java @@ -146,14 +146,14 @@ public ReadChangeStreamQuery streamPartition(ByteStringRange range) { return streamPartition(rangeBuilder.build()); } - /** This method is obsolete. Use {@link #startTimeInstant(java.time.Instant)} instead. */ - @ObsoleteApi("Use startTimeInstant(java.time.Instant) instead") + /** This method is obsolete. Use {@link #startTime(java.time.Instant)} instead. */ + @ObsoleteApi("Use startTime(java.time.Instant) instead") public ReadChangeStreamQuery startTime(org.threeten.bp.Instant value) { - return startTimeInstant(toJavaTimeInstant(value)); + return startTime(toJavaTimeInstant(value)); } /** Sets the startTime to read the change stream. */ - public ReadChangeStreamQuery startTimeInstant(java.time.Instant value) { + public ReadChangeStreamQuery startTime(java.time.Instant value) { Preconditions.checkState( !builder.hasContinuationTokens(), "startTime and continuationTokens can't be specified together"); @@ -165,14 +165,14 @@ public ReadChangeStreamQuery startTimeInstant(java.time.Instant value) { return this; } - /** This method is obsolete. Use {@link #endTimeInstant(java.time.Instant)} instead. */ - @ObsoleteApi("Use endTimeInstant(java.time.Instant) instead") + /** This method is obsolete. Use {@link #endTime(java.time.Instant)} instead. */ + @ObsoleteApi("Use endTime(java.time.Instant) instead") public ReadChangeStreamQuery endTime(org.threeten.bp.Instant value) { - return endTimeInstant(toJavaTimeInstant(value)); + return endTime(toJavaTimeInstant(value)); } /** Sets the endTime to read the change stream. */ - public ReadChangeStreamQuery endTimeInstant(java.time.Instant value) { + public ReadChangeStreamQuery endTime(java.time.Instant value) { builder.setEndTime( Timestamp.newBuilder() .setSeconds(value.getEpochSecond()) @@ -196,16 +196,14 @@ public ReadChangeStreamQuery continuationTokens( return this; } - /** - * This method is obsolete. Use {@link #heartbeatDurationJavaTime(java.time.Duration)} instead. - */ - @ObsoleteApi("Use heartbeatDurationJavaTime(java.time.Duration) instead") + /** This method is obsolete. Use {@link #heartbeatDuration(java.time.Duration)} instead. */ + @ObsoleteApi("Use heartbeatDuration(java.time.Duration) instead") public ReadChangeStreamQuery heartbeatDuration(org.threeten.bp.Duration duration) { - return heartbeatDurationJavaTime(toJavaTimeDuration(duration)); + return heartbeatDuration(toJavaTimeDuration(duration)); } /** Sets the heartbeat duration for the change stream. */ - public ReadChangeStreamQuery heartbeatDurationJavaTime(java.time.Duration duration) { + public ReadChangeStreamQuery heartbeatDuration(java.time.Duration duration) { builder.setHeartbeatDuration( Duration.newBuilder() .setSeconds(duration.getSeconds()) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java index 7627fb4751..27cb6f1478 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/changestream/ChangeStreamStateMachine.java @@ -331,7 +331,7 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { validate( dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: GC mutation shouldn't have source cluster id."); - builder.startGcMutationInstant( + builder.startGcMutation( dataChange.getRowKey(), java.time.Instant.ofEpochSecond( dataChange.getCommitTimestamp().getSeconds(), @@ -341,7 +341,7 @@ State handleDataChange(ReadChangeStreamResponse.DataChange dataChange) { validate( !dataChange.getSourceClusterId().isEmpty(), "AWAITING_NEW_STREAM_RECORD: User initiated data change missing source cluster id."); - builder.startUserMutationInstant( + builder.startUserMutation( dataChange.getRowKey(), dataChange.getSourceClusterId(), java.time.Instant.ofEpochSecond( @@ -575,7 +575,7 @@ private State checkAndFinishMutationIfNeeded(ReadChangeStreamResponse.DataChange validate(!dataChange.getToken().isEmpty(), "Last data change missing token"); validate(dataChange.hasEstimatedLowWatermark(), "Last data change missing lowWatermark"); completeChangeStreamRecord = - builder.finishChangeStreamMutationInstant( + builder.finishChangeStreamMutation( dataChange.getToken(), java.time.Instant.ofEpochSecond( dataChange.getEstimatedLowWatermark().getSeconds(), diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java index 676497ddb0..c3dc61244a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamMutationTest.java @@ -73,18 +73,17 @@ public void userInitiatedMutationTest() throws IOException, ClassNotFoundExcepti Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Test the getters. assertThat(changeStreamMutation.getRowKey()).isEqualTo(ByteString.copyFromUtf8("key")); assertThat(changeStreamMutation.getType()).isEqualTo(ChangeStreamMutation.MutationType.USER); assertThat(changeStreamMutation.getSourceClusterId()).isEqualTo("fake-source-cluster-id"); - assertThat(changeStreamMutation.getCommitTimestampInstant()).isEqualTo(FAKE_COMMIT_TIMESTAMP); + assertThat(changeStreamMutation.getCommitTime()).isEqualTo(FAKE_COMMIT_TIMESTAMP); assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0); assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token"); - assertThat(changeStreamMutation.getEstimatedLowWatermarkInstant()) - .isEqualTo(FAKE_LOW_WATERMARK); + assertThat(changeStreamMutation.getEstimatedLowWatermarkTime()).isEqualTo(FAKE_LOW_WATERMARK); // Test serialization. ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -113,7 +112,7 @@ public void gcMutationTest() throws IOException, ClassNotFoundException { ByteString.copyFromUtf8("fake-qualifier"), Range.TimestampRange.create(1000L, 2000L)) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Test the getters. @@ -121,11 +120,10 @@ public void gcMutationTest() throws IOException, ClassNotFoundException { assertThat(changeStreamMutation.getType()) .isEqualTo(ChangeStreamMutation.MutationType.GARBAGE_COLLECTION); Assert.assertTrue(changeStreamMutation.getSourceClusterId().isEmpty()); - assertThat(changeStreamMutation.getCommitTimestampInstant()).isEqualTo(FAKE_COMMIT_TIMESTAMP); + assertThat(changeStreamMutation.getCommitTime()).isEqualTo(FAKE_COMMIT_TIMESTAMP); assertThat(changeStreamMutation.getTieBreaker()).isEqualTo(0); assertThat(changeStreamMutation.getToken()).isEqualTo("fake-token"); - assertThat(changeStreamMutation.getEstimatedLowWatermarkInstant()) - .isEqualTo(FAKE_LOW_WATERMARK); + assertThat(changeStreamMutation.getEstimatedLowWatermarkTime()).isEqualTo(FAKE_LOW_WATERMARK); // Test serialization. ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -163,7 +161,7 @@ public void toRowMutationTest() { Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Convert it to a rowMutation and construct a MutateRowRequest. @@ -206,7 +204,7 @@ public void toRowMutationWithoutTokenShouldFailTest() { ChangeStreamMutation.createUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); + .setLowWatermarkTime(FAKE_LOW_WATERMARK); Assert.assertThrows(IllegalStateException.class, builder::build); } @@ -246,7 +244,7 @@ public void toRowMutationEntryTest() { Value.rawTimestamp(1000), Value.rawValue(ByteString.copyFrom(Longs.toByteArray(1234L)))) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Convert it to a rowMutationEntry and construct a MutateRowRequest. @@ -286,7 +284,7 @@ public void toRowMutationEntryWithoutTokenShouldFailTest() { ChangeStreamMutation.createUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); + .setLowWatermarkTime(FAKE_LOW_WATERMARK); Assert.assertThrows(IllegalStateException.class, builder::build); } @@ -311,7 +309,7 @@ public void testWithLongValue() { 1000L, ByteString.copyFrom(Longs.toByteArray(1L))) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); RowMutation rowMutation = changeStreamMutation.toRowMutation(TABLE_ID); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java index 56701a8e6f..425f9580b7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapterTest.java @@ -59,7 +59,7 @@ public void isHeartbeatTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); Assert.assertTrue(adapter.isHeartbeat(heartbeatRecord)); Assert.assertFalse(adapter.isHeartbeat(closeStreamRecord)); @@ -99,7 +99,7 @@ public void isChangeStreamMutationTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); Assert.assertFalse(adapter.isChangeStreamMutation(heartbeatRecord)); Assert.assertFalse(adapter.isChangeStreamMutation(closeStreamRecord)); @@ -112,7 +112,7 @@ public void getTokenFromChangeStreamMutationTest() { ChangeStreamMutation.createGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0) .setToken("change-stream-mutation-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); Assert.assertEquals( adapter.getTokenFromChangeStreamMutation(changeStreamMutationRecord), @@ -161,14 +161,14 @@ public void closeStreamTest() { @Test(expected = IllegalStateException.class) public void createHeartbeatWithExistingMutationShouldFailTest() { - changeStreamRecordBuilder.startGcMutationInstant( + changeStreamRecordBuilder.startGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.onHeartbeat(ReadChangeStreamResponse.Heartbeat.getDefaultInstance()); } @Test(expected = IllegalStateException.class) public void createCloseStreamWithExistingMutationShouldFailTest() { - changeStreamRecordBuilder.startGcMutationInstant( + changeStreamRecordBuilder.startGcMutation( ByteString.copyFromUtf8("key"), FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.onCloseStream( ReadChangeStreamResponse.CloseStream.getDefaultInstance()); @@ -186,21 +186,19 @@ public void singleDeleteFamilyTest() { ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily(deleteFromFamily.getFamilyName()); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -227,11 +225,11 @@ public void singleDeleteCellTest() { ByteString.copyFromUtf8("fake-qualifier"), Range.TimestampRange.create(1000L, 2000L)) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteCells( deleteFromColumn.getFamilyName(), @@ -240,13 +238,11 @@ public void singleDeleteCellTest() { deleteFromColumn.getTimeRange().getStartTimestampMicros(), deleteFromColumn.getTimeRange().getEndTimestampMicros())); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -262,25 +258,23 @@ public void singleNonChunkedCellTest() { 100L, ByteString.copyFromUtf8("fake-value")) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. // Suppose the SetCell is not chunked and the state machine calls `cellValue()` once. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("fake-value")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -296,13 +290,13 @@ public void singleChunkedCellTest() { 100L, ByteString.copyFromUtf8("fake-value1-value2")) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. // Suppose the SetCell is chunked into two pieces and the state machine calls `cellValue()` // twice. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); @@ -310,13 +304,11 @@ public void singleChunkedCellTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value2")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } @@ -335,10 +327,10 @@ public void multipleChunkedCellsTest() { } expectedChangeStreamMutationBuilder .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); + .setLowWatermarkTime(FAKE_LOW_WATERMARK); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); for (int i = 0; i < 10; ++i) { changeStreamRecordBuilder.startCell( @@ -350,13 +342,11 @@ public void multipleChunkedCellsTest() { } // Check that they're the same. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); // Call again. assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); } @@ -379,10 +369,10 @@ public void multipleDifferentModsTest() { 100L, ByteString.copyFromUtf8("chunked-value")) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK); + .setLowWatermarkTime(FAKE_LOW_WATERMARK); // Create the ChangeStreamMutation through the ChangeStreamRecordBuilder. - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily("fake-family"); // Add non-chunked cell. @@ -397,8 +387,7 @@ public void multipleDifferentModsTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutationBuilder.build()); } @@ -429,14 +418,13 @@ public void resetTest() { ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0) .deleteFamily("fake-family") .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.deleteFamily(deleteFromFamily.getDeleteFromFamily().getFamilyName()); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); // Reset a build a cell. @@ -450,10 +438,10 @@ public void resetTest() { 100L, ByteString.copyFromUtf8("fake-value1-value2")) .setToken("fake-token") - .setEstimatedLowWatermarkInstant(FAKE_LOW_WATERMARK) + .setLowWatermarkTime(FAKE_LOW_WATERMARK) .build(); - changeStreamRecordBuilder.startUserMutationInstant( + changeStreamRecordBuilder.startUserMutation( ByteString.copyFromUtf8("key"), "fake-source-cluster-id", FAKE_COMMIT_TIMESTAMP, 0); changeStreamRecordBuilder.startCell( "fake-family", ByteString.copyFromUtf8("fake-qualifier"), 100L); @@ -461,8 +449,7 @@ public void resetTest() { changeStreamRecordBuilder.cellValue(ByteString.copyFromUtf8("-value2")); changeStreamRecordBuilder.finishCell(); assertThat( - changeStreamRecordBuilder.finishChangeStreamMutationInstant( - "fake-token", FAKE_LOW_WATERMARK)) + changeStreamRecordBuilder.finishChangeStreamMutation("fake-token", FAKE_LOW_WATERMARK)) .isEqualTo(expectedChangeStreamMutation); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java index a214d887e8..13e1bcb915 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadChangeStreamQueryTest.java @@ -121,8 +121,7 @@ public void streamPartitionTest() { @Test public void startTimeTest() { - ReadChangeStreamQuery query = - ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(FAKE_START_TIME); + ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).startTime(FAKE_START_TIME); Builder expectedProto = expectedProtoBuilder() @@ -137,8 +136,7 @@ public void startTimeTest() { @Test public void endTimeTest() { - ReadChangeStreamQuery query = - ReadChangeStreamQuery.create(TABLE_ID).endTimeInstant(FAKE_END_TIME); + ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID).endTime(FAKE_END_TIME); Builder expectedProto = expectedProtoBuilder() @@ -154,8 +152,7 @@ public void endTimeTest() { @Test public void heartbeatDurationTest() { ReadChangeStreamQuery query = - ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); + ReadChangeStreamQuery.create(TABLE_ID).heartbeatDuration(java.time.Duration.ofSeconds(5)); Builder expectedProto = expectedProtoBuilder().setHeartbeatDuration(Duration.newBuilder().setSeconds(5).build()); @@ -208,7 +205,7 @@ public void createWithStartTimeAndContinuationTokensTest() { ChangeStreamContinuationToken token = ChangeStreamContinuationToken.fromProto(tokenProto); ReadChangeStreamQuery query = ReadChangeStreamQuery.create(TABLE_ID) - .startTimeInstant(FAKE_START_TIME) + .startTime(FAKE_START_TIME) .continuationTokens(Collections.singletonList(token)); expect.expect(IllegalArgumentException.class); expect.expectMessage("startTime and continuationTokens can't be specified together"); @@ -233,8 +230,8 @@ public void serializationTest() throws IOException, ClassNotFoundException { ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") .continuationTokens(Collections.singletonList(token)) - .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); + .endTime(FAKE_END_TIME) + .heartbeatDuration(java.time.Duration.ofSeconds(5)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); @@ -302,9 +299,9 @@ public void testEquality() { ReadChangeStreamQuery request = ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") - .startTimeInstant(FAKE_START_TIME) - .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); + .startTime(FAKE_START_TIME) + .endTime(FAKE_END_TIME) + .heartbeatDuration(java.time.Duration.ofSeconds(5)); // ReadChangeStreamQuery#toProto should not change the ReadChangeStreamQuery instance state request.toProto(requestContext); @@ -312,26 +309,24 @@ public void testEquality() { .isEqualTo( ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("simple-begin", "simple-end") - .startTimeInstant(FAKE_START_TIME) - .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5))); + .startTime(FAKE_START_TIME) + .endTime(FAKE_END_TIME) + .heartbeatDuration(java.time.Duration.ofSeconds(5))); assertThat(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-1", "end-1")) .isNotEqualTo(ReadChangeStreamQuery.create(TABLE_ID).streamPartition("begin-2", "end-1")); - assertThat(ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(FAKE_START_TIME)) + assertThat(ReadChangeStreamQuery.create(TABLE_ID).startTime(FAKE_START_TIME)) .isNotEqualTo( - ReadChangeStreamQuery.create(TABLE_ID) - .startTimeInstant(Instant.ofEpochSecond(1L, 1001L))); - assertThat(ReadChangeStreamQuery.create(TABLE_ID).endTimeInstant(FAKE_END_TIME)) + ReadChangeStreamQuery.create(TABLE_ID).startTime(Instant.ofEpochSecond(1L, 1001L))); + assertThat(ReadChangeStreamQuery.create(TABLE_ID).endTime(FAKE_END_TIME)) .isNotEqualTo( - ReadChangeStreamQuery.create(TABLE_ID) - .endTimeInstant(Instant.ofEpochSecond(1L, 1001L))); + ReadChangeStreamQuery.create(TABLE_ID).endTime(Instant.ofEpochSecond(1L, 1001L))); assertThat( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5))) + .heartbeatDuration(java.time.Duration.ofSeconds(5))) .isNotEqualTo( ReadChangeStreamQuery.create(TABLE_ID) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(6))); + .heartbeatDuration(java.time.Duration.ofSeconds(6))); } @Test @@ -353,8 +348,8 @@ public void testClone() { ReadChangeStreamQuery.create(TABLE_ID) .streamPartition("begin", "end") .continuationTokens(Collections.singletonList(token)) - .endTimeInstant(FAKE_END_TIME) - .heartbeatDurationJavaTime(java.time.Duration.ofSeconds(5)); + .endTime(FAKE_END_TIME) + .heartbeatDuration(java.time.Duration.ofSeconds(5)); ReadChangeStreamRequest request = ReadChangeStreamRequest.newBuilder() .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java index cb6d4a9432..3e03236bb8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamRetryTest.java @@ -392,7 +392,7 @@ public void retryRstStreamExceptionTest() { private List getResults() { ReadChangeStreamQuery query = - ReadChangeStreamQuery.create(TABLE_ID).startTimeInstant(REQUEST_START_TIME); + ReadChangeStreamQuery.create(TABLE_ID).startTime(REQUEST_START_TIME); // Always give it this partition. We don't care. ServerStream actualRecords = client.readChangeStream(query.streamPartition(START_KEY_CLOSED, END_KEY_OPEN)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java index a27e948e5c..d28d39c3d9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/changestream/ReadChangeStreamUserCallableTest.java @@ -41,9 +41,9 @@ public void testRequestIsConverted() { ReadChangeStreamQuery query = ReadChangeStreamQuery.create("fake-table") .streamPartition("begin", "end") - .startTimeInstant(Instant.ofEpochSecond(0L, 1000L)) - .endTimeInstant(Instant.ofEpochSecond(0L, 2000L)) - .heartbeatDurationJavaTime(Duration.ofSeconds(1)); + .startTime(Instant.ofEpochSecond(0L, 1000L)) + .endTime(Instant.ofEpochSecond(0L, 2000L)) + .heartbeatDuration(Duration.ofSeconds(1)); callable.call(query); Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.toProto(REQUEST_CONTEXT)); } From 6122ff131e1b0d123f82c1c18e8295d8767e99b1 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Thu, 5 Dec 2024 23:04:30 +0000 Subject: [PATCH 25/30] chore: generate libraries at Thu Dec 5 23:02:28 UTC 2024 --- .../data/v2/models/DefaultChangeStreamRecordAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index b025bd96aa..c28482a0ab 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.data.v2.models; - import com.google.api.core.InternalApi; import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; From 70d67129cd539f0fc6cad795b18780cd779abf09 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Fri, 6 Dec 2024 13:15:45 -0500 Subject: [PATCH 26/30] ignore changes in beta and internal surface --- .../clirr-ignored-differences.xml | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigtable/clirr-ignored-differences.xml b/google-cloud-bigtable/clirr-ignored-differences.xml index bbc32d1c0e..748848c8fa 100644 --- a/google-cloud-bigtable/clirr-ignored-differences.xml +++ b/google-cloud-bigtable/clirr-ignored-differences.xml @@ -276,9 +276,24 @@ * - - 7012 + + 7006 + com/google/cloud/bigtable/data/v2/internal/* + *getTimestamp(*) + java.time.Instant + + + + 7006 com/google/cloud/bigtable/data/v2/models/sql/StructReader - java.time.Instant getTimestampInstant(*) + *getTimestamp(*) + java.time.Instant + + + + 7005 + com/google/cloud/bigtable/data/v2/models/sql/Statement$Builder + *setTimestampParam(java.lang.String, org.threeten.bp.Instant) + *setTimestampParam(java.lang.String, java.time.Instant) From 21c4614044cbf585e827b1f2498e6fdd284cf084 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Fri, 6 Dec 2024 13:46:33 -0500 Subject: [PATCH 27/30] change imports instead of using full qualified names --- .../data/v2/models/ChangeStreamRecordAdapter.java | 8 ++++---- .../v2/models/DefaultChangeStreamRecordAdapter.java | 5 ++--- .../google/cloud/bigtable/testproxy/CbtTestProxy.java | 11 ++++++----- .../bigtable/testproxy/StatementDeserializer.java | 5 +++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java index ba8e57cde8..9b892b14ea 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter.java @@ -19,6 +19,7 @@ import com.google.bigtable.v2.ReadChangeStreamResponse; import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange; import com.google.protobuf.ByteString; +import java.time.Instant; import javax.annotation.Nonnull; /** @@ -115,7 +116,7 @@ interface ChangeStreamRecordBuilder { void startUserMutation( @Nonnull ByteString rowKey, @Nonnull String sourceClusterId, - java.time.Instant commitTimestamp, + Instant commitTimestamp, int tieBreaker); /** @@ -123,8 +124,7 @@ void startUserMutation( * once. If called, the current change stream record must not include any close stream message * or heartbeat. */ - void startGcMutation( - @Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker); + void startGcMutation(@Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker); /** Called to add a DeleteFamily mod. */ void deleteFamily(@Nonnull String familyName); @@ -177,7 +177,7 @@ void mergeToCell( /** Called once per stream record to signal that all mods have been processed (unless reset). */ ChangeStreamRecordT finishChangeStreamMutation( - @Nonnull String token, java.time.Instant estimatedLowWatermark); + @Nonnull String token, Instant estimatedLowWatermark); /** Called when the current in progress change stream record should be dropped */ void reset(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java index c28482a0ab..217caa93f2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/DefaultChangeStreamRecordAdapter.java @@ -112,8 +112,7 @@ public void startUserMutation( /** {@inheritDoc} */ @Override - public void startGcMutation( - ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) { + public void startGcMutation(ByteString rowKey, Instant commitTimestamp, int tieBreaker) { this.changeStreamMutationBuilder = ChangeStreamMutation.createGcMutation(rowKey, commitTimestamp, tieBreaker); } @@ -176,7 +175,7 @@ public void finishCell() { /** {@inheritDoc} */ @Override public ChangeStreamRecord finishChangeStreamMutation( - String token, java.time.Instant estimatedLowWatermark) { + String token, Instant estimatedLowWatermark) { this.changeStreamMutationBuilder.setToken(token); this.changeStreamMutationBuilder.setLowWatermarkTime(estimatedLowWatermark); return this.changeStreamMutationBuilder.build(); diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java index 28e191c730..06e2967a68 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java @@ -60,6 +60,7 @@ import java.io.ByteArrayInputStream; import java.io.Closeable; import java.io.IOException; +import java.time.Duration; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -108,7 +109,7 @@ public static CbtTestProxy create() { * @param newTimeout The value that is used to set the timeout. */ private static BigtableDataSettings.Builder overrideTimeoutSetting( - java.time.Duration newTimeout, BigtableDataSettings.Builder settingsBuilder) { + Duration newTimeout, BigtableDataSettings.Builder settingsBuilder) { updateTimeout( settingsBuilder.stubSettings().bulkMutateRowsSettings().retrySettings(), newTimeout); @@ -127,8 +128,8 @@ private static BigtableDataSettings.Builder overrideTimeoutSetting( return settingsBuilder; } - private static void updateTimeout(RetrySettings.Builder settings, java.time.Duration newTimeout) { - java.time.Duration rpcTimeout = settings.getInitialRpcTimeoutDuration(); + private static void updateTimeout(RetrySettings.Builder settings, Duration newTimeout) { + Duration rpcTimeout = settings.getInitialRpcTimeoutDuration(); // TODO: this should happen in gax // Clamp the rpcTimeout to the overall timeout @@ -179,8 +180,8 @@ public synchronized void createClient( .setAppProfileId(request.getAppProfileId()); if (request.hasPerOperationTimeout()) { - java.time.Duration newTimeout = - java.time.Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); + Duration newTimeout = + Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); settingsBuilder = overrideTimeoutSetting(newTimeout, settingsBuilder); logger.info( String.format( diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java index b887f75043..b0d5a4d349 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java @@ -21,6 +21,7 @@ import com.google.cloud.bigtable.data.v2.models.sql.SqlType; import com.google.cloud.bigtable.data.v2.models.sql.Statement; import com.google.protobuf.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -156,8 +157,8 @@ static Object decodeArrayElement(Value value, SqlType elemType) { } } - private static java.time.Instant toInstant(Timestamp timestamp) { - return java.time.Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); + private static Instant toInstant(Timestamp timestamp) { + return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); } private static Date fromProto(com.google.type.Date proto) { From 253d3515587f0ccb9ef7100e53fb40dc413963ff Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Fri, 6 Dec 2024 18:49:05 +0000 Subject: [PATCH 28/30] chore: generate libraries at Fri Dec 6 18:47:10 UTC 2024 --- .../java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java index 06e2967a68..86eae14dee 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java @@ -180,8 +180,7 @@ public synchronized void createClient( .setAppProfileId(request.getAppProfileId()); if (request.hasPerOperationTimeout()) { - Duration newTimeout = - Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); + Duration newTimeout = Duration.ofMillis(Durations.toMillis(request.getPerOperationTimeout())); settingsBuilder = overrideTimeoutSetting(newTimeout, settingsBuilder); logger.info( String.format( From ad9fa48bba3107e1f35d9631aa268eb475c12051 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Fri, 6 Dec 2024 13:58:35 -0500 Subject: [PATCH 29/30] simplify imports --- .../v2/BigtableTableAdminClientTests.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java index 77c668a1f1..15713b17f1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java @@ -708,11 +708,11 @@ public void testCreateBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); assertThat(actualResult.getStartTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); assertThat(actualResult.getEndTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getExpireTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -760,14 +760,14 @@ public void testCreateHotBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); assertThat(actualResult.getStartTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); assertThat(actualResult.getEndTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getExpireTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.HOT); assertThat(actualResult.getHotToStandardTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -807,11 +807,11 @@ public void testGetBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); assertThat(actualResult.getExpireTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getStartTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); assertThat(actualResult.getEndTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); assertThat(actualResult.getState()).isEqualTo(Backup.State.fromProto(state)); assertThat(actualResult.getBackupType()).isEqualTo(Backup.BackupType.STANDARD); @@ -845,9 +845,9 @@ public void testUpdateBackup() { assertThat(actualResult.getId()).isEqualTo(BACKUP_ID); assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID); assertThat(actualResult.getExpireTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime))); assertThat(actualResult.getHotToStandardTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(hotToStandardTime))); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } @@ -1063,9 +1063,9 @@ public void testCopyBackup() { assertThat(actualResult.getSourceTableId()).isEqualTo(srcTableId); assertThat(actualResult.getSourceBackupId()).isEqualTo(srcBackupId); assertThat(actualResult.getStartTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(startTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime))); assertThat(actualResult.getEndTime()) - .isEqualTo(org.threeten.bp.Instant.ofEpochMilli(Timestamps.toMillis(endTime))); + .isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime))); assertThat(actualResult.getExpireTime()).isEqualTo(expireTime); assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes); } From 07c939aa6ebe41fe959affa623eedd0f69ba3da3 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Fri, 6 Dec 2024 13:59:56 -0500 Subject: [PATCH 30/30] fix test proxy i --- .../cloud/bigtable/testproxy/StatementDeserializer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java index b0d5a4d349..4eb5f47e3a 100644 --- a/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java +++ b/test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/StatementDeserializer.java @@ -90,10 +90,10 @@ static Statement toStatement(ExecuteQueryRequest request) { break; case TIMESTAMP_TYPE: if (value.getKindCase().equals(KindCase.KIND_NOT_SET)) { - statementBuilder.setTimestampParamInstant(name, null); + statementBuilder.setTimestampParam(name, null); } else if (value.getKindCase().equals(KindCase.TIMESTAMP_VALUE)) { Timestamp ts = value.getTimestampValue(); - statementBuilder.setTimestampParamInstant(name, toInstant(ts)); + statementBuilder.setTimestampParam(name, toInstant(ts)); } else { throw new IllegalArgumentException("Malformed timestamp value: " + value); }