Skip to content

Commit 100db18

Browse files
author
Tony Cui
committed
Rename HedgeSettings to HedgingSettings
1 parent 2eb687f commit 100db18

4 files changed

Lines changed: 61 additions & 58 deletions

File tree

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/HedgeSettings.java renamed to java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/HedgingSettings.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.time.Duration;
2121

2222
/** Settings for configuring publish hedging. */
23-
public final class HedgeSettings {
23+
public final class HedgingSettings {
2424
/** Default hedging delay. */
2525
private static final Duration DEFAULT_DELAY = Duration.ofMillis(1000);
2626

@@ -45,7 +45,7 @@ public final class HedgeSettings {
4545
/** Refill rate. */
4646
private final float refillRatio;
4747

48-
private HedgeSettings(final Builder builder) {
48+
private HedgingSettings(final Builder builder) {
4949
this.hedgeDelay = builder.hedgeDelay;
5050
this.maxTokens = builder.maxTokens;
5151
this.refillRatio = builder.refillRatio;
@@ -69,15 +69,15 @@ float getRefillRatio() {
6969
}
7070

7171
/**
72-
* Returns a new builder for {@code HedgeSettings}.
72+
* Returns a new builder for {@code HedgingSettings}.
7373
*
7474
* @return a new builder.
7575
*/
7676
public static Builder newBuilder() {
7777
return new Builder();
7878
}
7979

80-
/** Builder for {@code HedgeSettings}. */
80+
/** Builder for {@code HedgingSettings}. */
8181
public static final class Builder {
8282
/** Hedging delay. */
8383
private Duration hedgeDelay = DEFAULT_DELAY;
@@ -141,12 +141,12 @@ public Builder setRefillRatio(final float refillRatio) {
141141
}
142142

143143
/**
144-
* Builds an instance of {@code HedgeSettings}.
144+
* Builds an instance of {@code HedgingSettings}.
145145
*
146-
* @return the built {@code HedgeSettings} instance.
146+
* @return the built {@code HedgingSettings} instance.
147147
*/
148-
public HedgeSettings build() {
149-
return new HedgeSettings(this);
148+
public HedgingSettings build() {
149+
return new HedgingSettings(this);
150150
}
151151
}
152152
}

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class Publisher implements PublisherInterface {
147147
private final OpenTelemetry openTelemetry;
148148
private OpenTelemetryPubsubTracer tracer = new OpenTelemetryPubsubTracer(null, false);
149149

150-
private final HedgeSettings hedgeSettings;
150+
private final HedgingSettings hedgingSettings;
151151
private final Set<StatusCode.Code> retryableCodes;
152152

153153
/**
@@ -260,10 +260,10 @@ private Publisher(Builder builder) throws IOException {
260260
backgroundResources = new BackgroundResourceAggregation(backgroundResourceList);
261261
shutdown = new AtomicBoolean(false);
262262
messagesWaiter = new Waiter();
263-
this.hedgeSettings = builder.hedgeSettings;
264-
if (this.hedgeSettings != null) {
263+
this.hedgingSettings = builder.hedgingSettings;
264+
if (this.hedgingSettings != null) {
265265
// Verify that the hedge delay is strictly less than the initial RPC timeout.
266-
Duration hedgeDelay = this.hedgeSettings.getHedgeDelay();
266+
Duration hedgeDelay = this.hedgingSettings.getHedgeDelay();
267267
Duration initialRpcTimeout = builder.retrySettings.getInitialRpcTimeoutDuration();
268268
if (hedgeDelay.compareTo(initialRpcTimeout) >= 0) {
269269
throw new IllegalArgumentException(
@@ -273,9 +273,9 @@ private Publisher(Builder builder) throws IOException {
273273
+ initialRpcTimeout.toMillis()
274274
+ "ms)");
275275
}
276-
this.scaledMaxHedgeTokens = this.hedgeSettings.getMaxTokens() * HEDGE_TOKEN_SCALE;
276+
this.scaledMaxHedgeTokens = this.hedgingSettings.getMaxTokens() * HEDGE_TOKEN_SCALE;
277277
this.scaledHedgeRefillAmount =
278-
(int) (this.hedgeSettings.getRefillRatio() * HEDGE_TOKEN_SCALE);
278+
(int) (this.hedgingSettings.getRefillRatio() * HEDGE_TOKEN_SCALE);
279279
this.hedgeTokenBucket.set(0);
280280
}
281281
this.clock = builder.clock != null ? builder.clock : CurrentMillisClock.getDefaultClock();
@@ -300,13 +300,13 @@ public String getTopicNameString() {
300300
}
301301

302302
/** Returns the configured hedging settings, or null if hedging is disabled. */
303-
public HedgeSettings getHedgeSettings() {
304-
return hedgeSettings;
303+
public HedgingSettings getHedgingSettings() {
304+
return hedgingSettings;
305305
}
306306

307307
@VisibleForTesting
308308
Float getHedgeTokenBalance() {
309-
if (hedgeSettings == null) {
309+
if (hedgingSettings == null) {
310310
return null;
311311
}
312312
return (float) hedgeTokenBucket.get() / HEDGE_TOKEN_SCALE;
@@ -659,7 +659,7 @@ public void onFailure(Throwable t) {
659659
ApiFuture<PublishResponse> future;
660660
Executor callbackExecutor = directExecutor();
661661
if (outstandingBatch.orderingKey == null || outstandingBatch.orderingKey.isEmpty()) {
662-
if (hedgeSettings != null) {
662+
if (hedgingSettings != null) {
663663
future = startHedgedCall(outstandingBatch);
664664
} else {
665665
future = publishCall(outstandingBatch);
@@ -680,15 +680,15 @@ public ApiFuture<PublishResponse> call() {
680680
}
681681

682682
void refillTokenBucket() {
683-
if (hedgeSettings != null) {
683+
if (hedgingSettings != null) {
684684
hedgeTokenBucket.accumulateAndGet(
685685
scaledHedgeRefillAmount,
686686
(current, refill) -> Math.min(scaledMaxHedgeTokens, current + refill));
687687
}
688688
}
689689

690690
boolean tryAcquireHedgeToken() {
691-
if (hedgeSettings == null) {
691+
if (hedgingSettings == null) {
692692
return false;
693693
}
694694
int previous =
@@ -725,7 +725,7 @@ public void run() {
725725

726726
ApiFuture<PublishResponse> firstAttemptFuture = publishCall(outstandingBatch);
727727
coordinator.addAttempt(0, firstAttemptFuture);
728-
long delayMs = hedgeSettings.getHedgeDelay().toMillis();
728+
long delayMs = hedgingSettings.getHedgeDelay().toMillis();
729729
HedgedRequest item = new HedgedRequest(coordinator, 1, clock.millisTime() + delayMs);
730730
hedgingQueue.add(item);
731731
coordinator.isInQueue.set(true);
@@ -790,7 +790,7 @@ private void processQueue() {
790790

791791
if (tryAcquireHedgeToken()) {
792792
// Clone and schedule next attempt check (Attempt + 1)
793-
long delayMs = hedgeSettings.getHedgeDelay().toMillis();
793+
long delayMs = hedgingSettings.getHedgeDelay().toMillis();
794794
HedgedRequest nextItem =
795795
new HedgedRequest(coordinator, item.getAttemptNumber() + 1, now + delayMs);
796796
hedgingQueue.add(nextItem);
@@ -1041,7 +1041,7 @@ public PubsubMessage apply(PubsubMessage input) {
10411041

10421042
private boolean enableOpenTelemetryTracing = false;
10431043
private OpenTelemetry openTelemetry = null;
1044-
private HedgeSettings hedgeSettings = null;
1044+
private HedgingSettings hedgingSettings = null;
10451045
ApiClock clock = null;
10461046

10471047
private Builder(String topic) {
@@ -1196,8 +1196,8 @@ public Builder setOpenTelemetry(OpenTelemetry openTelemetry) {
11961196
}
11971197

11981198
/** Configures the Publisher's hedging parameters. */
1199-
public Builder setHedgeSettings(HedgeSettings hedgeSettings) {
1200-
this.hedgeSettings = hedgeSettings;
1199+
public Builder setHedgingSettings(HedgingSettings hedgingSettings) {
1200+
this.hedgingSettings = hedgingSettings;
12011201
return this;
12021202
}
12031203

@@ -1213,7 +1213,7 @@ public static BatchingSettings getDefaultBatchingSettings() {
12131213

12141214
public Publisher build() throws IOException {
12151215
Preconditions.checkState(
1216-
!(enableMessageOrdering && hedgeSettings != null),
1216+
!(enableMessageOrdering && hedgingSettings != null),
12171217
"Publish hedging and message ordering cannot be enabled at the same time.");
12181218
return new Publisher(this);
12191219
}

java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/HedgeSettingsTest.java renamed to java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/HedgingSettingsTest.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import org.junit.runners.JUnit4;
2727

2828
@RunWith(JUnit4.class)
29-
public class HedgeSettingsTest {
29+
public class HedgingSettingsTest {
3030

3131
@Test
3232
public void testDefaultSettings() {
33-
HedgeSettings settings = HedgeSettings.newBuilder().build();
33+
HedgingSettings settings = HedgingSettings.newBuilder().build();
3434
assertNotNull(settings);
3535
assertEquals(Duration.ofMillis(1000), settings.getHedgeDelay());
3636
assertEquals(50, settings.getMaxTokens());
@@ -40,7 +40,7 @@ public void testDefaultSettings() {
4040
@Test
4141
public void testCustomDelay() {
4242
Duration customDelay = Duration.ofMillis(200);
43-
HedgeSettings settings = HedgeSettings.newBuilder().setHedgeDelay(customDelay).build();
43+
HedgingSettings settings = HedgingSettings.newBuilder().setHedgeDelay(customDelay).build();
4444
assertNotNull(settings);
4545
assertEquals(customDelay, settings.getHedgeDelay());
4646
}
@@ -49,76 +49,79 @@ public void testCustomDelay() {
4949
public void testDelayTooSmallThrows() {
5050
assertThrows(
5151
IllegalArgumentException.class,
52-
() -> HedgeSettings.newBuilder().setHedgeDelay(Duration.ofMillis(99)));
52+
() -> HedgingSettings.newBuilder().setHedgeDelay(Duration.ofMillis(99)));
5353
}
5454

5555
@Test
5656
public void testDelayTooLargeThrows() {
5757
assertThrows(
5858
IllegalArgumentException.class,
59-
() -> HedgeSettings.newBuilder().setHedgeDelay(Duration.ofMillis(10001)));
59+
() -> HedgingSettings.newBuilder().setHedgeDelay(Duration.ofMillis(10001)));
6060
}
6161

6262
@Test
6363
public void testNullDelayThrows() {
64-
assertThrows(NullPointerException.class, () -> HedgeSettings.newBuilder().setHedgeDelay(null));
64+
assertThrows(
65+
NullPointerException.class, () -> HedgingSettings.newBuilder().setHedgeDelay(null));
6566
}
6667

6768
@Test
6869
public void testCustomMaxTokens() {
69-
HedgeSettings settings = HedgeSettings.newBuilder().setMaxTokens(10).build();
70+
HedgingSettings settings = HedgingSettings.newBuilder().setMaxTokens(10).build();
7071
assertEquals(10, settings.getMaxTokens());
7172
}
7273

7374
@Test
7475
public void testNegativeMaxTokensThrows() {
75-
assertThrows(IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setMaxTokens(-5));
76+
assertThrows(
77+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setMaxTokens(-5));
7678
}
7779

7880
@Test
7981
public void testZeroMaxTokensThrows() {
80-
assertThrows(IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setMaxTokens(0));
82+
assertThrows(
83+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setMaxTokens(0));
8184
}
8285

8386
@Test
8487
public void testMaxTokensTooLargeThrows() {
8588
assertThrows(
86-
IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setMaxTokens(251));
89+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setMaxTokens(251));
8790
}
8891

8992
@Test
9093
public void testCustomRefill() {
91-
HedgeSettings settings = HedgeSettings.newBuilder().setRefillRatio(0.15f).build();
94+
HedgingSettings settings = HedgingSettings.newBuilder().setRefillRatio(0.15f).build();
9295
assertEquals(0.15f, settings.getRefillRatio(), 0.0001f);
9396
}
9497

9598
@Test
9699
public void testNegativeRefillThrows() {
97100
assertThrows(
98-
IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setRefillRatio(-0.1f));
101+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setRefillRatio(-0.1f));
99102
}
100103

101104
@Test
102105
public void testZeroRefillThrows() {
103106
assertThrows(
104-
IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setRefillRatio(0.0f));
107+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setRefillRatio(0.0f));
105108
}
106109

107110
@Test
108111
public void testRefillTooLargeThrows() {
109112
assertThrows(
110-
IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setRefillRatio(0.21f));
113+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setRefillRatio(0.21f));
111114
}
112115

113116
@Test
114117
public void testRefillTooSmallThrows() {
115118
assertThrows(
116-
IllegalArgumentException.class, () -> HedgeSettings.newBuilder().setRefillRatio(0.0009f));
119+
IllegalArgumentException.class, () -> HedgingSettings.newBuilder().setRefillRatio(0.0009f));
117120
}
118121

119122
@Test
120123
public void testMinimumRefillValid() {
121-
HedgeSettings settings = HedgeSettings.newBuilder().setRefillRatio(0.001f).build();
124+
HedgingSettings settings = HedgingSettings.newBuilder().setRefillRatio(0.001f).build();
122125
assertEquals(0.001f, settings.getRefillRatio(), 0.0001f);
123126
}
124127
}

java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,12 +1359,12 @@ public void testPublishOpenTelemetryTracing() throws Exception {
13591359
}
13601360

13611361
@Test
1362-
public void testPublisherWithHedgeSettings() throws Exception {
1363-
HedgeSettings hedgeSettings =
1364-
HedgeSettings.newBuilder().setHedgeDelay(Duration.ofMillis(100)).build();
1365-
Publisher publisher = getTestPublisherBuilder().setHedgeSettings(hedgeSettings).build();
1362+
public void testPublisherWithHedgingSettings() throws Exception {
1363+
HedgingSettings hedgingSettings =
1364+
HedgingSettings.newBuilder().setHedgeDelay(Duration.ofMillis(100)).build();
1365+
Publisher publisher = getTestPublisherBuilder().setHedgingSettings(hedgingSettings).build();
13661366

1367-
assertThat(publisher.getHedgeSettings()).isEqualTo(hedgeSettings);
1367+
assertThat(publisher.getHedgingSettings()).isEqualTo(hedgingSettings);
13681368
assertThat(publisher.getHedgeTokenBalance()).isNotNull();
13691369
assertThat(publisher.getHedgeTokenBalance()).isWithin(0.0001f).of(0.0f);
13701370

@@ -1373,8 +1373,8 @@ public void testPublisherWithHedgeSettings() throws Exception {
13731373

13741374
@Test
13751375
public void testPublisherThrowsIfHedgeDelayGtRpcTimeout() throws Exception {
1376-
HedgeSettings hedgeSettings =
1377-
HedgeSettings.newBuilder().setHedgeDelay(Duration.ofMillis(500)).build();
1376+
HedgingSettings hedgingSettings =
1377+
HedgingSettings.newBuilder().setHedgeDelay(Duration.ofMillis(500)).build();
13781378
com.google.api.gax.retrying.RetrySettings retrySettings =
13791379
com.google.api.gax.retrying.RetrySettings.newBuilder()
13801380
.setInitialRpcTimeoutDuration(Duration.ofMillis(400))
@@ -1384,7 +1384,7 @@ public void testPublisherThrowsIfHedgeDelayGtRpcTimeout() throws Exception {
13841384

13851385
try {
13861386
getTestPublisherBuilder()
1387-
.setHedgeSettings(hedgeSettings)
1387+
.setHedgingSettings(hedgingSettings)
13881388
.setRetrySettings(retrySettings)
13891389
.build();
13901390
fail(
@@ -1397,8 +1397,8 @@ public void testPublisherThrowsIfHedgeDelayGtRpcTimeout() throws Exception {
13971397

13981398
@Test
13991399
public void testPublisherThrowsIfHedgeDelayEqRpcTimeout() throws Exception {
1400-
HedgeSettings hedgeSettings =
1401-
HedgeSettings.newBuilder().setHedgeDelay(Duration.ofMillis(500)).build();
1400+
HedgingSettings hedgingSettings =
1401+
HedgingSettings.newBuilder().setHedgeDelay(Duration.ofMillis(500)).build();
14021402
com.google.api.gax.retrying.RetrySettings retrySettings =
14031403
com.google.api.gax.retrying.RetrySettings.newBuilder()
14041404
.setInitialRpcTimeoutDuration(Duration.ofMillis(500))
@@ -1408,7 +1408,7 @@ public void testPublisherThrowsIfHedgeDelayEqRpcTimeout() throws Exception {
14081408

14091409
try {
14101410
getTestPublisherBuilder()
1411-
.setHedgeSettings(hedgeSettings)
1411+
.setHedgingSettings(hedgingSettings)
14121412
.setRetrySettings(retrySettings)
14131413
.build();
14141414
fail(
@@ -1420,10 +1420,10 @@ public void testPublisherThrowsIfHedgeDelayEqRpcTimeout() throws Exception {
14201420
}
14211421

14221422
@Test
1423-
public void testPublisherWithoutHedgeSettings() throws Exception {
1423+
public void testPublisherWithoutHedgingSettings() throws Exception {
14241424
Publisher publisher = getTestPublisherBuilder().build();
14251425

1426-
assertThat(publisher.getHedgeSettings()).isNull();
1426+
assertThat(publisher.getHedgingSettings()).isNull();
14271427
assertThat(publisher.getHedgeTokenBalance()).isNull();
14281428

14291429
shutdownTestPublisher(publisher);
@@ -1435,14 +1435,14 @@ private Publisher getPublisherWithHedge(Duration delay) throws Exception {
14351435

14361436
private Publisher getPublisherWithHedge(Duration delay, float refillRatio, int maxTokens)
14371437
throws Exception {
1438-
HedgeSettings hedgeSettings =
1439-
HedgeSettings.newBuilder()
1438+
HedgingSettings hedgingSettings =
1439+
HedgingSettings.newBuilder()
14401440
.setHedgeDelay(delay)
14411441
.setRefillRatio(refillRatio)
14421442
.setMaxTokens(maxTokens)
14431443
.build();
14441444
return getTestPublisherBuilder()
1445-
.setHedgeSettings(hedgeSettings)
1445+
.setHedgingSettings(hedgingSettings)
14461446
.setClock(fakeExecutor.getClock())
14471447
.setBatchingSettings(
14481448
Publisher.Builder.DEFAULT_BATCHING_SETTINGS.toBuilder()

0 commit comments

Comments
 (0)