Skip to content

Commit b84654e

Browse files
authored
fix: update StorageOptions to carry forward fields that aren't part of ServiceOptions (#2521)
1 parent 67a7c6b commit b84654e

12 files changed

+414
-8
lines changed

google-cloud-storage/clirr-ignored-differences.xml

+12
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@
8484
<className>com/google/cloud/storage/WriteFlushStrategy$DefaultBidiFlusher</className>
8585
</difference>
8686

87+
<!-- BlobWriteSessionConfig is package-private extendable only, allow hashCode/equals -->
88+
<difference>
89+
<differenceType>7013</differenceType>
90+
<className>com/google/cloud/storage/BlobWriteSessionConfig</className>
91+
<method>int hashCode()</method>
92+
</difference>
93+
<difference>
94+
<differenceType>7013</differenceType>
95+
<className>com/google/cloud/storage/BlobWriteSessionConfig</className>
96+
<method>boolean equals(java.lang.Object)</method>
97+
</difference>
98+
8799
</differences>

google-cloud-storage/src/main/java/com/google/cloud/storage/BidiBlobWriteSessionConfig.java

+18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.storage.v2.BidiWriteObjectResponse;
2929
import java.io.IOException;
3030
import java.time.Clock;
31+
import java.util.Objects;
3132
import javax.annotation.concurrent.Immutable;
3233

