diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/models/ExecutionStats.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/models/ExecutionStats.java index 52184a01a..6738d84e3 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/models/ExecutionStats.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/models/ExecutionStats.java @@ -15,25 +15,27 @@ */ package com.google.cloud.datastore.models; +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.cloud.Structs; import com.google.common.base.Objects; import java.util.Map; -import org.threeten.bp.Duration; /** Model class for {@link com.google.datastore.v1.ExecutionStats} */ @BetaApi public class ExecutionStats { private final long resultsReturned; - private final Duration executionDuration; + private final java.time.Duration executionDuration; private final long readOperations; private final Map debugStats; @InternalApi public ExecutionStats(com.google.datastore.v1.ExecutionStats proto) { this.resultsReturned = proto.getResultsReturned(); - this.executionDuration = Duration.ofNanos(proto.getExecutionDuration().getNanos()); + this.executionDuration = java.time.Duration.ofNanos(proto.getExecutionDuration().getNanos()); this.readOperations = proto.getReadOperations(); this.debugStats = Structs.asMap(proto.getDebugStats()); } @@ -51,8 +53,14 @@ public Map getDebugStats() { return debugStats; } + /** This method is obsolete. Use {@link #getExecutionDurationJavaTime()} instead. */ + @ObsoleteApi("Use getExecutionDurationJavaTime() instead") + public org.threeten.bp.Duration getExecutionDuration() { + return toThreetenDuration(getExecutionDurationJavaTime()); + } + /** Returns the total time to execute the query in the backend. */ - public Duration getExecutionDuration() { + public java.time.Duration getExecutionDurationJavaTime() { return executionDuration; } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java index 2723325ee..32bf9611c 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java @@ -16,9 +16,11 @@ package com.google.cloud.datastore.testing; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import static com.google.common.base.MoreObjects.firstNonNull; import com.google.api.core.InternalApi; +import com.google.api.core.ObsoleteApi; import com.google.cloud.NoCredentials; import com.google.cloud.ServiceOptions; import com.google.cloud.datastore.DatastoreOptions; @@ -38,7 +40,6 @@ import java.util.UUID; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; -import org.threeten.bp.Duration; /** * Utility to start and stop local Google Cloud Datastore emulators. @@ -307,6 +308,14 @@ public void reset() throws IOException { sendPostRequest("/reset"); } + /** This method is obsolete. Use {@link #stopDuration(java.time.Duration)} instead */ + @ObsoleteApi("Use stopDuration(java.time.Duration) instead") + @Override + public void stop(org.threeten.bp.Duration timeout) + throws IOException, InterruptedException, TimeoutException { + stopDuration(toJavaTimeDuration(timeout)); + } + /** * Stops the Datastore emulator. * @@ -319,15 +328,16 @@ public void reset() throws IOException { * this value high to ensure proper shutdown, like 5 seconds or more. */ @Override - public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException { + public void stopDuration(java.time.Duration timeout) + throws IOException, InterruptedException, TimeoutException { sendPostRequest("/shutdown"); - waitForProcess(timeout); + waitForProcessDuration(timeout); deleteRecursively(gcdPath); } /** - * Stops the Datastore emulator. The same as {@link #stop(Duration)} but with timeout duration of - * 20 seconds. + * Stops the Datastore emulator. The same as {@link #stopDuration(java.time.Duration)} but with + * timeout duration of 20 seconds. * *

It is important to stop the emulator. Since the emulator runs in its own process, not * stopping it might cause it to become orphan. @@ -335,7 +345,7 @@ public void stop(Duration timeout) throws IOException, InterruptedException, Tim *

It is not required to call {@link #reset()} before {@code stop()}. */ public void stop() throws IOException, InterruptedException, TimeoutException { - stop(Duration.ofSeconds(20)); + stopDuration(java.time.Duration.ofSeconds(20)); } static void deleteRecursively(Path path) throws IOException { diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java index d88e1d1ec..459278f25 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java @@ -68,6 +68,7 @@ import com.google.datastore.v1.TransactionOptions; import com.google.protobuf.ByteString; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -87,7 +88,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 DatastoreTest { @@ -193,7 +193,7 @@ public void setUp() { @AfterClass public static void afterClass() throws IOException, InterruptedException, TimeoutException { - helper.stop(Duration.ofMinutes(1)); + helper.stopDuration(Duration.ofMinutes(1)); } @Test diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java index c012d28c9..bf0c20dce 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java @@ -81,6 +81,7 @@ import com.google.common.truth.Truth; import com.google.datastore.v1.TransactionOptions; import com.google.datastore.v1.TransactionOptions.ReadOnly; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -103,7 +104,6 @@ import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.threeten.bp.Duration; @RunWith(Parameterized.class) public class ITDatastoreTest { @@ -674,7 +674,7 @@ private void assertExecutionStats( Truth.assertThat(debugStats.get("index_entries_scanned")) .isEqualTo(expectedIndexEntriesScanned); - Duration executionDuration = executionStats.getExecutionDuration(); + Duration executionDuration = executionStats.getExecutionDurationJavaTime(); Truth.assertThat(executionDuration).isIn(Range.greaterThan(Duration.ofMillis(0))); long readOperations = executionStats.getReadOperations(); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/models/ExecutionStatsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/models/ExecutionStatsTest.java index 4706e3b86..a0e778cee 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/models/ExecutionStatsTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/models/ExecutionStatsTest.java @@ -41,8 +41,8 @@ public class ExecutionStatsTest { @Test public void testModel() { Truth.assertThat(executionStats.getDebugStats()).isEqualTo(Structs.asMap(struct)); - Truth.assertThat(executionStats.getExecutionDuration()) - .isEqualTo(org.threeten.bp.Duration.ofNanos(duration.getNanos())); + Truth.assertThat(executionStats.getExecutionDurationJavaTime()) + .isEqualTo(java.time.Duration.ofNanos(duration.getNanos())); Truth.assertThat(executionStats.getReadOperations()).isEqualTo(2); Truth.assertThat(executionStats.getResultsReturned()).isEqualTo(3); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/ITLocalDatastoreHelperTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/ITLocalDatastoreHelperTest.java index 3ebd3ef4a..dfa2255a0 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/ITLocalDatastoreHelperTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/ITLocalDatastoreHelperTest.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.time.Duration; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Assert; @@ -39,7 +40,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 ITLocalDatastoreHelperTest { @@ -178,7 +178,7 @@ public void testStartStopReset() throws IOException, InterruptedException, Timeo assertNotNull(datastore.get(key)); helper.reset(); assertNull(datastore.get(key)); - helper.stop(Duration.ofMinutes(1)); + helper.stopDuration(Duration.ofMinutes(1)); datastore.get(key); Assert.fail(); } catch (DatastoreException ex) { @@ -198,7 +198,7 @@ public void testStartStopResetWithBuilder() assertNotNull(datastore.get(key)); helper.reset(); assertNull(datastore.get(key)); - helper.stop(Duration.ofMinutes(1)); + helper.stopDuration(Duration.ofMinutes(1)); datastore.get(key); Assert.fail(); } catch (DatastoreException ex) { diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java index 6167cedca..a4b389a1e 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java @@ -27,9 +27,9 @@ import com.google.cloud.datastore.StructuredQuery; import com.google.cloud.http.HttpTransportOptions; import io.opentelemetry.sdk.OpenTelemetrySdk; +import java.time.Duration; import java.util.UUID; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Utility to create a remote datastore configuration for testing. Datastore options can be obtained @@ -110,13 +110,13 @@ public static RemoteDatastoreHelper create(String databaseId) { private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxAttempts(10) - .setMaxRetryDelay(Duration.ofMillis(30000L)) - .setTotalTimeout(Duration.ofMillis(120000L)) - .setInitialRetryDelay(Duration.ofMillis(250L)) + .setMaxRetryDelayDuration(Duration.ofMillis(30000L)) + .setTotalTimeoutDuration(Duration.ofMillis(120000L)) + .setInitialRetryDelayDuration(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) - .setInitialRpcTimeout(Duration.ofMillis(120000L)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) - .setMaxRpcTimeout(Duration.ofMillis(120000L)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(120000L)) .build(); } } diff --git a/samples/snippets/src/test/java/com/google/datastore/snippets/ConceptsTest.java b/samples/snippets/src/test/java/com/google/datastore/snippets/ConceptsTest.java index 045b16a9a..33aa63ab4 100644 --- a/samples/snippets/src/test/java/com/google/datastore/snippets/ConceptsTest.java +++ b/samples/snippets/src/test/java/com/google/datastore/snippets/ConceptsTest.java @@ -77,7 +77,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; /** Contains Cloud Datastore snippets demonstrating concepts for documentation. */ @RunWith(JUnit4.class) @@ -147,7 +146,7 @@ public void tearDown() throws Exception { */ @AfterClass public static void afterClass() throws IOException, InterruptedException, TimeoutException { - HELPER.stop(Duration.ofMinutes(1)); + HELPER.stopDuration(java.time.Duration.ofMinutes(1)); } private void assertValidKey(Key taskKey) {