From 4c0332ec55ba99c39572ef608ea508e55547ccf7 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 20 May 2016 15:30:26 +0200 Subject: [PATCH] Move Clock out of ServiceOptions, use it in RetryHelper (#954) * Move Clock out of ServiceOptions, use it in RetryHelper * Always pass options.clock() to RetryHelper.runWithRetries --- .../google/cloud/bigquery/BigQueryImpl.java | 34 ++--- .../cloud/bigquery/TableDataWriteChannel.java | 2 +- .../com/google/cloud/compute/ComputeImpl.java | 130 +++++++++--------- .../src/main/java/com/google/cloud/Clock.java | 59 ++++++++ .../java/com/google/cloud/RetryHelper.java | 23 ++-- .../java/com/google/cloud/ServiceOptions.java | 40 ------ .../com/google/cloud/RetryHelperTest.java | 22 ++- .../com/google/cloud/ServiceOptionsTest.java | 1 - .../google/cloud/datastore/DatastoreImpl.java | 12 +- .../java/com/google/cloud/dns/DnsImpl.java | 18 +-- .../com/google/cloud/dns/DnsImplTest.java | 4 +- .../resourcemanager/ResourceManagerImpl.java | 18 +-- .../google/cloud/storage/BlobReadChannel.java | 2 +- .../cloud/storage/BlobWriteChannel.java | 2 +- .../com/google/cloud/storage/CopyWriter.java | 2 +- .../com/google/cloud/storage/StorageImpl.java | 26 ++-- .../google/cloud/storage/StorageImplTest.java | 4 +- 17 files changed, 206 insertions(+), 193 deletions(-) create mode 100644 gcloud-java-core/src/main/java/com/google/cloud/Clock.java diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 62a72647beff..d8dfcaea445d 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -164,7 +164,7 @@ public Dataset create(DatasetInfo dataset, DatasetOption... options) { public com.google.api.services.bigquery.model.Dataset call() { return bigQueryRpc.create(datasetPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -182,7 +182,7 @@ public Table create(TableInfo table, TableOption... options) { public com.google.api.services.bigquery.model.Table call() { return bigQueryRpc.create(tablePb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -200,7 +200,7 @@ public Job create(JobInfo job, JobOption... options) { public com.google.api.services.bigquery.model.Job call() { return bigQueryRpc.create(jobPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -221,7 +221,7 @@ public Dataset getDataset(final DatasetId datasetId, DatasetOption... options) { public com.google.api.services.bigquery.model.Dataset call() { return bigQueryRpc.getDataset(datasetId.dataset(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Dataset.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); @@ -244,7 +244,7 @@ private static Page listDatasets(final BigQueryOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listDatasets(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); return new PageImpl<>(new DatasetPageFetcher(serviceOptions, cursor, optionsMap), cursor, Iterables.transform(result.y(), @@ -273,7 +273,7 @@ public boolean delete(final DatasetId datasetId, DatasetDeleteOption... options) public Boolean call() { return bigQueryRpc.deleteDataset(datasetId.dataset(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -292,7 +292,7 @@ public boolean delete(final TableId tableId) { public Boolean call() { return bigQueryRpc.deleteTable(tableId.dataset(), tableId.table()); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -310,7 +310,7 @@ public Dataset update(DatasetInfo dataset, DatasetOption... options) { public com.google.api.services.bigquery.model.Dataset call() { return bigQueryRpc.patch(datasetPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -328,7 +328,7 @@ public Table update(TableInfo table, TableOption... options) { public com.google.api.services.bigquery.model.Table call() { return bigQueryRpc.patch(tablePb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -349,7 +349,7 @@ public Table getTable(final TableId tableId, TableOption... options) { public com.google.api.services.bigquery.model.Table call() { return bigQueryRpc.getTable(tableId.dataset(), tableId.table(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Table.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); @@ -377,7 +377,7 @@ private static Page listTables(final String datasetId, final BigQueryOpti call() { return serviceOptions.rpc().listTables(datasetId, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable
tables = Iterables.transform(result.y(), new Function() { @@ -432,7 +432,7 @@ public BigQueryRpc.Tuple> call() { return serviceOptions.rpc() .listTableData(tableId.dataset(), tableId.table(), optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); return new PageImpl<>(new TableDataPageFetcher(tableId, serviceOptions, cursor, optionsMap), cursor, transformTableData(result.y())); @@ -467,7 +467,7 @@ public Job getJob(final JobId jobId, JobOption... options) { public com.google.api.services.bigquery.model.Job call() { return bigQueryRpc.getJob(jobId.job(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Job.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); @@ -489,7 +489,7 @@ private static Page listJobs(final BigQueryOptions serviceOptions, call() { return serviceOptions.rpc().listJobs(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable jobs = Iterables.transform(result.y(), new Function() { @@ -514,7 +514,7 @@ public boolean cancel(final JobId jobId) { public Boolean call() { return bigQueryRpc.cancel(jobId.job()); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } @@ -529,7 +529,7 @@ public QueryResponse query(final QueryRequest request) { public com.google.api.services.bigquery.model.QueryResponse call() { return bigQueryRpc.query(request.setProjectId(options().projectId()).toPb()); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); QueryResponse.Builder builder = QueryResponse.builder(); JobId completeJobId = JobId.fromPb(results.getJobReference()); builder.jobId(completeJobId); @@ -574,7 +574,7 @@ private static QueryResponse getQueryResults(final JobId jobId, public GetQueryResultsResponse call() { return serviceOptions.rpc().getQueryResults(jobId.job(), optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); QueryResponse.Builder builder = QueryResponse.builder(); JobId completeJobId = JobId.fromPb(results.getJobReference()); builder.jobId(completeJobId); diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java index 9319b59cfea3..d56358f86e98 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java +++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java @@ -47,7 +47,7 @@ protected void flushBuffer(final int length, final boolean last) { public void run() { options().rpc().write(uploadId(), buffer(), 0, position(), length, last); } - }), options().retryParams(), BigQueryImpl.EXCEPTION_HANDLER); + }), options().retryParams(), BigQueryImpl.EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw BigQueryException.translateAndThrow(e); } diff --git a/gcloud-java-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java b/gcloud-java-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java index c0846749d326..23501f93bcc6 100644 --- a/gcloud-java-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java +++ b/gcloud-java-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java @@ -471,7 +471,7 @@ public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... optio public com.google.api.services.compute.model.DiskType call() { return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.type(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : DiskType.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -499,7 +499,7 @@ private static Page listDiskTypes(final String zone, Iterable> call() { return serviceOptions.rpc().listDiskTypes(zone, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable diskTypes = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -533,7 +533,7 @@ private static Page listDiskTypes(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listDiskTypes(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable diskTypes = Iterables.transform(result.y(), new Function() { @@ -559,7 +559,7 @@ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOp public com.google.api.services.compute.model.MachineType call() { return computeRpc.getMachineType(machineType.zone(), machineType.type(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : MachineType.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -587,7 +587,7 @@ private static Page listMachineTypes(final String zone, Iterable> call() { return serviceOptions.rpc().listMachineTypes(zone, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable machineTypes = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -622,7 +622,7 @@ private static Page listMachineTypes(final ComputeOptions serviceOp Iterable> call() { return serviceOptions.rpc().listMachineTypes(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable machineTypes = Iterables.transform(result.y(), new Function() { @@ -650,7 +650,7 @@ public Region getRegion(final String region, RegionOption... options) { public com.google.api.services.compute.model.Region call() { return computeRpc.getRegion(region, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Region.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -673,7 +673,7 @@ private static Page listRegions(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listRegions(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable regions = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -701,7 +701,7 @@ public Zone getZone(final String zone, ZoneOption... options) { public com.google.api.services.compute.model.Zone call() { return computeRpc.getZone(zone, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Zone.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -724,7 +724,7 @@ private static Page listZones(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listZones(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable zones = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -757,7 +757,7 @@ public License getLicense(LicenseId license, LicenseOption... options) { public com.google.api.services.compute.model.License call() { return computeRpc.getLicense(completeId.project(), completeId.license(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : License.fromPb(answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -787,7 +787,7 @@ public com.google.api.services.compute.model.Operation call() { throw new IllegalArgumentException("Unexpected operation identity type"); } } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -820,7 +820,7 @@ private static Page listGlobalOperations(final ComputeOptions service Iterable> call() { return serviceOptions.rpc().listGlobalOperations(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -848,7 +848,7 @@ private static Page listRegionOperations(final String region, Iterable> call() { return serviceOptions.rpc().listRegionOperations(region, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -876,7 +876,7 @@ private static Page listZoneOperations(final String zone, Iterable> call() { return serviceOptions.rpc().listZoneOperations(zone, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -909,7 +909,7 @@ public Boolean call() { throw new IllegalArgumentException("Unexpected operation identity type"); } } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } @@ -934,7 +934,7 @@ public com.google.api.services.compute.model.Address call() { throw new IllegalArgumentException("Unexpected address identity type"); } } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Address.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -962,7 +962,7 @@ public com.google.api.services.compute.model.Operation call() { throw new IllegalArgumentException("Unexpected address identity type"); } } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } @@ -994,7 +994,7 @@ private static Page
listGlobalAddresses(final ComputeOptions serviceOpt Iterable> call() { return serviceOptions.rpc().listGlobalAddresses(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable
operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1022,7 +1022,7 @@ private static Page
listRegionAddresses(final String region, Iterable> call() { return serviceOptions.rpc().listRegionAddresses(region, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable
operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1050,7 +1050,7 @@ private static Page
listAddresses(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listAddresses(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable
operations = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1087,7 +1087,7 @@ public com.google.api.services.compute.model.Operation call() { throw new IllegalArgumentException("Unexpected address identity type"); } } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1107,7 +1107,7 @@ public com.google.api.services.compute.model.Operation call() { completeSnapshot.sourceDisk().disk(), completeSnapshot.snapshotId().snapshot(), completeSnapshot.description(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1124,7 +1124,7 @@ public Snapshot getSnapshot(final String snapshot, SnapshotOption... options) { public com.google.api.services.compute.model.Snapshot call() { return computeRpc.getSnapshot(snapshot, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Snapshot.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1147,7 +1147,7 @@ private static Page listSnapshots(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listSnapshots(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable snapshots = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1180,7 +1180,7 @@ public Operation deleteSnapshot(final String snapshot, OperationOption... option public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteSnapshot(snapshot, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1198,7 +1198,7 @@ public Operation create(ImageInfo image, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.createImage(completeImage.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1217,7 +1217,7 @@ public com.google.api.services.compute.model.Image call() { return computeRpc.getImage(completeImageId.project(), completeImageId.image(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Image.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1245,7 +1245,7 @@ private static Page listImages(final String project, final ComputeOptions Iterable> call() { return serviceOptions.rpc().listImages(project, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable images = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1274,7 +1274,7 @@ public Operation deleteImage(ImageId image, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteImage(completeId.project(), completeId.image(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1294,7 +1294,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.deprecateImage(completeId.project(), completeId.image(), deprecationStatus.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1311,7 +1311,7 @@ public Disk getDisk(final DiskId diskId, DiskOption... options) { public com.google.api.services.compute.model.Disk call() { return computeRpc.getDisk(diskId.zone(), diskId.disk(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Disk.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1330,7 +1330,7 @@ public Operation create(final DiskInfo disk, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.createDisk(disk.diskId().zone(), diskPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } @@ -1362,7 +1362,7 @@ private static Page listDisks(final String zone, final ComputeOptions serv Iterable> call() { return serviceOptions.rpc().listDisks(zone, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable disks = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1390,7 +1390,7 @@ private static Page listDisks(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listDisks(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable disks = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1412,7 +1412,7 @@ public Operation deleteDisk(final DiskId disk, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteDisk(disk.zone(), disk.disk(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1429,7 +1429,7 @@ public Operation resize(final DiskId disk, final long sizeGb, OperationOption... public com.google.api.services.compute.model.Operation call() { return computeRpc.resizeDisk(disk.zone(), disk.disk(), sizeGb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1447,7 +1447,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.createSubnetwork(completeSubnetwork.subnetworkId().region(), completeSubnetwork.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1465,7 +1465,7 @@ public com.google.api.services.compute.model.Subnetwork call() { return computeRpc.getSubnetwork(subnetworkId.region(), subnetworkId.subnetwork(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Subnetwork.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1498,7 +1498,7 @@ private static Page listSubnetworks(final String region, Iterable> call() { return serviceOptions.rpc().listSubnetworks(region, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable subnetworks = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1526,7 +1526,7 @@ private static Page listSubnetworks(final ComputeOptions serviceOpti Iterable> call() { return serviceOptions.rpc().listSubnetworks(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable subnetworks = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1549,7 +1549,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteSubnetwork(subnetwork.region(), subnetwork.subnetwork(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1567,7 +1567,7 @@ public Operation create(NetworkInfo network, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.createNetwork(completeNetwork.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1584,7 +1584,7 @@ public Network getNetwork(final String network, NetworkOption... options) { public com.google.api.services.compute.model.Network call() { return computeRpc.getNetwork(network, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Network.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1607,7 +1607,7 @@ private static Page listNetworks(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listNetworks(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable networks = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1635,7 +1635,7 @@ public Operation deleteNetwork(final NetworkId network, OperationOption... optio public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteNetwork(network.network(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1659,7 +1659,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.createInstance(completeInstance.instanceId().zone(), completeInstance.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1676,7 +1676,7 @@ public Instance getInstance(final InstanceId instance, InstanceOption... options public com.google.api.services.compute.model.Instance call() { return computeRpc.getInstance(instance.zone(), instance.instance(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Instance.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1709,7 +1709,7 @@ private static Page listInstances(final String zone, Iterable> call() { return serviceOptions.rpc().listInstances(zone, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable instances = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1737,7 +1737,7 @@ private static Page listInstances(final ComputeOptions serviceOptions, Iterable> call() { return serviceOptions.rpc().listInstances(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable instances = Iterables.transform( result.y() == null ? ImmutableList.of() @@ -1759,7 +1759,7 @@ public Operation deleteInstance(final InstanceId instance, OperationOption... op public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteInstance(instance.zone(), instance.instance(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1778,7 +1778,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.addAccessConfig(instance.zone(), instance.instance(), networkInterface, accessConfig.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1797,7 +1797,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.attachDisk(instance.zone(), instance.instance(), completeDisk.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1838,7 +1838,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteAccessConfig(instance.zone(), instance.instance(), networkInterface, accessConfig, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1857,7 +1857,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.detachDisk(instance.zone(), instance.instance(), deviceName, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1873,7 +1873,7 @@ public String call() { return computeRpc.getSerialPortOutput(instance.zone(), instance.instance(), port, optionMap()); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } @@ -1888,7 +1888,7 @@ public String call() { return computeRpc.getSerialPortOutput(instance.zone(), instance.instance(), null, optionMap()); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } @@ -1904,7 +1904,7 @@ public Operation reset(final InstanceId instance, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.reset(instance.zone(), instance.instance(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1923,7 +1923,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.setDiskAutoDelete(instance.zone(), instance.instance(), deviceName, autoDelete, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1943,7 +1943,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.setMachineType(instance.zone(), instance.instance(), machineTypeUrl, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1962,7 +1962,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.setMetadata(instance.zone(), instance.instance(), metadata.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1981,7 +1981,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.setScheduling(instance.zone(), instance.instance(), schedulingOptions.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -1999,7 +1999,7 @@ public com.google.api.services.compute.model.Operation call() { return computeRpc.setTags(instance.zone(), instance.instance(), tags.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -2016,7 +2016,7 @@ public Operation start(final InstanceId instance, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.start(instance.zone(), instance.instance(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); @@ -2033,7 +2033,7 @@ public Operation stop(final InstanceId instance, OperationOption... options) { public com.google.api.services.compute.model.Operation call() { return computeRpc.stop(instance.zone(), instance.instance(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); diff --git a/gcloud-java-core/src/main/java/com/google/cloud/Clock.java b/gcloud-java-core/src/main/java/com/google/cloud/Clock.java new file mode 100644 index 000000000000..447200b03bf4 --- /dev/null +++ b/gcloud-java-core/src/main/java/com/google/cloud/Clock.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +/** + * A class providing access to the current time in milliseconds. This class is mainly used for + * testing and will be replaced by Java8's {@code java.time.Clock}. + * + *

Implementations should implement {@code Serializable} wherever possible and must document + * whether or not they do support serialization. + */ +public abstract class Clock { + + private static final Clock DEFAULT_TIME_SOURCE = new DefaultClock(); + + /** + * Returns current time in milliseconds according to this clock. + */ + public abstract long millis(); + + /** + * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time + * in milliseconds. + */ + public static Clock defaultClock() { + return DEFAULT_TIME_SOURCE; + } + + private static class DefaultClock extends Clock implements Serializable { + + private static final long serialVersionUID = -5077300394286703864L; + + @Override + public long millis() { + return System.currentTimeMillis(); + } + + private Object readResolve() throws ObjectStreamException { + return DEFAULT_TIME_SOURCE; + } + } +} diff --git a/gcloud-java-core/src/main/java/com/google/cloud/RetryHelper.java b/gcloud-java-core/src/main/java/com/google/cloud/RetryHelper.java index 48bd5fcf9324..bd59070d4754 100644 --- a/gcloud-java-core/src/main/java/com/google/cloud/RetryHelper.java +++ b/gcloud-java-core/src/main/java/com/google/cloud/RetryHelper.java @@ -21,12 +21,10 @@ import static java.lang.StrictMath.min; import static java.lang.StrictMath.pow; import static java.lang.StrictMath.random; -import static java.util.concurrent.TimeUnit.MILLISECONDS; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; -import com.google.common.base.Stopwatch; import java.io.InterruptedIOException; import java.nio.channels.ClosedByInterruptException; @@ -45,7 +43,7 @@ public class RetryHelper { private static final Logger log = Logger.getLogger(RetryHelper.class.getName()); - private final Stopwatch stopwatch; + private final Clock clock; private final Callable callable; private final RetryParams params; private final ExceptionHandler exceptionHandler; @@ -153,10 +151,10 @@ static Context getContext() { @VisibleForTesting RetryHelper(Callable callable, RetryParams params, ExceptionHandler exceptionHandler, - Stopwatch stopwatch) { + Clock clock) { this.callable = checkNotNull(callable); this.params = checkNotNull(params); - this.stopwatch = checkNotNull(stopwatch); + this.clock = checkNotNull(clock); this.exceptionHandler = checkNotNull(exceptionHandler); exceptionHandler.verifyCaller(callable); } @@ -165,7 +163,7 @@ static Context getContext() { public String toString() { ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); toStringHelper.add("params", params); - toStringHelper.add("stopwatch", stopwatch); + toStringHelper.add("clock", clock); toStringHelper.add("attemptNumber", attemptNumber); toStringHelper.add("callable", callable); toStringHelper.add("exceptionHandler", exceptionHandler); @@ -173,7 +171,7 @@ public String toString() { } private V doRetry() throws RetryHelperException { - stopwatch.start(); + long start = clock.millis(); while (true) { attemptNumber++; Exception exception; @@ -196,7 +194,7 @@ private V doRetry() throws RetryHelperException { } if (attemptNumber >= params.retryMaxAttempts() || attemptNumber >= params.retryMinAttempts() - && stopwatch.elapsed(MILLISECONDS) >= params.totalRetryPeriodMillis()) { + && clock.millis() - start >= params.totalRetryPeriodMillis()) { throw new RetriesExhaustedException(this + ": Too many failures, giving up", exception); } long sleepDurationMillis = getSleepDuration(params, attemptNumber); @@ -234,13 +232,12 @@ public static V runWithRetries(Callable callable) throws RetryHelperExcep public static V runWithRetries(Callable callable, RetryParams params, ExceptionHandler exceptionHandler) throws RetryHelperException { - return runWithRetries(callable, params, exceptionHandler, Stopwatch.createUnstarted()); + return runWithRetries(callable, params, exceptionHandler, Clock.defaultClock()); } - @VisibleForTesting - static V runWithRetries(Callable callable, RetryParams params, - ExceptionHandler exceptionHandler, Stopwatch stopwatch) throws RetryHelperException { - RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, stopwatch); + public static V runWithRetries(Callable callable, RetryParams params, + ExceptionHandler exceptionHandler, Clock clock) throws RetryHelperException { + RetryHelper retryHelper = new RetryHelper<>(callable, params, exceptionHandler, clock); Context previousContext = getContext(); setContext(new Context(retryHelper)); try { diff --git a/gcloud-java-core/src/main/java/com/google/cloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/cloud/ServiceOptions.java index 194f61b45c42..d2f648b01fe5 100644 --- a/gcloud-java-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/gcloud-java-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -43,7 +43,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; -import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.Method; import java.net.HttpURLConnection; @@ -125,45 +124,6 @@ public HttpTransport create() { } } - /** - * A class providing access to the current time in milliseconds. This class is mainly used for - * testing and will be replaced by Java8's {@code java.time.Clock}. - * - *

Implementations should implement {@code Serializable} wherever possible and must document - * whether or not they do support serialization. - */ - public abstract static class Clock { - - private static final ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock(); - - /** - * Returns current time in milliseconds according to this clock. - */ - public abstract long millis(); - - /** - * Returns the default clock. Default clock uses {@link System#currentTimeMillis()} to get time - * in milliseconds. - */ - public static ServiceOptions.Clock defaultClock() { - return DEFAULT_TIME_SOURCE; - } - - private static class DefaultClock extends ServiceOptions.Clock implements Serializable { - - private static final long serialVersionUID = -5077300394286703864L; - - @Override - public long millis() { - return System.currentTimeMillis(); - } - - private Object readResolve() throws ObjectStreamException { - return DEFAULT_TIME_SOURCE; - } - } - } - /** * Builder for {@code ServiceOptions}. * diff --git a/gcloud-java-core/src/test/java/com/google/cloud/RetryHelperTest.java b/gcloud-java-core/src/test/java/com/google/cloud/RetryHelperTest.java index 3887cecd6a83..fcb404a4624f 100644 --- a/gcloud-java-core/src/test/java/com/google/cloud/RetryHelperTest.java +++ b/gcloud-java-core/src/test/java/com/google/cloud/RetryHelperTest.java @@ -24,8 +24,6 @@ import com.google.cloud.RetryHelper.NonRetriableException; import com.google.cloud.RetryHelper.RetriesExhaustedException; -import com.google.common.base.Stopwatch; -import com.google.common.base.Ticker; import org.junit.Test; @@ -157,24 +155,24 @@ public void testTriesNoMoreThanMaxTimes() { } } - private static class FakeTicker extends Ticker { - private final AtomicLong nanos = new AtomicLong(); + private static class FakeClock extends Clock { - // Advances the ticker value by {@code time} in {@code timeUnit}. + private final AtomicLong millis = new AtomicLong(); + + // Advances the clock value by {@code time} in {@code timeUnit}. void advance(long time, TimeUnit timeUnit) { - nanos.addAndGet(timeUnit.toNanos(time)); + millis.addAndGet(timeUnit.toMillis(time)); } @Override - public long read() { - return nanos.get(); + public long millis() { + return millis.get(); } } @Test public void testTriesNoMoreLongerThanTotalRetryPeriod() { - final FakeTicker ticker = new FakeTicker(); - Stopwatch stopwatch = Stopwatch.createUnstarted(ticker); + final FakeClock fakeClock = new FakeClock(); // The 8th attempt (after min and before max) will trigger a 1 second (virtual) delay exceeding // total retry period which is set just under 1 second. Test occurs faster than realtime. RetryParams params = RetryParams.builder().initialRetryDelayMillis(0) @@ -190,11 +188,11 @@ public void testTriesNoMoreLongerThanTotalRetryPeriod() { @Override public void run() { timesCalled.incrementAndGet(); if (timesCalled.get() == sleepOnAttempt) { - ticker.advance(1000, TimeUnit.MILLISECONDS); + fakeClock.advance(1000, TimeUnit.MILLISECONDS); } throw new RuntimeException(); } - }), params, handler, stopwatch); + }), params, handler, fakeClock); fail(); } catch (RetriesExhaustedException expected) { // verify timesCalled diff --git a/gcloud-java-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/gcloud-java-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index b6f7a5453ddc..bcbecbe3c6cb 100644 --- a/gcloud-java-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/gcloud-java-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.cloud.ServiceOptions.Clock; import com.google.cloud.ServiceOptions.DefaultHttpTransportFactory; import com.google.cloud.ServiceOptions.HttpTransportFactory; import com.google.cloud.spi.ServiceRpcFactory; diff --git a/gcloud-java-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java b/gcloud-java-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java index 2aa0638bfa7c..07ca76d2118f 100644 --- a/gcloud-java-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java +++ b/gcloud-java-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java @@ -91,7 +91,7 @@ com.google.datastore.v1beta3.RunQueryResponse runQuery( throws DatastoreException { return datastoreRpc.runQuery(requestPb); } - }, retryParams, EXCEPTION_HANDLER); + }, retryParams, EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } @@ -129,7 +129,7 @@ com.google.datastore.v1beta3.AllocateIdsResponse allocateIds( throws DatastoreException { return datastoreRpc.allocateIds(requestPb); } - }, retryParams, EXCEPTION_HANDLER); + }, retryParams, EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } @@ -285,7 +285,7 @@ com.google.datastore.v1beta3.LookupResponse lookup( throws DatastoreException { return datastoreRpc.lookup(requestPb); } - }, retryParams, EXCEPTION_HANDLER); + }, retryParams, EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } @@ -365,7 +365,7 @@ public com.google.datastore.v1beta3.CommitResponse call() throws DatastoreExcept } }, retryParams, - EXCEPTION_HANDLER); + EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } @@ -388,7 +388,7 @@ public com.google.datastore.v1beta3.BeginTransactionResponse call() } }, retryParams, - EXCEPTION_HANDLER); + EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } @@ -408,7 +408,7 @@ void rollback(final com.google.datastore.v1beta3.RollbackRequest requestPb) { datastoreRpc.rollback(requestPb); return null; } - }, retryParams, EXCEPTION_HANDLER); + }, retryParams, EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw DatastoreException.translateAndThrow(e); } diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/DnsImpl.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/DnsImpl.java index be0e8621cf41..1bf2a0c1d8cb 100644 --- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/DnsImpl.java +++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/DnsImpl.java @@ -135,7 +135,7 @@ private static Page listZones(final DnsOptions serviceOptions, public DnsRpc.ListResult call() { return rpc.listZones(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.pageToken(); // transform that list into zone objects Iterable zones = result.results() == null ? ImmutableList.of() @@ -163,7 +163,7 @@ private static Page listChangeRequests(final String zoneName, public DnsRpc.ListResult call() { return rpc.listChangeRequests(zoneName, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.pageToken(); // transform that list into change request objects Iterable changes = result.results() == null @@ -193,7 +193,7 @@ private static Page listRecordSets(final String zoneName, public DnsRpc.ListResult call() { return rpc.listRecordSets(zoneName, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.pageToken(); // transform that list into record sets Iterable recordSets = result.results() == null @@ -216,7 +216,7 @@ public Zone create(final ZoneInfo zoneInfo, Dns.ZoneOption... options) { public ManagedZone call() { return dnsRpc.create(zoneInfo.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Zone.fromPb(this, answer); } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); @@ -233,7 +233,7 @@ public Zone getZone(final String zoneName, Dns.ZoneOption... options) { public ManagedZone call() { return dnsRpc.getZone(zoneName, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Zone.fromPb(this, answer); } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); @@ -248,7 +248,7 @@ public boolean delete(final String zoneName) { public Boolean call() { return dnsRpc.deleteZone(zoneName); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); } @@ -264,7 +264,7 @@ public ProjectInfo getProject(Dns.ProjectOption... fields) { public Project call() { return dnsRpc.getProject(optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : ProjectInfo.fromPb(answer); // should never be null } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); @@ -282,7 +282,7 @@ public ChangeRequest applyChangeRequest(final String zoneName, public Change call() { return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer); // not null } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); @@ -300,7 +300,7 @@ public ChangeRequest getChangeRequest(final String zoneName, final String change public Change call() { return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer); } catch (RetryHelper.RetryHelperException ex) { throw DnsException.translateAndThrow(ex); diff --git a/gcloud-java-dns/src/test/java/com/google/cloud/dns/DnsImplTest.java b/gcloud-java-dns/src/test/java/com/google/cloud/dns/DnsImplTest.java index d34cb340e6e3..deefe21f36aa 100644 --- a/gcloud-java-dns/src/test/java/com/google/cloud/dns/DnsImplTest.java +++ b/gcloud-java-dns/src/test/java/com/google/cloud/dns/DnsImplTest.java @@ -22,9 +22,9 @@ import com.google.api.services.dns.model.Change; import com.google.api.services.dns.model.ManagedZone; import com.google.api.services.dns.model.ResourceRecordSet; +import com.google.cloud.Clock; import com.google.cloud.Page; import com.google.cloud.RetryParams; -import com.google.cloud.ServiceOptions; import com.google.cloud.dns.spi.DnsRpc; import com.google.cloud.dns.spi.DnsRpcFactory; import com.google.common.collect.ImmutableList; @@ -100,7 +100,7 @@ public class DnsImplTest { // Other private static final Map EMPTY_RPC_OPTIONS = ImmutableMap.of(); - private static final ServiceOptions.Clock TIME_SOURCE = new ServiceOptions.Clock() { + private static final Clock TIME_SOURCE = new Clock() { @Override public long millis() { return 42000L; diff --git a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java index 4054a4b2443a..81bcb563cd93 100644 --- a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java +++ b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManagerImpl.java @@ -55,7 +55,7 @@ public Project create(final ProjectInfo project) { public com.google.api.services.cloudresourcemanager.model.Project call() { return resourceManagerRpc.create(project.toPb()); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } @@ -70,7 +70,7 @@ public Void call() { resourceManagerRpc.delete(projectId); return null; } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } @@ -86,7 +86,7 @@ public Project get(final String projectId, ProjectGetOption... options) { public com.google.api.services.cloudresourcemanager.model.Project call() { return resourceManagerRpc.get(projectId, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Project.fromPb(this, answer); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); @@ -129,7 +129,7 @@ Iterable> call() { return serviceOptions.rpc().list(optionsMap); } }, - serviceOptions.retryParams(), EXCEPTION_HANDLER); + serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable projects = result.y() == null @@ -161,7 +161,7 @@ public Project replace(final ProjectInfo newProject) { public com.google.api.services.cloudresourcemanager.model.Project call() { return resourceManagerRpc.replace(newProject.toPb()); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } @@ -176,7 +176,7 @@ public Void call() { resourceManagerRpc.undelete(projectId); return null; } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } @@ -192,7 +192,7 @@ public Policy getPolicy(final String projectId) { public com.google.api.services.cloudresourcemanager.model.Policy call() { return resourceManagerRpc.getPolicy(projectId); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Policy.fromPb(answer); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); @@ -208,7 +208,7 @@ public Policy replacePolicy(final String projectId, final Policy newPolicy) { public com.google.api.services.cloudresourcemanager.model.Policy call() { return resourceManagerRpc.replacePolicy(projectId, newPolicy.toPb()); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } @@ -223,7 +223,7 @@ public List testPermissions(final String projectId, final List public List call() { return resourceManagerRpc.testPermissions(projectId, permissions); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException ex) { throw ResourceManagerException.translateAndThrow(ex); } diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java index 49ceb99a5792..0352e8a9d550 100644 --- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobReadChannel.java @@ -126,7 +126,7 @@ public int read(ByteBuffer byteBuffer) throws IOException { public Tuple call() { return storageRpc.read(storageObject, requestOptions, position, toRead); } - }, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER, serviceOptions.clock()); if (result.y().length > 0 && lastEtag != null && !Objects.equals(result.x(), lastEtag)) { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append("Blob ").append(blob).append(" was updated while reading"); diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobWriteChannel.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobWriteChannel.java index 0076b3cbaac4..9765b8fa1bb7 100644 --- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobWriteChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobWriteChannel.java @@ -48,7 +48,7 @@ protected void flushBuffer(final int length, final boolean last) { public void run() { options().rpc().write(uploadId(), buffer(), 0, position(), length, last); } - }), options().retryParams(), StorageImpl.EXCEPTION_HANDLER); + }), options().retryParams(), StorageImpl.EXCEPTION_HANDLER, options().clock()); } catch (RetryHelper.RetryHelperException e) { throw StorageException.translateAndThrow(e); } diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/CopyWriter.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/CopyWriter.java index 9e674052f877..2cf309d7c5ca 100644 --- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/CopyWriter.java +++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/CopyWriter.java @@ -113,7 +113,7 @@ public void copyChunk() { public RewriteResponse call() { return storageRpc.continueRewrite(rewriteResponse); } - }, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER, serviceOptions.clock()); } catch (RetryHelper.RetryHelperException e) { throw StorageException.translateAndThrow(e); } diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/StorageImpl.java index 8a33f2bc4203..50a1076fc84a 100644 --- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/StorageImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/StorageImpl.java @@ -100,7 +100,7 @@ public Bucket create(BucketInfo bucketInfo, BucketTargetOption... options) { public com.google.api.services.storage.model.Bucket call() { return storageRpc.create(bucketPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -142,7 +142,7 @@ public StorageObject call() { return storageRpc.create(blobPb, firstNonNull(content, new ByteArrayInputStream(EMPTY_BYTE_ARRAY)), optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -159,7 +159,7 @@ public Bucket get(String bucket, BucketGetOption... options) { public com.google.api.services.storage.model.Bucket call() { return storageRpc.get(bucketPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Bucket.fromPb(this, answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); @@ -181,7 +181,7 @@ public Blob get(BlobId blob, BlobGetOption... options) { public StorageObject call() { return storageRpc.get(storedObject, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return storageObject == null ? null : Blob.fromPb(this, storageObject); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); @@ -253,7 +253,7 @@ private static Page listBuckets(final StorageOptions serviceOptions, public Tuple> call() { return serviceOptions.rpc().list(optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable buckets = result.y() == null ? ImmutableList.of() : Iterables.transform(result.y(), @@ -280,7 +280,7 @@ private static Page listBlobs(final String bucket, public Tuple> call() { return serviceOptions.rpc().list(bucket, optionsMap); } - }, serviceOptions.retryParams(), EXCEPTION_HANDLER); + }, serviceOptions.retryParams(), EXCEPTION_HANDLER, serviceOptions.clock()); String cursor = result.x(); Iterable blobs = result.y() == null @@ -311,7 +311,7 @@ public Bucket update(BucketInfo bucketInfo, BucketTargetOption... options) { public com.google.api.services.storage.model.Bucket call() { return storageRpc.patch(bucketPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -327,7 +327,7 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) { public StorageObject call() { return storageRpc.patch(storageObject, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -348,7 +348,7 @@ public boolean delete(String bucket, BucketSourceOption... options) { public Boolean call() { return storageRpc.delete(bucketPb, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -369,7 +369,7 @@ public boolean delete(BlobId blob, BlobSourceOption... options) { public Boolean call() { return storageRpc.delete(storageObject, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -398,7 +398,7 @@ public Blob compose(final ComposeRequest composeRequest) { public StorageObject call() { return storageRpc.compose(sources, target, targetOptions); } - }, options().retryParams(), EXCEPTION_HANDLER)); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } @@ -420,7 +420,7 @@ public RewriteResponse call() { copyRequest.overrideInfo(), targetObject, targetOptions, copyRequest.megabytesCopiedPerChunk())); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return new CopyWriter(options(), rewriteResponse); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); @@ -442,7 +442,7 @@ public byte[] readAllBytes(BlobId blob, BlobSourceOption... options) { public byte[] call() { return storageRpc.load(storageObject, optionsMap); } - }, options().retryParams(), EXCEPTION_HANDLER); + }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } diff --git a/gcloud-java-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java index 9df971721906..b6188df3b3c5 100644 --- a/gcloud-java-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java +++ b/gcloud-java-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java @@ -26,10 +26,10 @@ import com.google.api.services.storage.model.StorageObject; import com.google.cloud.AuthCredentials.ServiceAccountAuthCredentials; +import com.google.cloud.Clock; import com.google.cloud.Page; import com.google.cloud.ReadChannel; import com.google.cloud.RetryParams; -import com.google.cloud.ServiceOptions; import com.google.cloud.WriteChannel; import com.google.cloud.storage.Storage.CopyRequest; import com.google.cloud.storage.spi.StorageRpc; @@ -225,7 +225,7 @@ public class StorageImplTest { + "EkPPhszldvQTY486uPxyD/D7HdfnGW/Nbw5JUhfvecAdudDEhNAQ3PNabyDMI+TpiHy4NTWOrgdcWrzj6VXcdc" + "+uuABnPwRCdcyJ1xl2kOrPksRnp1auNGMLOe4IpEBjGY7baX9UG8+A45MbG0aHmkR59Op/aR9XowIDAQAB"; - private static final ServiceOptions.Clock TIME_SOURCE = new ServiceOptions.Clock() { + private static final Clock TIME_SOURCE = new Clock() { @Override public long millis() { return 42000L;