3334
/**
@@ -64,6 +65,23 @@ public int getBufferSize() {
6465
return bufferSize;
6566
}
6667

68+
@Override
69+
public boolean equals(Object o) {
70+
if (this == o) {
71+
return true;
72+
}
73+
if (!(o instanceof BidiBlobWriteSessionConfig)) {
74+
return false;
75+
}
76+
BidiBlobWriteSessionConfig that = (BidiBlobWriteSessionConfig) o;
77+
return bufferSize == that.bufferSize;
78+
}
79+
80+
@Override
81+
public int hashCode() {
82+
return Objects.hashCode(bufferSize);
83+
}
84+
6785
@Override
6886
WriterFactory createFactory(Clock clock) throws IOException {
6987
return new Factory(bufferSize);

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public abstract class BlobWriteSessionConfig implements Serializable {
4343
@InternalApi
4444
BlobWriteSessionConfig() {}
4545

46+
@Override
47+
public abstract int hashCode();
48+
49+
@Override
50+
public abstract boolean equals(Object obj);
51+
4652
@InternalApi
4753
abstract WriterFactory createFactory(Clock clock) throws IOException;
4854

google-cloud-storage/src/main/java/com/google/cloud/storage/BufferToDiskThenUpload.java

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.time.Duration;
4242
import java.util.ArrayList;
4343
import java.util.Collection;
44+
import java.util.Objects;
4445
import java.util.stream.Collector;
4546
import javax.annotation.concurrent.Immutable;
4647
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -81,6 +82,25 @@ public final class BufferToDiskThenUpload extends BlobWriteSessionConfig
8182
this.includeLoggingSink = includeLoggingSink;
8283
}
8384

85+
@Override
86+
public boolean equals(Object o) {
87+
if (this == o) {
88+
return true;
89+
}
90+
if (!(o instanceof BufferToDiskThenUpload)) {
91+
return false;
92+
}
93+
BufferToDiskThenUpload that = (BufferToDiskThenUpload) o;
94+
return includeLoggingSink == that.includeLoggingSink
95+
&& Objects.equals(paths, that.paths)
96+
&& Objects.equals(absolutePaths, that.absolutePaths);
97+
}
98+
99+
@Override
100+
public int hashCode() {
101+
return Objects.hash(paths, includeLoggingSink, absolutePaths);
102+
}
103+
84104
@VisibleForTesting
85105
@InternalApi
86106
BufferToDiskThenUpload withIncludeLoggingSink() throws IOException {

google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.nio.channels.WritableByteChannel;
3838
import java.time.Clock;
3939
import java.util.Map;
40+
import java.util.Objects;
4041
import java.util.function.Supplier;
4142
import javax.annotation.concurrent.Immutable;
4243

@@ -105,6 +106,23 @@ public DefaultBlobWriteSessionConfig withChunkSize(int chunkSize) {
105106
return new DefaultBlobWriteSessionConfig(chunkSize);
106107
}
107108

109+
@Override
110+
public boolean equals(Object o) {
111+
if (this == o) {
112+
return true;
113+
}
114+
if (!(o instanceof DefaultBlobWriteSessionConfig)) {
115+
return false;
116+
}
117+
DefaultBlobWriteSessionConfig that = (DefaultBlobWriteSessionConfig) o;
118+
return chunkSize == that.chunkSize;
119+
}
120+
121+
@Override
122+
public int hashCode() {
123+
return Objects.hashCode(chunkSize);
124+
}
125+
108126
@Override
109127
@InternalApi
110128
WriterFactory createFactory(Clock clock) {

google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcRetryAlgorithmManager.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.storage;
1818

1919
import com.google.api.gax.retrying.ResultRetryAlgorithm;
20+
import com.google.common.base.MoreObjects;
2021
import com.google.iam.v1.GetIamPolicyRequest;
2122
import com.google.iam.v1.SetIamPolicyRequest;
2223
import com.google.iam.v1.TestIamPermissionsRequest;
@@ -50,11 +51,12 @@
5051
import com.google.storage.v2.UpdateObjectRequest;
5152
import com.google.storage.v2.WriteObjectRequest;
5253
import java.io.Serializable;
54+
import java.util.Objects;
5355

5456
final class GrpcRetryAlgorithmManager implements Serializable {
5557

5658
private static final long serialVersionUID = 3084833873820431477L;
57-
private final StorageRetryStrategy retryStrategy;
59+
final StorageRetryStrategy retryStrategy;
5860

5961
GrpcRetryAlgorithmManager(StorageRetryStrategy retryStrategy) {
6062
this.retryStrategy = retryStrategy;
@@ -217,4 +219,26 @@ public ResultRetryAlgorithm<?> getFor(BidiWriteObjectRequest req) {
217219
? retryStrategy.getIdempotentHandler()
218220
: retryStrategy.getNonidempotentHandler();
219221
}
222+
223+
@Override
224+
public boolean equals(Object o) {
225+
if (this == o) {
226+
return true;
227+
}
228+
if (!(o instanceof GrpcRetryAlgorithmManager)) {
229+
return false;
230+
}
231+
GrpcRetryAlgorithmManager that = (GrpcRetryAlgorithmManager) o;
232+
return Objects.equals(retryStrategy, that.retryStrategy);
233+
}
234+
235+
@Override
236+
public int hashCode() {
237+
return Objects.hashCode(retryStrategy);
238+
}
239+
240+
@Override
241+
public String toString() {
242+
return MoreObjects.toStringHelper(this).add("retryStrategy", retryStrategy).toString();
243+
}
220244
}

google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,30 @@ public GrpcStorageOptions.Builder toBuilder() {
346346

347347
@Override
348348
public int hashCode() {
349-
return baseHashCode();
349+
return Objects.hash(
350+
retryAlgorithmManager,
351+
terminationAwaitDuration,
352+
attemptDirectPath,
353+
grpcInterceptorProvider,
354+
blobWriteSessionConfig,
355+
baseHashCode());
350356
}
351357

352358
@Override
353-
public boolean equals(Object obj) {
354-
return obj instanceof GrpcStorageOptions && baseEquals((GrpcStorageOptions) obj);
359+
public boolean equals(Object o) {
360+
if (this == o) {
361+
return true;
362+
}
363+
if (!(o instanceof GrpcStorageOptions)) {
364+
return false;
365+
}
366+
GrpcStorageOptions that = (GrpcStorageOptions) o;
367+
return attemptDirectPath == that.attemptDirectPath
368+
&& Objects.equals(retryAlgorithmManager, that.retryAlgorithmManager)
369+
&& Objects.equals(terminationAwaitDuration, that.terminationAwaitDuration)
370+
&& Objects.equals(grpcInterceptorProvider, that.grpcInterceptorProvider)
371+
&& Objects.equals(blobWriteSessionConfig, that.blobWriteSessionConfig)
372+
&& this.baseEquals(that);
355373
}
356374

357375
/** @since 2.14.0 This new api is in preview and is subject to breaking changes. */
@@ -399,6 +417,12 @@ public static final class Builder extends StorageOptions.Builder {
399417

400418
Builder(StorageOptions options) {
401419
super(options);
420+
GrpcStorageOptions gso = (GrpcStorageOptions) options;
421+
this.storageRetryStrategy = gso.getRetryAlgorithmManager().retryStrategy;
422+
this.terminationAwaitDuration = gso.getTerminationAwaitDuration();
423+
this.attemptDirectPath = gso.attemptDirectPath;
424+
this.grpcInterceptorProvider = gso.grpcInterceptorProvider;
425+
this.blobWriteSessionConfig = gso.blobWriteSessionConfig;
402426
}
403427

404428
/**

google-cloud-storage/src/main/java/com/google/cloud/storage/HttpRetryAlgorithmManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
final class HttpRetryAlgorithmManager implements Serializable {
3636

3737
private static final long serialVersionUID = -3301856948991518651L;
38-
private final StorageRetryStrategy retryStrategy;
38+
final StorageRetryStrategy retryStrategy;
3939

4040
HttpRetryAlgorithmManager(StorageRetryStrategy retryStrategy) {
4141
this.retryStrategy = retryStrategy;

google-cloud-storage/src/main/java/com/google/cloud/storage/HttpStorageOptions.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.ObjectInputStream;
4343
import java.io.Serializable;
4444
import java.time.Clock;
45+
import java.util.Objects;
4546
import java.util.Set;
4647
import org.checkerframework.checker.nullness.qual.NonNull;
4748

@@ -93,12 +94,21 @@ public HttpStorageOptions.Builder toBuilder() {
9394

9495
@Override
9596
public int hashCode() {
96-
return baseHashCode();
97+
return Objects.hash(retryAlgorithmManager, blobWriteSessionConfig, baseHashCode());
9798
}
9899

99100
@Override
100-
public boolean equals(Object obj) {
101-
return obj instanceof HttpStorageOptions && baseEquals((HttpStorageOptions) obj);
101+
public boolean equals(Object o) {
102+
if (this == o) {
103+
return true;
104+
}
105+
if (!(o instanceof HttpStorageOptions)) {
106+
return false;
107+
}
108+
HttpStorageOptions that = (HttpStorageOptions) o;
109+
return Objects.equals(retryAlgorithmManager, that.retryAlgorithmManager)
110+
&& Objects.equals(blobWriteSessionConfig, that.blobWriteSessionConfig)
111+
&& this.baseEquals(that);
102112
}
103113

104114
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
@@ -133,6 +143,9 @@ public static class Builder extends StorageOptions.Builder {
133143

134144
Builder(StorageOptions options) {
135145
super(options);
146+
HttpStorageOptions hso = (HttpStorageOptions) options;
147+
this.storageRetryStrategy = hso.retryAlgorithmManager.retryStrategy;
148+
this.blobWriteSessionConfig = hso.blobWriteSessionConfig;
136149
}
137150

138151
@Override

google-cloud-storage/src/main/java/com/google/cloud/storage/JournalingBlobWriteSessionConfig.java

+20
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.time.Duration;
4646
import java.time.Instant;
4747
import java.util.ArrayList;
48+
import java.util.Objects;
4849
import java.util.stream.Collector;
4950
import javax.annotation.concurrent.Immutable;
5051
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -89,6 +90,25 @@ public final class JournalingBlobWriteSessionConfig extends BlobWriteSessionConf
8990
this.includeLoggingSink = includeLoggingSink;
9091
}
9192

93+
@Override
94+
public boolean equals(Object o) {
95+
if (this == o) {
96+
return true;
97+
}
98+
if (!(o instanceof JournalingBlobWriteSessionConfig)) {
99+
return false;
100+
}
101+
JournalingBlobWriteSessionConfig that = (JournalingBlobWriteSessionConfig) o;
102+
return includeLoggingSink == that.includeLoggingSink
103+
&& Objects.equals(paths, that.paths)
104+
&& Objects.equals(absolutePaths, that.absolutePaths);
105+
}
106+
107+
@Override
108+
public int hashCode() {
109+
return Objects.hash(paths, includeLoggingSink, absolutePaths);
110+
}
111+
92112
@VisibleForTesting
93113
@InternalApi
94114
JournalingBlobWriteSessionConfig withIncludeLoggingSink() {

0 commit comments

Comments
 (0)